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

CallbackSystemAction (NetBeans Utilities API) - NetBeans API Javadoc 5.0.0

 

org.openide.util.actions
Class CallbackSystemAction

java.lang.Object
  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
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(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

CallbackSystemAction

public CallbackSystemAction()
Method Detail

initialize

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

Overrides:
initialize in class SystemAction

getActionPerformer

public ActionPerformer getActionPerformer()
Get the current action performer.

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

setActionPerformer

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(ActionEvent ev)
Perform the action. Tries the performer and then scans the ActionMap of selected topcomponent.

Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class CallableSystemAction

performAction

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

getActionMapKey

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.

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 Action createContextAwareInstance(Lookup actionContext)
Implements ContextAwareAction interface method.

Specified by:
createContextAwareInstance in interface ContextAwareAction

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

 

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