站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc 5.5.1

NodeAction (NetBeans Nodes API) - NetBeans API Javadoc 5.5.1

org.openide.nodes 6.7.31

org.openide.util.actions
Class NodeAction

java.lang.Object
  extended by org.openide.util.SharedClassObject
      extended by org.openide.util.actions.SystemAction
          extended by org.openide.util.actions.CallableSystemAction
              extended by org.openide.util.actions.NodeAction
All Implemented Interfaces:
ActionListener, Externalizable, Serializable, EventListener, Action, Presenter, Presenter.Menu, Presenter.Popup, Presenter.Toolbar, ContextAwareAction, HelpCtx.Provider
Direct Known Subclasses:
CookieAction

public abstract class NodeAction
extends CallableSystemAction
implements ContextAwareAction

A type of action that listens on change in activated nodes selection and allows its subclasses to simply change their enabled state and handle action invocation requests.

Whenever a list of activated nodes changes (a new TopComponent is selected or its internal selection changes like in explorer) the overriden method 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 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.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openide.util.actions.Presenter
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
 
Nested classes/interfaces inherited from interface org.openide.util.actions.Presenter
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
 
Nested classes/interfaces inherited from interface org.openide.util.actions.Presenter
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
 
Field Summary
 
Fields inherited from class org.openide.util.actions.SystemAction
PROP_ENABLED, PROP_ICON
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
NodeAction()
           
 
Method Summary
 void actionPerformed(ActionEvent ev)
          Deprecated. Using a special action event in this way is deprecated. Better is to use 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 enable(org.openide.nodes.Node[]).
 void performAction()
          Deprecated. Do not call this programmatically. Use 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.
 
Methods inherited from class org.openide.util.actions.CallableSystemAction
asynchronous, getMenuPresenter, getPopupPresenter, getToolbarPresenter
 
Methods inherited from class org.openide.util.actions.SystemAction
clearSharedData, createPopupMenu, createToolbarPresenter, get, getHelpCtx, getIcon, getIcon, getName, getValue, iconResource, linkActions, putValue, setIcon
 
Methods inherited from class org.openide.util.SharedClassObject
addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removePropertyChangeListener, reset, writeExternal, writeReplace
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.Action
addPropertyChangeListener, getValue, putValue, removePropertyChangeListener
 

Constructor Detail

NodeAction

public NodeAction()
Method Detail

initialize

protected void initialize()
Overrides:
initialize in class SystemAction

addNotify

protected void addNotify()
Initializes selection listener. If you override this method, you must always call the super method first.

Overrides:
addNotify in class SharedClassObject

removeNotify

protected void removeNotify()
Shuts down the selection listener. If you override this method, you must always call the super method last.

Overrides:
removeNotify in class SharedClassObject

isEnabled

public boolean isEnabled()
Test for enablement based on enable(org.openide.nodes.Node[]). You probably ought not ever override this.

Specified by:
isEnabled in interface Action
Overrides:
isEnabled in class SystemAction
Returns:
true to enable

setEnabled

public void setEnabled(boolean e)
Specified by:
setEnabled in interface Action
Overrides:
setEnabled in class SystemAction

actionPerformed

public void actionPerformed(ActionEvent ev)
Deprecated. Using a special action event in this way is deprecated. Better is to use createContextAwareInstance(org.openide.util.Lookup) and pass a lookup containing all desired Node instances.

Perform the action with a specific action event. Normally this simply calls 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).

Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class CallableSystemAction
Parameters:
ev - action event

performAction

public void performAction()
Deprecated. Do not call this programmatically. Use createContextAwareInstance(org.openide.util.Lookup) to pass in a node selection. Do not override this method.

Performs the action. In the default implementation, calls performAction(Node[]).

Specified by:
performAction in class CallableSystemAction

getActivatedNodes

public final Node[] getActivatedNodes()
Get the currently activated nodes.

Returns:
the nodes (may be empty but not null)

surviveFocusChange

protected boolean surviveFocusChange()
Specify the behavior of the action when a window with no activated nodes is selected. If the action should then be disabled, return false here; if the action should stay in the previous state, return true.

Note that getActivatedNodes() and 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.

Returns:
true in the default implementation

performAction

protected abstract void performAction(Node[] activatedNodes)
Perform the action based on the currently activated nodes. Note that if the source of the event triggering this action was itself a node, that node will be the sole argument to this method, rather than the activated nodes.

Parameters:
activatedNodes - current activated nodes, may be empty but not null

enable

protected abstract boolean enable(Node[] activatedNodes)
Test whether the action should be enabled based on the currently activated nodes.

Parameters:
activatedNodes - current activated nodes, may be empty but not null
Returns:
true to be enabled, false to be disabled

createContextAwareInstance

public Action createContextAwareInstance(Lookup actionContext)
Implements ContextAwareAction interface method.

Specified by:
createContextAwareInstance in interface ContextAwareAction

org.openide.nodes 6.7.31

Built on March 26 2007.  |  Portions Copyright 1997-2005 Sun Microsystems, Inc. All rights reserved.