dsto.dfc.swt.viewers
Class CmdMoveItem

java.lang.Object
  extended by dsto.dfc.util.BasicPropertyEventSource
      extended by dsto.dfc.swt.commands.AbstractCommand
          extended by dsto.dfc.swt.viewers.CmdMoveItem
All Implemented Interfaces:
CollectionListener, DfcMonitoredListListener, Command, Copyable, JavaBean, PropertyEventSource, Serializable, Cloneable, EventListener, org.eclipse.jface.viewers.ISelectionChangedListener, org.eclipse.swt.events.DisposeListener, org.eclipse.swt.internal.SWTEventListener

public class CmdMoveItem
extends AbstractCommand
implements org.eclipse.jface.viewers.ISelectionChangedListener, DfcMonitoredListListener, org.eclipse.swt.events.DisposeListener

Generic command to move items up/down in a viewer that is displaying a java.util.List. If the list is a DfcMonitoredList (which supports in-place movement of items) move () is used rather than remove/add.

See Also:
Serialized Form

Field Summary
protected  int direction
           
static int DOWN
           
protected  List items
           
static int UP
           
protected  org.eclipse.jface.viewers.Viewer viewer
           
 
Fields inherited from class dsto.dfc.swt.commands.AbstractCommand
NO_ICON
 
Constructor Summary
CmdMoveItem(org.eclipse.jface.viewers.Viewer viewer, int direction)
          Create a new instance.
 
Method Summary
protected  boolean canMove(List toMove)
           
 void dispose()
           
 void elementMoved(CollectionEvent e)
          Fired when an element in the list has moved (changed indexes).
 void elementsAdded(CollectionEvent e)
           
 void elementsRemoved(CollectionEvent e)
           
 void execute()
          Execute the command.
protected  void inputChanged(List oldInput, List newInput)
           
protected  void moveItem(int oldIndex, int newIndex)
           
 void selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent e)
           
 void setInput(List newItems)
          Notify the command that the input to the viewer has changed (there is no automatic way to do this).
protected  void updateEnabled()
          Update the enabled status of the command given the current selected items.
 void widgetDisposed(org.eclipse.swt.events.DisposeEvent e)
           
 
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

UP

public static final int UP
See Also:
Constant Field Values

DOWN

public static final int DOWN
See Also:
Constant Field Values

viewer

protected org.eclipse.jface.viewers.Viewer viewer

items

protected List items

direction

protected int direction
Constructor Detail

CmdMoveItem

public CmdMoveItem(org.eclipse.jface.viewers.Viewer viewer,
                   int direction)
Create a new instance.

Parameters:
viewer - The viewer.
direction - The direction to move the entries (MOVE_UP or MOVE_DOWN).
See Also:
setInput(List)
Method Detail

dispose

public void dispose()

setInput

public void setInput(List newItems)
Notify the command that the input to the viewer has changed (there is no automatic way to do this). If the items list also implements MonitoredCollection it is tracked and the command will be correctly enabled/disabled depending on the current context.


inputChanged

protected void inputChanged(List oldInput,
                            List newInput)

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

moveItem

protected void moveItem(int oldIndex,
                        int newIndex)

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 canMove () is true.


canMove

protected boolean canMove(List toMove)

selectionChanged

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

elementsAdded

public void elementsAdded(CollectionEvent e)
Specified by:
elementsAdded in interface CollectionListener

elementsRemoved

public void elementsRemoved(CollectionEvent e)
Specified by:
elementsRemoved in interface CollectionListener

elementMoved

public void elementMoved(CollectionEvent e)
Description copied from interface: DfcMonitoredListListener
Fired when an element in the list has moved (changed indexes).

Specified by:
elementMoved in interface DfcMonitoredListListener
Parameters:
e - The move event. startIndex is the element's old index, endIndex is the new index.

widgetDisposed

public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e)
Specified by:
widgetDisposed in interface org.eclipse.swt.events.DisposeListener


Copyright © 2008 Commonwealth of Australia