org.netbeans.modules.refactoring.java/1 1.37.0 1

org.netbeans.modules.refactoring.java.spi.ui
Class JavaRefactoringActionDelegate

java.lang.Object
  extended by org.netbeans.modules.refactoring.java.spi.ui.JavaRefactoringActionDelegate

public abstract class JavaRefactoringActionDelegate
extends Object

Delegate which creates a refactoring UI and runs a refactoring. To be used by implementors of Java refactorings.

Usage:
Implement this class to provide a RefactoringUI for your refactoring. Include a static method on your implementation which instantiates an instance of your JavaRefactoringActionDelegate and passes it to JavaRefactoringActionDelegate.createAction().

Register an action in your module‘s XML Layer, in the folder for the menu (toolbar button, keybinding, etc.) where you want it to appear - typically Menu/Refactorings. Set the instanceCreate attribute to the fully qualified path to the static method you created (which should return javax.swing.Action.

Example Registration

  <filesystem>
    <folder name="Menu">
      <folder name="Refactoring">
        <file name="MyRefactoring.shadow">
          <attr name="originalFile"
                stringvalue="Actions/Refactoring/MyRefactoring.instance"/>
         </file>
      </folder>
    </folder>
    <folder name="Actions">
      <folder name="Refactoring">
        <file name="MyRefactoring.instance">
          <attr name="instanceCreate" methodvalue="com.foo.MyClass.myStaticMethod"/>
        </file>
      </folder>
    </folder>
  </filesystem>
  


Constructor Summary
protected JavaRefactoringActionDelegate(String name)
          Create a new refactoring action delegate which does not require a text selection, with the passed name.
protected JavaRefactoringActionDelegate(String name, boolean requiresSelection)
          Create a new refactoring action delegate which may require a text selection, with the passed name.
 
Method Summary
static Action createAction(JavaRefactoringActionDelegate delegate)
          Create an Action which should appear in menus to invoke this refactoring.
abstract  RefactoringUI createRefactoringUI(TreePathHandle selectedElement, int startOffset, int endOffset, CompilationInfo info)
          Create the refactoring UI which will be used to configure and invoke the refactoring.
 String getErrorMessage()
          Get an error message to be shown to the user if the creaetRefactoringUI() has just returned null.
protected  boolean isEnabled(Lookup context)
          Determine if the action should be enabled.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JavaRefactoringActionDelegate

protected JavaRefactoringActionDelegate(String name)
Create a new refactoring action delegate which does not require a text selection, with the passed name.

Parameters:
name - The display name of the action

JavaRefactoringActionDelegate

protected JavaRefactoringActionDelegate(String name,
                                        boolean requiresSelection)
Create a new refactoring action delegate which may require a text selection, with the passed name.

Parameters:
name - The display name of the action
requiresSelection - if true, isEnabled() will return false unless there is a text selection in the editor
Method Detail

createRefactoringUI

public abstract RefactoringUI createRefactoringUI(TreePathHandle selectedElement,
                                                  int startOffset,
                                                  int endOffset,
                                                  CompilationInfo info)
Create the refactoring UI which will be used to configure and invoke the refactoring.

Returns:
A refactoring UI, or null if the refactoring cannot be performed. It is preferable not to do deep source analysis here, but to do that in the analysis phase, unless the analysis can be done very quickly.

getErrorMessage

public String getErrorMessage()
Get an error message to be shown to the user if the creaetRefactoringUI() has just returned null.

Returns:
an error message - by default, simply says that this refactoring cannot be performed

createAction

public static Action createAction(JavaRefactoringActionDelegate delegate)
Create an Action which should appear in menus to invoke this refactoring.

Parameters:
delegate - An instance of JavaRefactoringActionDelegate which the resulting action will call to create the refactoring ui.

isEnabled

protected boolean isEnabled(Lookup context)
Determine if the action should be enabled. By default, this method checks for the presence of an open editor; if requiresSelection was passed to the constructor, it also depends on a text selection in that editor being present.

Parameters:
context - A Lookup containing either an EditorCookie or one or more Nodes whose lookup contains an EditorCookie
Returns:
true if the action should be enabled, false otherwise

org.netbeans.modules.refactoring.java/1 1.37.0 1

Built on May 25 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.