Package org.eclipse.gef.ui.actions
Class WorkbenchPartAction
- java.lang.Object
-
- org.eclipse.core.commands.common.EventManager
-
- org.eclipse.jface.action.AbstractAction
-
- org.eclipse.jface.action.Action
-
- org.eclipse.gef.ui.actions.WorkbenchPartAction
-
- All Implemented Interfaces:
Disposable
,UpdateAction
,IAction
- Direct Known Subclasses:
CopyTemplateAction
,EditorPartAction
,PrintAction
,SelectionAction
,StackAction
public abstract class WorkbenchPartAction extends Action implements Disposable, UpdateAction
Base class for actions involving a WorkbenchPart. The workbench part is useful for obtaining data needed by the action. For example, selection can be obtained using the part's site. Anything can potentially be obtained usingIAdaptable.getAdapter(java.lang.Class)
.
-
-
Field Summary
-
Fields inherited from interface org.eclipse.jface.action.IAction
AS_CHECK_BOX, AS_DROP_DOWN_MENU, AS_PUSH_BUTTON, AS_RADIO_BUTTON, AS_UNSPECIFIED, CHECKED, DESCRIPTION, ENABLED, HANDLED, IMAGE, RESULT, TEXT, TOOL_TIP_TEXT
-
-
Constructor Summary
Constructors Constructor Description WorkbenchPartAction(IWorkbenchPart part)
Constructs a WorkbenchPartAction for the given part.WorkbenchPartAction(IWorkbenchPart part, int style)
Constructs a WorkbenchPartAction for the given part and style.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract boolean
calculateEnabled()
Calculates and returns the enabled state of this action.void
dispose()
Disposes the action when it is no longer needed.protected void
execute(Command command)
Executes the givenCommand
using the command stack.protected CommandStack
getCommandStack()
Returns the editor's command stack.protected IWorkbenchPart
getWorkbenchPart()
Returns the workbench part given in the constructorprotected void
init()
Initializes this action.boolean
isEnabled()
Returnstrue
if the action is enabled.protected void
refresh()
Refreshes the properties of this action.void
setLazyEnablementCalculation(boolean value)
Sets lazy calculation of the isEnabled property.protected void
setWorkbenchPart(IWorkbenchPart part)
Sets the workbench part.void
update()
Called to update the receiver.-
Methods inherited from class org.eclipse.jface.action.Action
convertAccelerator, convertAccelerator, findKeyCode, findKeyString, findModifier, findModifierString, getAccelerator, getActionDefinitionId, getDescription, getDisabledImageDescriptor, getHelpListener, getHoverImageDescriptor, getId, getImageDescriptor, getMenuCreator, getStyle, getText, getToolTipText, isChecked, isHandled, notifyResult, removeAcceleratorText, removeMnemonics, run, runWithEvent, setAccelerator, setActionDefinitionId, setChecked, setDescription, setDisabledImageDescriptor, setEnabled, setHelpListener, setHoverImageDescriptor, setId, setImageDescriptor, setMenuCreator, setText, setToolTipText
-
Methods inherited from class org.eclipse.jface.action.AbstractAction
addPropertyChangeListener, firePropertyChange, firePropertyChange, removePropertyChangeListener
-
Methods inherited from class org.eclipse.core.commands.common.EventManager
addListenerObject, clearListeners, getListeners, isListenerAttached, removeListenerObject
-
-
-
-
Constructor Detail
-
WorkbenchPartAction
public WorkbenchPartAction(IWorkbenchPart part)
Constructs a WorkbenchPartAction for the given part.- Parameters:
part
- the workbench part
-
WorkbenchPartAction
public WorkbenchPartAction(IWorkbenchPart part, int style)
Constructs a WorkbenchPartAction for the given part and style.- Parameters:
part
- the workbench partstyle
- one ofAS_PUSH_BUTTON
,AS_CHECK_BOX
,AS_DROP_DOWN_MENU
,AS_RADIO_BUTTON
, andAS_UNSPECIFIED
.
-
-
Method Detail
-
calculateEnabled
protected abstract boolean calculateEnabled()
Calculates and returns the enabled state of this action.- Returns:
true
if the action is enabled
-
dispose
public void dispose()
Disposes the action when it is no longer needed.- Specified by:
dispose
in interfaceDisposable
-
execute
protected void execute(Command command)
Executes the givenCommand
using the command stack. The stack is obtained by callinggetCommandStack()
, which usesIAdapatable
to retrieve the stack from the workbench part.- Parameters:
command
- the command to execute
-
getCommandStack
protected CommandStack getCommandStack()
Returns the editor's command stack. This is done by asking the workbench part for its CommandStack viaIAdaptable.getAdapter(java.lang.Class)
.- Returns:
- the command stack
-
getWorkbenchPart
protected IWorkbenchPart getWorkbenchPart()
Returns the workbench part given in the constructor- Returns:
- the workbench part
-
init
protected void init()
Initializes this action.
-
isEnabled
public boolean isEnabled()
Returnstrue
if the action is enabled. If the action determines enablemenu lazily, thencalculateEnabled()
is always called. Otherwise, the enablement state set usingAction.setEnabled(boolean)
is returned.- Specified by:
isEnabled
in interfaceIAction
- Overrides:
isEnabled
in classAction
- Returns:
true
if the action is enabled- See Also:
setLazyEnablementCalculation(boolean)
-
refresh
protected void refresh()
Refreshes the properties of this action.
-
setLazyEnablementCalculation
public void setLazyEnablementCalculation(boolean value)
Sets lazy calculation of the isEnabled property. If this value is set totrue
, then the action will always usecalculateEnabled()
wheneverisEnabled()
is called.Sometimes a value of
false
can be used to improve performance and reduce the number of timescalculateEnabled()
is called. However, the client must then call theupdate()
method at the proper times to force the update of enablement.Sometimes a value of
true
can be used to improve performance. If anAction
only appears in a dynamic context menu, then there is no reason to agressively update its enablement status because the user cannot see the Action. Instead, its enablement only needs to be determined when asked for, or lazily.The default value for this setting is
true
.- Parameters:
value
-true
if the enablement should be lazy
-
setWorkbenchPart
protected void setWorkbenchPart(IWorkbenchPart part)
Sets the workbench part.- Parameters:
part
- the workbench part
-
update
public void update()
Description copied from interface:UpdateAction
Called to update the receiver.- Specified by:
update
in interfaceUpdateAction
- See Also:
UpdateAction.update()
-
-