org.openide.util.actions
Class NodeAction

java.lang.Object
  |
  +--org.openide.util.SharedClassObject
        |
        +--org.openide.util.actions.SystemAction
              |
              +--org.openide.util.actions.CallableSystemAction
                    |
                    +--org.openide.util.actions.NodeAction
All Implemented Interfaces:
Action, ActionListener, EventListener, Externalizable, Presenter, Presenter.Menu, Presenter.Popup, Presenter.Toolbar, Serializable
Direct Known Subclasses:
AbstractCompileAction, CookieAction, CustomizeAction, GoAction, InstantiateAction, MoveDownAction, MoveUpAction, NewAction, NewTemplateAction, OpenLocalExplorerAction, PropertiesAction, RenameAction, SaveAsTemplateAction, StartDebuggerAction

public abstract class NodeAction
extends CallableSystemAction

An action which can listen to the activated node selection. This means that the set of nodes active in a window may change the enabled state of the action according to enable(org.openide.nodes.Node[]).

See Also:
Serialized Form

Inner classes inherited from class org.openide.util.actions.Presenter
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
 
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)
          Actually perform the action.
protected  void addNotify()
          Notify subclasses that the first listener has been added to this action.
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()
          Initialize the action.
 boolean isEnabled()
          Test for enablement based on enable(org.openide.nodes.Node[]).
 void performAction()
          Performs the action.
protected abstract  void performAction(Node[] activatedNodes)
          Perform the action based on the currently activated nodes.
protected  void removeNotify()
          Notify subclasses that the last listener has been removed from this action.
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
getMenuPresenter, getPopupPresenter, getToolbarPresenter
 
Methods inherited from class org.openide.util.actions.SystemAction
clearSharedData, createPopupMenu, createToolbarPresenter, get, getHelpCtx, getIcon, getIcon, getName, getValue, iconResource, linkActions, putValue, setEnabled, setIcon
 
Methods inherited from class org.openide.util.SharedClassObject
addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removePropertyChangeListener, 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, removePropertyChangeListener
 

Constructor Detail

NodeAction

public NodeAction()
Method Detail

initialize

protected void initialize()
Description copied from class: SystemAction
Initialize the action. The default implementation just enabled it.
Overrides:
initialize in class SystemAction

addNotify

protected void addNotify()
Description copied from class: SharedClassObject
Notify subclasses that the first listener has been added to this action. The default implementation does nothing.
Overrides:
addNotify in class SharedClassObject

removeNotify

protected void removeNotify()
Description copied from class: SharedClassObject
Notify subclasses that the last listener has been removed from this action. The default implementation does nothing.
Overrides:
removeNotify in class SharedClassObject

isEnabled

public boolean isEnabled()
Test for enablement based on enable(org.openide.nodes.Node[]). You probably ought not override this, except possibly to call the super method and add an additional check.
Overrides:
isEnabled in class SystemAction
Returns:
true to enable

actionPerformed

public void actionPerformed(ActionEvent ev)
Description copied from class: SystemAction
Actually perform the action. Specified in ActionListener.actionPerformed(java.awt.event.ActionEvent).

In some cases, the implementation may have an empty body, if the presenters handle the performing of the action in a different way than by calling this method.

Overrides:
actionPerformed in class CallableSystemAction
Following copied from class: org.openide.util.actions.SystemAction
Parameters:
ev - the event triggering the action

performAction

public void performAction()
Performs the action. In the default implementation, calls performAction(Node[]). In general you need not override this.
Overrides:
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


Built on February 22 2001.  |  Portions Copyright 1997-2000 Sun Microsystems, Inc. All rights reserved.