org.openide.util.actions
Class CallbackSystemAction

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.CallbackSystemAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Externalizable, java.io.Serializable, java.util.EventListener, javax.swing.Action, Presenter, Presenter.Menu, Presenter.Popup, Presenter.Toolbar, ContextAwareAction, HelpCtx.Provider

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.

Author:
Ian Formanek, Jaroslav Tulach, Petr Hamernik
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
(package private) static long serialVersionUID
           
 
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
CallbackSystemAction()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ev)
          Perform the action.
 javax.swing.Action createContextAwareInstance(Lookup actionContext)
          Implements ContextAwareAction interface method.
 java.lang.Object getActionMapKey()
          Getter for action map key, which is used to find action from provided context (i.e.
 ActionPerformer getActionPerformer()
          Deprecated. use TopComponent.getActionMap() as described in the javadoc
 boolean getSurviveFocusChange()
          Test whether the action will survive a change in focus.
protected  void initialize()
          Initialize the action to have no performer.
 void performAction()
          Deprecated. This only uses ActionPerformer. Use actionPerformed(java.awt.event.ActionEvent) instead.
 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
 

Field Detail

serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

CallbackSystemAction

public CallbackSystemAction()
Method Detail

initialize

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

Overrides:
initialize in class SystemAction

getActionPerformer

@Deprecated
public ActionPerformer getActionPerformer()
Deprecated. use TopComponent.getActionMap() as described in the javadoc

Get the current action performer.

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

setActionPerformer

@Deprecated
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.

Parameters:
performer - the new action performer or null to disable

actionPerformed

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

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class CallableSystemAction
Parameters:
ev - the event triggering the action

performAction

@Deprecated
public void performAction()
Deprecated. This only uses ActionPerformer. Use actionPerformed(java.awt.event.ActionEvent) instead.

Perform the action. This default implementation calls the assigned action performer if it exists, otherwise does nothing.

Specified by:
performAction in class CallableSystemAction

getActionMapKey

public java.lang.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.

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

getSurviveFocusChange

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

Returns:
true if the enabled state of the action survives focus changes

createContextAwareInstance

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

Specified by:
createContextAwareInstance in interface ContextAwareAction
Parameters:
actionContext - an arbitrary context (e.g. "cookies" from a node selection)
Returns:
a transient action whose behavior applies only to that context

setSurviveFocusChange

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.

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