Class CallbackSystemAction

  extended byorg.openide.util.SharedClassObject
      extended byorg.openide.util.actions.SystemAction
          extended byorg.openide.util.actions.CallableSystemAction
              extended byorg.openide.util.actions.CallbackSystemAction
All Implemented Interfaces:
Action, ActionListener, ContextAwareAction, EventListener, Externalizable, HelpCtx.Provider, Presenter, Presenter.Menu, Presenter.Popup, Presenter.Toolbar, Serializable

public abstract class CallbackSystemAction
extends CallableSystemAction
implements ContextAwareAction

Action that can have a performer of the action attached to it at any time, or changed. The action will be automatically disabled when it has no performer.

Also may be made sensitive to changes in window focus.

See Also:
Serialized Form

Nested Class Summary
Nested classes inherited from class org.openide.util.actions.Presenter
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
Field Summary
Fields inherited from class org.openide.util.actions.SystemAction
Fields inherited from interface javax.swing.Action
Constructor Summary
Method Summary
 void actionPerformed(ActionEvent ev)
          Perform the action.
 Action createContextAwareInstance(Lookup actionContext)
          Implements ContextAwareAction interface method.
 Object getActionMapKey()
          Getter for action map key, which is used to find action from provided context (i.e.
 ActionPerformer getActionPerformer()
          Get the current action performer.
 boolean getSurviveFocusChange()
          Test whether the action will survive a change in focus.
protected  void initialize()
          Initialize the action to have no performer.
 void performAction()
          Perform the action.
 void setActionPerformer(ActionPerformer performer)
          Deprecated. use TopComponent.getActionMap() as described in the javadoc
 void setSurviveFocusChange(boolean b)
          Set whether the action will survive a change in focus.
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, isEnabled, linkActions, putValue, setEnabled, setIcon
Methods inherited from class org.openide.util.SharedClassObject
addNotify, addPropertyChangeListener, equals, finalize, findObject, findObject, firePropertyChange, getLock, getProperty, hashCode, putProperty, putProperty, readExternal, removeNotify, 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, isEnabled, putValue, removePropertyChangeListener, setEnabled

Constructor Detail


public CallbackSystemAction()
Method Detail


protected void initialize()
Initialize the action to have no performer.

initialize in class SystemAction


public ActionPerformer getActionPerformer()
Get the current action performer.

the current action performer, or null if there is currently no performer


public void setActionPerformer(ActionPerformer performer)
Deprecated. use TopComponent.getActionMap() as described in the javadoc

Set the action performer. The specified value can be null, which means that the action will have no performer and is disabled. (SystemAction.isEnabled() will return false regardless its previous state.)

This method is too dynamic it depends on the actuall order of callers and is for example very fragile with respect to focus switching and correct delivering of focus change events. That is why an alternative based on ActionMap proposal has been developed.

So if you are providing a TopComponent and want to provide your own handling of CopyAction use following code:

 TopComponent tc = ...;
 javax.swing.Action yourCopyAction = ...; // the action to invoke instead of Copy

 CopyAction globalCopyAction = SystemAction.get (CopyAction.class);
 Object key = globalCopyAction.getActionMapKey(); // key is a special value defined by all CallbackSystemActions

 // and finally:
 tc.getActionMap ().put (key, yourCopyAction);
This code registers yourCopyAction with tc top component, so whenever a globalCopyAction is invoked, your action is being delegated to.

performer - the new action performer or null to disable


public void actionPerformed(ActionEvent ev)
Perform the action. Tries the performer and then scans the ActionMap of selected topcomponent.

Specified by:
actionPerformed in interface ActionListener
actionPerformed in class CallableSystemAction


public void performAction()
Perform the action. This default implementation calls the assigned action performer if it exists, otherwise does nothing.

Specified by:
performAction in class CallableSystemAction


public Object getActionMapKey()
Getter for action map key, which is used to find action from provided context (i.e. ActionMap provided by the context), which acts as a callback. Override this method in subclasses to provide 'nice' key.

key which is used to find the action which performs callback, default returned key is a class name.


public boolean getSurviveFocusChange()
Test whether the action will survive a change in focus. By default, it will not.

true if the enabled state of the action survives focus changes


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

Specified by:
createContextAwareInstance in interface ContextAwareAction


public void setSurviveFocusChange(boolean b)
Set whether the action will survive a change in focus. If false, then the action will be automatically disabled (using setActionPerformer(org.openide.util.actions.ActionPerformer)) when the window focus changes.

b - true to survive focus changes, false to be sensitive to them


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