dsto.dfc.swt.viewers
Class CmdDeleteItem

java.lang.Object
  extended by dsto.dfc.util.BasicPropertyEventSource
      extended by dsto.dfc.swt.commands.AbstractCommand
          extended by dsto.dfc.swt.viewers.CmdDeleteItem
All Implemented Interfaces:
Command, Copyable, Disposable, JavaBean, PropertyEventSource, Serializable, Cloneable, org.eclipse.jface.viewers.ISelectionChangedListener

public class CmdDeleteItem
extends AbstractCommand
implements org.eclipse.jface.viewers.ISelectionChangedListener, Disposable

Generic "Delete Items" command for JFace Viewer's showing a Collection (although could be subclassed for non Collection's). The default behaviour is to remove () the selected items from the collection. Subclasses may choose to override canDelete(List), confirmDelete, deleteItems(List) and updateEnabled() to customize behaviour.

Version:
$Revision$
Author:
mpp
See Also:
Serialized Form

Field Summary
protected  boolean confirmDelete
           
protected  String confirmMessage
           
protected  Collection items
           
protected  org.eclipse.jface.viewers.Viewer viewer
           
 
Fields inherited from class dsto.dfc.swt.commands.AbstractCommand
NO_ICON
 
Constructor Summary
CmdDeleteItem(org.eclipse.jface.viewers.Viewer viewer)
          Create a new instance.
CmdDeleteItem(org.eclipse.jface.viewers.Viewer viewer, Collection items)
          Create a new instance.
 
Method Summary
protected  boolean canDelete(List toDelete)
          Check if all the items in the list can be deleted (eg some items may be undeletable).
protected  boolean confirmDelete(List toDelete)
          Confirm with the user that it's OK to delete the given items.
protected  void deleteItems(List toDelete)
          Delete the given items.
 void dispose()
          Dispose of the object (unregister listeners, close open resources etc).
 void execute()
          Execute the command.
 String getConfirmMessage()
           
protected  Collection getItems()
           
 boolean isConfirmDelete()
           
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent e)
           
 void setConfirmDelete(boolean confirmDelete)
          Set whether the default confirmDelete () method will ask the user to confirm the operation.
 void setConfirmMessage(String message)
          Set the message that is displayed in the confirm dialog.
protected  void updateEnabled()
          Update the enabled status of the command given the current selected items.
 
Methods inherited from class dsto.dfc.swt.commands.AbstractCommand
addCommandListener, clone, createDefaultDisplayName, fireCommandExecuted, fireCommandExecuted, getAccelerator, getContextMenuGroup, getDescription, getDisplayName, getGroupInView, getIcon, getLogString, getMainMenuGroup, getMnemonic, getName, getToolbarGroup, isEnabled, isInteractive, removeCommandListener, setAccelerator, setContextMenuGroup, setDescription, setDisplayName, setEnabled, setIcon, setInteractive, setMainMenuGroup, setMnemonic, setName, setToolbarGroup
 
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

viewer

protected org.eclipse.jface.viewers.Viewer viewer

items

protected Collection items

confirmDelete

protected boolean confirmDelete

confirmMessage

protected String confirmMessage
Constructor Detail

CmdDeleteItem

public CmdDeleteItem(org.eclipse.jface.viewers.Viewer viewer)
Create a new instance. The items to delete from are assumed to be the viewer's current input (ie from its getInput () method).


CmdDeleteItem

public CmdDeleteItem(org.eclipse.jface.viewers.Viewer viewer,
                     Collection items)
Create a new instance.

Parameters:
viewer - The viewer.
items - The items to delete from.
Method Detail

dispose

public void dispose()
Description copied from interface: Disposable
Dispose of the object (unregister listeners, close open resources etc). It should be safe to call this method more than once. Note for beans that support client event listeners: if there are listeners registered when this is called, this method should do nothing.

Specified by:
dispose in interface Disposable

isConfirmDelete

public boolean isConfirmDelete()

setConfirmDelete

public void setConfirmDelete(boolean confirmDelete)
Set whether the default confirmDelete () method will ask the user to confirm the operation.


setConfirmMessage

public void setConfirmMessage(String message)
Set the message that is displayed in the confirm dialog.


getConfirmMessage

public String getConfirmMessage()

execute

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

Specified by:
execute in interface Command
Specified by:
execute in class AbstractCommand

getItems

protected Collection getItems()

deleteItems

protected void deleteItems(List toDelete)
Delete the given items.


confirmDelete

protected boolean confirmDelete(List toDelete)
Confirm with the user that it's OK to delete the given items. This implementation pops up a yes/no dialog if confirmDelete is true.

Returns:
true if the items can be safely deleted.

canDelete

protected boolean canDelete(List toDelete)
Check if all the items in the list can be deleted (eg some items may be undeletable).

Returns:
True if all the items in the list can be deleted.

updateEnabled

protected void updateEnabled()
Update the enabled status of the command given the current selected items. Default is to be enabled when items is not empty and canDelete () is true.


selectionChanged

public void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent e)
Specified by:
selectionChanged in interface org.eclipse.jface.viewers.ISelectionChangedListener


Copyright © 2008 Commonwealth of Australia