dsto.dfc.swt.commands
Class AbstractCommand

java.lang.Object
  extended by dsto.dfc.util.BasicPropertyEventSource
      extended by dsto.dfc.swt.commands.AbstractCommand
All Implemented Interfaces:
Command, Copyable, JavaBean, PropertyEventSource, Serializable, Cloneable
Direct Known Subclasses:
AbstractAboutCommand, AbstractAddEntryCommand, AbstractCopyCommand, AbstractCreateItemCommand, AbstractCutCommand, AbstractDeleteCommand, AbstractPasteCommand, AbstractPropertiesCommand, BasicExitCommand, BasicToggleCommand, CmdAboutBox, CmdChangeDataObjectProperty, CmdDeleteItem, CmdMoveItem, CmdRestartOsgi, CmdShowPanel, CmdShutdownOsgi, CmdToggleDataBeanProperty

public abstract class AbstractCommand
extends BasicPropertyEventSource
implements Command, Copyable

Base class for most commands. Subclasses only have to implement execute().

Version:
$Revision$
See Also:
Serialized Form

Field Summary
static Icon NO_ICON
          Value to use when a command has no icon.
 
Constructor Summary
AbstractCommand(String name, Icon icon, String group, String description, boolean interactive)
          Create a new instance.
AbstractCommand(String name, Icon icon, String group, String description, boolean interactive, char mnemonic, int accelerator)
          Create a new instance.
AbstractCommand(String name, String iconName, String group, String description, boolean interactive)
          Create a new instance.
AbstractCommand(String name, String iconName, String group, String description, boolean interactive, char mnemonic, int accelerator)
          Create a new instance.
 
Method Summary
 void addCommandListener(CommandListener l)
           
 Object clone()
          Create a completely separate copy of this object and any mutable objects owned by the object.
protected  String createDefaultDisplayName()
          Generates a display name based on the last component of the command name.
abstract  void execute()
          Execute the command.
 void fireCommandExecuted()
           
 void fireCommandExecuted(Object data)
           
 int getAccelerator()
          eg SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2
 String getContextMenuGroup()
           
 String getDescription()
          A short description of the command, suitable for a tooltip or use in a status panel.
 String getDisplayName()
          The name of the command as it should be displayed (eg on a menu).
 String getGroupInView(String viewName)
          Get the preferred group that this command should appear in for a given view.
 Icon getIcon()
          The symbolic icon for the command.
 String getLogString()
          Simply returns the command name followed by empty brackets.
 String getMainMenuGroup()
           
 char getMnemonic()
          Get a character shortcut for the command (eg for use on a menu).
 String getName()
          The formal identifying name for this command (eg edit.Copy, file.Open).
 String getToolbarGroup()
           
 boolean isEnabled()
          True if the command is enabled, ie able to execute in the current context.
 boolean isInteractive()
          True if this command will interact with the user when execute () is called.
 void removeCommandListener(CommandListener l)
           
 void setAccelerator(int newAccelerator)
          Sets the accelerator.
 void setContextMenuGroup(String newContextMenuGroup)
          Sets the contextMenuGroup.
 void setDescription(String newDescription)
          Sets the description.
 void setDisplayName(String newDisplayName)
           
 void setEnabled(boolean newValue)
           
 void setIcon(Icon newIcon)
           
 void setInteractive(boolean newInteractive)
          Sets the interactive.
 void setMainMenuGroup(String newMainMenuGroup)
          Sets the mainMenuGroup.
 void setMnemonic(char newMnemonic)
          Sets the mnemonic.
 void setName(String newName)
          Sets the name.
 void setToolbarGroup(String newToolbarGroup)
          Sets the toolbarGroup.
 
Methods inherited from class dsto.dfc.util.BasicPropertyEventSource
addPropertyChangeListener, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeSource, removePropertyChangeListener, setPropertyChangeSource
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dsto.dfc.util.PropertyEventSource
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

NO_ICON

public static final Icon NO_ICON
Value to use when a command has no icon. Resolves problem in distinguishing constructors when passing null as icon argument.

Constructor Detail

AbstractCommand

public AbstractCommand(String name,
                       Icon icon,
                       String group,
                       String description,
                       boolean interactive)
Create a new instance.

Parameters:
name - The command name.
icon - The icon resource name (passed to Images).
group - The base group for the command. This is used for the default context and toolbar groups. The main menu group is also derived from this.
description - A tooltip-length description of the command.
interactive - True of the command will interact with the user when executed.

AbstractCommand

public AbstractCommand(String name,
                       String iconName,
                       String group,
                       String description,
                       boolean interactive)
Create a new instance.

Parameters:
name - The command name.
iconName - The icon resource name (passed to Images).
group - The base group for the command. This is used for the default context and toolbar groups. The main menu group is also derived from this.
description - A tooltip-length description of the command.
interactive - True of the command will interact with the user when executed.

AbstractCommand

public AbstractCommand(String name,
                       String iconName,
                       String group,
                       String description,
                       boolean interactive,
                       char mnemonic,
                       int accelerator)
Create a new instance.

Parameters:
name - The command name.
iconName - The icon resource name (passed to Images).
group - The base group for the command. This is used for the default context and toolbar groups. The main menu group is also derived from this.
description - A tooltip-length description of the command.
interactive - True of the command will interact with the user when executed.
mnemonic - A menu mnemonic for the command.
accelerator - The global accelerator key for the command.

AbstractCommand

public AbstractCommand(String name,
                       Icon icon,
                       String group,
                       String description,
                       boolean interactive,
                       char mnemonic,
                       int accelerator)
Create a new instance.

