com.tensegrity.gui.swt.repository
Class ActionSwtRepositoryItem

java.lang.Object
  extended byorg.eclipse.swt.widgets.Widget
      extended byorg.eclipse.swt.widgets.Control
          extended byorg.eclipse.swt.widgets.Scrollable
              extended byorg.eclipse.swt.widgets.Composite
                  extended bycom.tensegrity.gui.swt.repository.AbstractSwtRepositoryItem
                      extended bycom.tensegrity.gui.swt.repository.ActionSwtRepositoryItem
All Implemented Interfaces:
org.eclipse.swt.graphics.Drawable, java.util.EventListener, org.eclipse.swt.events.MouseListener, org.eclipse.swt.events.MouseTrackListener, org.eclipse.swt.internal.SWTEventListener

public class ActionSwtRepositoryItem
extends AbstractSwtRepositoryItem

An ActionSwtRepositoryItem is a AbstractSwtRepositoryItem which can perform a given action (i.e. perform a Command) upon a left or right mouse click.

Three constructors are available, the more useful ones being ActionSwtRepositoryItem(Composite, String, Class, Command, String, int, int) and ActionSwtRepositoryItem(Composite, SwtIcon, Command, String, int, int) since they set the icon one the ActionSwtRepositoryItem instance.

Note that by default no AbstractSwtDragSourceListener is set, but one can use the setDragListener(AbstractSwtDragSourceListener) method in order to set one.

Subclasses might consider overridding invokeRightClickAction(MouseEvent) for example in order to add a context menu to instances of ActionSwtRepositoryItem.

Note that this class can be considered as the SWT equivalent of ActionRepositoryItem.

One should call the dispose() method in order to free all allocated resources once instances of this class are no longer needed.

Version:
$Id: ActionSwtRepositoryItem.java,v 1.14 2006/05/04 08:51:18 ArndHouben Exp $
Author:
S�bastien Guyon

Nested Class Summary
static class ActionSwtRepositoryItem.ClickActionProvider
           This class allows, by mean of inheritance, to customize the application behaviour when a left or right mouse click is performed upon repository items.
 
Field Summary
 
Fields inherited from class com.tensegrity.gui.swt.repository.AbstractSwtRepositoryItem
DEFAULT_WIDTH_AND_HEIGHT, mouseIn, mousePressed
 
Fields inherited from class org.eclipse.swt.widgets.Control
handle
 
Constructor Summary
ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent, Command action, java.lang.String tooltip, int iconWidth, int iconHeight)
          Creates an instance of ActionSwtRepositoryItem with no associated icon.
ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent, java.lang.String iconPath, java.lang.Class resourceclass, Command action, java.lang.String tooltip, int iconWidth, int iconHeight)
          Creates an instance of ActionSwtRepositoryItem with the image which can be loaded using the two parameters iconPath and resourceclass.
ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent, SwtIcon icon, Command action, java.lang.String tooltip, int iconWidth, int iconHeight)
          Creates an instance of ActionSwtRepositoryItem which displays the passed icon.
 
Method Summary
 ActionSwtRepositoryItem.ClickActionProvider getClickActionProvider()
          Returns the clickActionProvider.
protected  AbstractSwtDragSourceListener getDragListener()
           Returns the AbstractSwtDragSourceListener associated to this repository item.
protected  java.lang.Object getTooltip()
           Returns the tooltip for this repository item.
 java.lang.String getToolTipText()
           
 void invokeLeftClickAction(org.eclipse.swt.events.MouseEvent e)
          Invokes the actionPerformed of the internal Action instance.
 void invokeRightClickAction(org.eclipse.swt.events.MouseEvent e)
          Forwards to the invokeLeftClickAction, but can be overriden to implement context menus on repository items.
 boolean isCommandEnabled()
           Check whether or not the command is enabled
 void mouseDown(org.eclipse.swt.events.MouseEvent e)
           
 void performAction()
          Perform the registered action
 void setClickActionProvider(ActionSwtRepositoryItem.ClickActionProvider clickActionProvider)
          Sets the value of clickActionProvider
 void setDragListener(AbstractSwtDragSourceListener dragListener)
           Associates the given AbstractSwtDragSourceListener with this instance of ActionSwtRepositoryItem.
 void setText(java.lang.String text)
          Overridden method change the tooltip controlled by an UIManager-instance.
 
Methods inherited from class com.tensegrity.gui.swt.repository.AbstractSwtRepositoryItem
dispose, getIconHeight, getIconlabel, getIconWidth, initToolTipGenerator, installDragging, mouseDoubleClick, mouseEnter, mouseExit, mouseHover, mouseUp, setImage
 
