public abstract class NodeAction extends CallableSystemAction implements ContextAwareAction
Whenever a list of activated nodes changes (a new
TopComponent is selected or
its internal selection changes like in
explorer)
the overriden method NodeAction.enable(org.openide.nodes.Node[])
is called and state of the action is updated
according to the result. When the action is performed, the subclasses are
notified by a call to their NodeAction.performAction(Node[])
where they
can perform their operation on the currently selected array of nodes.
Note: if your action involves getting cookies from nodes, which in many cases is the correct design, please use CookieAction instead, as that permits sensitivity to cookies and also listens to changes in supplied cookies.
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
PROP_ENABLED, PROP_ICON
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
Constructor and Description |
---|
NodeAction() |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent ev)
Deprecated.
Using a special action event in this way is deprecated.
Better is to use
NodeAction.createContextAwareInstance(org.openide.util.Lookup) and pass
a lookup containing all desired Node instances. |
protected void |
addNotify()
Initializes selection listener.
|
Action |
createContextAwareInstance(Lookup actionContext)
Implements
ContextAwareAction interface method. |
protected abstract boolean |
enable(Node[] activatedNodes)
Test whether the action should be enabled based
on the currently activated nodes.
|
Node[] |
getActivatedNodes()
Get the currently activated nodes.
|
protected void |
initialize() |
boolean |
isEnabled()
Test for enablement based on
NodeAction.enable(org.openide.nodes.Node[]) . |
void |
performAction()
Deprecated.
Do not call this programmatically.
Use
NodeAction.createContextAwareInstance(org.openide.util.Lookup) to pass in a node selection.
Do not override this method. |
protected abstract void |
performAction(Node[] activatedNodes)
Perform the action based on the currently activated nodes.
|
protected void |
removeNotify()
Shuts down the selection listener.
|
void |
setEnabled(boolean e) |
protected boolean |
surviveFocusChange()
Specify the behavior of the action when a window with no
activated nodes is selected.
|
asynchronous, getMenuPresenter, getPopupPresenter, getToolbarPresenter
clearSharedData, createPopupMenu, createToolbarPresenter, get, getHelpCtx, getIcon, getIcon, getName, getValue, iconResource, linkActions, putValue, setIcon
addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removePropertyChangeListener, reset, writeExternal, writeReplace
clone, getClass, notify, notifyAll, toString, wait, wait, wait
accept, addPropertyChangeListener, getValue, putValue, removePropertyChangeListener
protected void initialize()
initialize
in class SystemAction
protected void addNotify()
addNotify
in class SharedClassObject
protected void removeNotify()
removeNotify
in class SharedClassObject
public boolean isEnabled()
NodeAction.enable(org.openide.nodes.Node[])
.
You probably ought not ever override this.isEnabled
in interface Action
isEnabled
in class SystemAction
true
to enablepublic void setEnabled(boolean e)
setEnabled
in interface Action
setEnabled
in class SystemAction
@Deprecated public void actionPerformed(ActionEvent ev)
NodeAction.createContextAwareInstance(org.openide.util.Lookup)
and pass
a lookup containing all desired Node
instances.NodeAction.performAction()
, that is using
the global node selection.
However you may call this directly, with an action event whose
source is either a node or an array of nodes, to invoke the action
directly on that nodes or nodes. If you do this, the action must
be such that it would be enabled on that node selection, otherwise
the action is not required to behave correctly (that is, it can
be written to assume that it is never called with a node selection
it is not enabled on).actionPerformed
in interface ActionListener
actionPerformed
in class CallableSystemAction
ev
- action event@Deprecated public void performAction()
NodeAction.createContextAwareInstance(org.openide.util.Lookup)
to pass in a node selection.
Do not override this method.NodeAction.performAction(Node[])
.performAction
in class CallableSystemAction
public final Node[] getActivatedNodes()
null
)protected boolean surviveFocusChange()
false
here; if the action should stay in the previous state,
return true
.
Note that NodeAction.getActivatedNodes()
and NodeAction.performAction()
are still
passed the set of selected nodes from the old window, if you keep this feature on.
This is useful, e.g., for an action like Compilation which should remain active
even if the user switches to a window like the Output Window that has no associated nodes;
then running the action will still use the last selection from e.g. an Explorer window
or the Editor, if there was one to begin with.
true
in the default implementationprotected abstract void performAction(Node[] activatedNodes)
activatedNodes
- current activated nodes, may be empty but not null
protected abstract boolean enable(Node[] activatedNodes)
activatedNodes
- current activated nodes, may be empty but not null
true
to be enabled, false
to be disabledpublic Action createContextAwareInstance(Lookup actionContext)
ContextAwareAction
interface method.
Returns a delegate action that is associated with a specific lookup and
extracts the nodes it operates on from it. Otherwise it delegates to the
regular NodeAction (especially to NodeAction.enable(org.openide.nodes.Node[])
and NodeAction.performAction()
methods).
Note: Never call directly methods setEnabled
or putValue
of this delegate action, it is useless, they are empty. The enablement
state of the action is driven by the content of the actionContext
.createContextAwareInstance
in interface ContextAwareAction
actionContext
- a lookup contains action context, cannot be null