Parameters:
name - The command name.
icon - The command icon.
group - The base group for the command. This is used for the default context and toolbar groups. The main menu group is also derived from this.
description - A tooltip-length description of the command.
interactive - True of the command will interact with the user when executed.
mnemonic - A menu mnemonic for the command.
accelerator - The global accelerator key for the command.
Method Detail

clone

public Object clone()
             throws CloneNotSupportedException
Description copied from interface: Copyable
Create a completely separate copy of this object and any mutable objects owned by the object.

NOTE: subclasses should not remove the CloneNotSupportedException throws clause if they themselves support subclassing: removing the CloneNotSupportedException declaration stops subclasses from indicating that a clone was not possible.

Specified by:
clone in interface Copyable
Overrides:
clone in class BasicPropertyEventSource
Throws:
CloneNotSupportedException - if the clone failed or is not possible.

execute

public abstract void execute()
Description copied from interface: Command
Execute the command. Commands should fire CommandListener.commandExecuted(CommandEvent) when executed.

Specified by:
execute in interface Command

addCommandListener

public void addCommandListener(CommandListener l)
Specified by:
addCommandListener in interface Command

removeCommandListener

public void removeCommandListener(CommandListener l)
Specified by:
removeCommandListener in interface Command

getGroupInView

public String getGroupInView(String viewName)
Description copied from interface: Command
Get the preferred group that this command should appear in for a given view. eg "File.doc" for a main menu or "edit" for a context menu. Deeply nested groups such as "View.window.Windows.recent" will be placed in nested pullright menus.

NOTE: groups may be overridden by a setting in the CommandRegistry.

If the command changes its group it should generate a property change event with the property name the name of the view, the old value set to the old group and the new value set to the new group.

Specified by:
getGroupInView in interface Command
Parameters:
viewName - The name of the view.
Returns:
The group in the view, or null if this command does not appear in the given view.

getIcon

public Icon getIcon()
Description copied from interface: Command
The symbolic icon for the command. May be null.

Specified by:
getIcon in interface Command

setIcon

public void setIcon(Icon newIcon)
Specified by:
setIcon in interface Command

getName

public String getName()
Description copied from interface: Command
The formal identifying name for this command (eg edit.Copy, file.Open). This must not change during the lifetime of a command instance.

Specified by:
getName in interface Command

getDescription

public String getDescription()
Description copied from interface: Command
A short description of the command, suitable for a tooltip or use in a status panel.

Specified by:
getDescription in interface Command

isInteractive

public boolean isInteractive()
Description copied from interface: Command
True if this command will interact with the user when execute () is called.

Specified by:
isInteractive in interface Command

getMainMenuGroup

public String getMainMenuGroup()

getContextMenuGroup

public String getContextMenuGroup()

getToolbarGroup

public String getToolbarGroup()

getMnemonic

public char getMnemonic()
Description copied from interface: Command
Get a character shortcut for the command (eg for use on a menu). May Return 0 for no mnemonic.

Specified by:
getMnemonic in interface Command

getAccelerator

public int getAccelerator()
eg SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2

Specified by:
getAccelerator in interface Command
Returns:
The SWT acclerator (eg SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2) or 0 for no accelerator.

getDisplayName

public String getDisplayName()
Description copied from interface: Command
The name of the command as it should be displayed (eg on a menu). May be null in which case the command name (or some derivative) will be used.

Specified by:
getDisplayName in interface Command

setDisplayName

public void setDisplayName(String newDisplayName)
Specified by:
setDisplayName in interface Command

createDefaultDisplayName

protected String createDefaultDisplayName()
Generates a display name based on the last component of the command name. eg "file.oc.Edit" becomes "Edit". Adds mnemonic & if mnemonic is set.


getLogString

public String getLogString()
Simply returns the command name followed by empty brackets.

Specified by:
getLogString in interface Command

isEnabled

public boolean isEnabled()
Description copied from interface: Command
True if the command is enabled, ie able to execute in the current context.

Specified by:
isEnabled in interface Command

setEnabled

public void setEnabled(boolean newValue)
Specified by:
setEnabled in interface Command

setAccelerator

public void setAccelerator(int newAccelerator)
Sets the accelerator.

Specified by:
setAccelerator in interface Command
Parameters:
newAccelerator - The accelerator to set

setContextMenuGroup

public void setContextMenuGroup(String newContextMenuGroup)
Sets the contextMenuGroup.

Specified by:
setContextMenuGroup in interface Command
Parameters:
newContextMenuGroup - The contextMenuGroup to set
See Also:
Command.getGroupInView(String)

setDescription

public void setDescription(String newDescription)
Sets the description.

Specified by:
setDescription in interface Command
Parameters:
newDescription - The description to set

setInteractive

public void setInteractive(boolean newInteractive)
Sets the interactive.

Parameters:
newInteractive - The interactive to set

setMainMenuGroup

public void setMainMenuGroup(String newMainMenuGroup)
Sets the mainMenuGroup.

Specified by:
setMainMenuGroup in interface Command
Parameters:
newMainMenuGroup - The mainMenuGroup to set
See Also:
Command.getGroupInView(String)

setMnemonic

public void setMnemonic(char newMnemonic)
Sets the mnemonic.

Specified by:
setMnemonic in interface Command
Parameters:
newMnemonic - The mnemonic to set

setName

public void setName(String newName)
Sets the name.

Parameters:
newName - The name to set

setToolbarGroup

public void setToolbarGroup(String newToolbarGroup)
Sets the toolbarGroup.

Specified by:
setToolbarGroup in interface Command
Parameters:
newToolbarGroup - The toolbarGroup to set
See Also:
Command.getGroupInView(String)

fireCommandExecuted

public void fireCommandExecuted()

fireCommandExecuted

public void fireCommandExecuted(Object data)


Copyright © 2008 Commonwealth of Australia