Methods inherited from class org.eclipse.swt.widgets.Composite
checkSubclass, computeSize, getChildren, getLayout, getTabList, layout, layout, setFocus, setLayout, setTabList
 
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
 
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addFocusListener, addHelpListener, addKeyListener, addMouseListener, addMouseMoveListener, addMouseTrackListener, addPaintListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBorderWidth, getBounds, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getParent, getShell, getSize, getVisible, internal_dispose_GC, internal_new_GC, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeFocusListener, removeHelpListener, removeKeyListener, removeMouseListener, removeMouseMoveListener, removeMouseTrackListener, removePaintListener, removeTraverseListener, setBackground, setBounds, setBounds, setCapture, setCursor, setEnabled, setFont, setForeground, setLayoutData, setLocation, setLocation, setMenu, setParent, setRedraw, setSize, setSize, setToolTipText, setVisible, toControl, toControl, toDisplay, toDisplay, traverse, update
 
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkWidget, getData, getData, getDisplay, getStyle, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ActionSwtRepositoryItem

public ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent,
                               java.lang.String iconPath,
                               java.lang.Class resourceclass,
                               Command action,
                               java.lang.String tooltip,
                               int iconWidth,
                               int iconHeight)
Creates an instance of ActionSwtRepositoryItem with the image which can be loaded using the two parameters iconPath and resourceclass. Upon left or right mouse click the given Command is performed.

Parameters:
parent - widget which will be the parent of the new instance (cannot be null)
iconPath - the path to the image relative to resourceclass
resourceclass - the class used to load the icon
action - the Command to perform on click, cannot be null
tooltip - the tooltip, which may be null
iconWidth - the icon width
iconHeight - the icon height

ActionSwtRepositoryItem

public ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent,
                               Command action,
                               java.lang.String tooltip,
                               int iconWidth,
                               int iconHeight)
Creates an instance of ActionSwtRepositoryItem with no associated icon. Upon left or right mouse click the given Command is performed.

Parameters:
parent - widget which will be the parent of the new instance (cannot be null)
action - the Command to perform on click, cannot be null
tooltip - the tooltip, which may be null
iconWidth - the icon width
iconHeight - the icon height

ActionSwtRepositoryItem

public ActionSwtRepositoryItem(org.eclipse.swt.widgets.Composite parent,
                               SwtIcon icon,
                               Command action,
                               java.lang.String tooltip,
                               int iconWidth,
                               int iconHeight)
Creates an instance of ActionSwtRepositoryItem which displays the passed icon. Upon left or right mouse click the given Command is performed.

Parameters:
parent - widget which will be the parent of the new instance (cannot be null)
icon - optional icon, which may be null
action - the Command to perform on click, cannot be null
tooltip - the tooltip, which may be null
iconWidth - the icon width
iconHeight - the icon height
Method Detail

setText

public void setText(java.lang.String text)
Overridden method change the tooltip controlled by an UIManager-instance.

Overrides:
setText in class AbstractSwtRepositoryItem
Parameters:
text - the new tooltip text.

invokeRightClickAction

public void invokeRightClickAction(org.eclipse.swt.events.MouseEvent e)
Forwards to the invokeLeftClickAction, but can be overriden to implement context menus on repository items.

Parameters:
e - the MouseEvent.

invokeLeftClickAction

public void invokeLeftClickAction(org.eclipse.swt.events.MouseEvent e)
Invokes the actionPerformed of the internal Action instance. NOTE: You may consider to use invokeLater here to allow Labels mousePressed to return *BEFORE* the actionPerformed has been processed.

Parameters:
e - the MouseEvent.

performAction

public void performAction()
Perform the registered action


getDragListener

protected AbstractSwtDragSourceListener getDragListener()
Description copied from class: AbstractSwtRepositoryItem

Returns the AbstractSwtDragSourceListener associated to this repository item.

Specified by:
getDragListener in class AbstractSwtRepositoryItem
Returns:
the AbstractSwtDragSourceListener associated to this repository item.

setDragListener

public void setDragListener(AbstractSwtDragSourceListener dragListener)

Associates the given AbstractSwtDragSourceListener with this instance of ActionSwtRepositoryItem.

Parameters:
dragListener - the new AbstractSwtDragSourceListener associated with this instance of ActionSwtRepositoryItem

getTooltip

protected java.lang.Object getTooltip()
Description copied from class: AbstractSwtRepositoryItem

Returns the tooltip for this repository item.

Specified by:
getTooltip in class AbstractSwtRepositoryItem
Returns:
the tooltip for this repository item.

getToolTipText

public java.lang.String getToolTipText()

mouseDown

public void mouseDown(org.eclipse.swt.events.MouseEvent e)
Specified by:
mouseDown in interface org.eclipse.swt.events.MouseListener
Overrides:
mouseDown in class AbstractSwtRepositoryItem

setClickActionProvider

public void setClickActionProvider(ActionSwtRepositoryItem.ClickActionProvider clickActionProvider)
Sets the value of clickActionProvider

Parameters:
clickActionProvider - The new value to set.

getClickActionProvider

public ActionSwtRepositoryItem.ClickActionProvider getClickActionProvider()
Returns the clickActionProvider.

Returns:
the clickActionProvider.

isCommandEnabled

public boolean isCommandEnabled()

Check whether or not the command is enabled

Returns:
true if the command is enabled, false otherwise


Copyright © 2005 Tensegrity Software GmbH. All Rights Reserved. Date of creation: 09.06.2006.