at.spardat.xma.appshell
Class MenuItem

java.lang.Object
  extended byat.spardat.xma.appshell.MenuItem
All Implemented Interfaces:
IMenuItem

public class MenuItem
extends java.lang.Object
implements IMenuItem

Logical representation of a menu item. It contains a Task which is called every time the menu item is selected. It may contain a list of MenuItems representing its submenu. Internally it maintains references to its parent MenuItem, the AppShell the visual representation of the menu item.

Since:
1.4.0

Constructor Summary
MenuItem(IAppShell appShell)
          creates a MenuItem
MenuItem(java.lang.String name)
          creates a MenuItem
MenuItem(java.lang.String name, org.eclipse.swt.graphics.Image image)
           
MenuItem(java.lang.String name, int style)
          Note: For a MenuItem used at a MenuAppShell and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified.
MenuItem(java.lang.String name, int style, org.eclipse.swt.graphics.Image image)
          Note: For a MenuItem used at a MenuAppShell and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified.
MenuItem(java.lang.String name, Task task)
          creates a MenuItem
MenuItem(java.lang.String name, Task task, org.eclipse.swt.graphics.Image image)
           
MenuItem(java.lang.String name, Task task, int style)
          Note: For a MenuItem used at a ShellMenuAppShell (i.e. at an SWT menu) and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified.
MenuItem(java.lang.String name, Task task, int style, org.eclipse.swt.graphics.Image image)
          Note: For a MenuItem used at a ShellMenuAppShell (i.e. at an SWT menu) and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified.
 
Method Summary
 void addItem(int index, MenuItem item)
          Add the given MenuItem to the list of subitems at the given index.
 void addItem(MenuItem item)
          Add the given MenuItem to the list of subitems.
 void clearItems()
          Remove all MenuItems from the list of subitems.
 boolean containsItem(IMenuItem item)
          Determine if the given item is contained in the submenu of this menu.
 java.lang.Object getAttached()
          Get the visual representation of the MenuItem.
 org.eclipse.swt.graphics.Image getImage()
           
 int getIndex()
          Get the index of the MenuItem in the list of subitems in its parent.
 int getIndexOf(IMenuItem item)
          Get the index of the given MenuItem in the submenu of this.
 java.util.List getItems()
          Get the list of all MenuItems of the submenu of this MenuItem.
 java.lang.String getName()
          Get the name of the MenuItem.
 IMenuItem getParent()
          Get the MenuItem containing this MenuItem in its submenu.
 java.lang.Object getParentAttached()
          Get the visual representation of the parent MenuItem
 int getStyle()
          If no style was set then SWT.NONE is returned.
 ITask getTask()
          Get the Task than will be called whenever this MenuItem is selected.
 void removeItem(MenuItem item)
          Remove the given MenuItem from the list of subitems.
 void select()
          Select the MenuItem.
 void setAttached(java.lang.Object attached)
          Set the visual representation of the MenuItem e.g.: a ITreeWMClient or org.eclipse.swt.widget.MenuItem.
 void setImage(org.eclipse.swt.graphics.Image image)
          Sets the image to show at this item.
 void setName(java.lang.String name)
          Set the name of the MenuItem
 void setTask(ITask task)
          Set the task to run when the MenuItem is selected
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuItem

public MenuItem(IAppShell appShell)
creates a MenuItem

Parameters:
appShell - the AppShell containing the MenuItem

MenuItem

public MenuItem(java.lang.String name)
creates a MenuItem

Parameters:
name - the name of the MenuItem

MenuItem

public MenuItem(java.lang.String name,
                Task task)
creates a MenuItem

Parameters:
name - the name of the MenuItem
task - the task to run when the MenuItem is selected

MenuItem

public MenuItem(java.lang.String name,
                int style)
Note: For a MenuItem used at a MenuAppShell and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified. If this MenuItem has childs then only the style CASCADE is valid.

Parameters:
name - the name of the MenuItem
style - the SWT style

MenuItem

public MenuItem(java.lang.String name,
                org.eclipse.swt.graphics.Image image)
Parameters:
name - the name of the MenuItem
image - an image shown at the MenuItem

MenuItem

public MenuItem(java.lang.String name,
                int style,
                org.eclipse.swt.graphics.Image image)
Note: For a MenuItem used at a MenuAppShell and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified. If this MenuItem has childs then only the style CASCADE is valid.

Parameters:
name - the name of the MenuItem
style - the SWT style
image - an image shown at the MenuItem

MenuItem

public MenuItem(java.lang.String name,
                Task task,
                int style)
Note: For a MenuItem used at a ShellMenuAppShell (i.e. at an SWT menu) and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified. If this MenuItem has childs then only the style CASCADE is valid.

Parameters:
name - the name of the MenuItem
task - the task to run when the MenuItem is selected
style - the SWT style

MenuItem

public MenuItem(java.lang.String name,
                Task task,
                org.eclipse.swt.graphics.Image image)
Parameters:
name - the name of the MenuItem
task - the task to run when the MenuItem is selected
image - an image shown at the MenuItem

MenuItem

public MenuItem(java.lang.String name,
                Task task,
                int style,
                org.eclipse.swt.graphics.Image image)
Note: For a MenuItem used at a ShellMenuAppShell (i.e. at an SWT menu) and so representing an org.eclipse.swt.widgets.MenuItem only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR may be specified. If this MenuItem has childs then only the style CASCADE is valid.

Parameters:
name - the name of the MenuItem
task - the task to run when the MenuItem is selected
style - the SWT style
image - an image shown at the MenuItem
Method Detail

getName

public java.lang.String getName()
Get the name of the MenuItem. The name must be unique within the client side application.

Specified by:
getName in interface IMenuItem
Returns:
the name of the MenuItem

setName

public void setName(java.lang.String name)
Set the name of the MenuItem

Parameters:
name - the unique name of this item.

setTask

public void setTask(ITask task)
Set the task to run when the MenuItem is selected

Specified by:
setTask in interface IMenuItem
Parameters:
task - the task of this item.

getTask

public ITask getTask()
Get the Task than will be called whenever this MenuItem is selected.

Specified by:
getTask in interface IMenuItem
Returns:
the Task of this item.

getAttached

public java.lang.Object getAttached()
Get the visual representation of the MenuItem. e.g.: a ITreeWMClient or org.eclipse.swt.widget.MenuItem.

Specified by:
getAttached in interface IMenuItem
Returns:
the GUI-Object corresponding to this MenuItem.

setAttached

public void setAttached(java.lang.Object attached)
Set the visual representation of the MenuItem e.g.: a ITreeWMClient or org.eclipse.swt.widget.MenuItem.

Specified by:
setAttached in interface IMenuItem
Parameters:
attached - the GUI-Object corresponding to this MenuItem.

getImage

public org.eclipse.swt.graphics.Image getImage()
Specified by:
getImage in interface IMenuItem
Returns:
Returns the image which is shown at this item. Can be null

setImage

public void setImage(org.eclipse.swt.graphics.Image image)
Description copied from interface: IMenuItem
Sets the image to show at this item.

Specified by:
setImage in interface IMenuItem
Parameters:
image - Sets the image to show at this item.

getStyle

public int getStyle()
If no style was set then SWT.NONE is returned.

Specified by:
getStyle in interface IMenuItem
Returns:
Returns the SWT style set at this item.

getParentAttached

public java.lang.Object getParentAttached()
Get the visual representation of the parent MenuItem

Specified by:
getParentAttached in interface IMenuItem
Returns:
the GUI-Object corresponding to the parent of this MenuItem.

getParent

public IMenuItem getParent()
Get the MenuItem containing this MenuItem in its submenu.

Returns:
the parent MenuItem.

getIndex

public int getIndex()
Get the index of the MenuItem in the list of subitems in its parent.

Specified by:
getIndex in interface IMenuItem
Returns:
the index of this.

getIndexOf

public int getIndexOf(IMenuItem item)
Get the index of the given MenuItem in the submenu of this.

Specified by:
getIndexOf in interface IMenuItem
Parameters:
item - to determine the index of
Returns:
the index of the given item in the submenu

select

public void select()
Select the MenuItem. This runs its contained Task. If there is no Task atached to this MenuItem, nothing happens.

Specified by:
select in interface IMenuItem

addItem

public void addItem(MenuItem item)
Add the given MenuItem to the list of subitems. The new item is registered at the AppShell and becomes visible. Note: A MenuItem used at a MenuAppShell (i.e. at an SWT menu) must be of the style CASCADE to have children.

Specified by:
addItem in interface IMenuItem
Parameters:
item - to add.

addItem

public void addItem(int index,
                    MenuItem item)
Add the given MenuItem to the list of subitems at the given index. The new item is registered at the AppShell and becomes visible. Note: A MenuItem used at a MenuAppShell (i.e. at an SWT menu) must be of the style CASCADE to have children.

Specified by:
addItem in interface IMenuItem
Parameters:
index - where to add the new item.
item - to add.

getItems

public java.util.List getItems()
Get the list of all MenuItems of the submenu of this MenuItem.

Specified by:
getItems in interface IMenuItem
Returns:
the list of all MenuItems of the submenu.

clearItems

public void clearItems()
Remove all MenuItems from the list of subitems. The items are unregisterd from the AppShell and are no longer visible.

Specified by:
clearItems in interface IMenuItem

removeItem

public void removeItem(MenuItem item)
Remove the given MenuItem from the list of subitems. This item is unregisterd from the AppShell and is no longer visible.

Specified by:
removeItem in interface IMenuItem
Parameters:
item - to remove

containsItem

public boolean containsItem(IMenuItem item)
Determine if the given item is contained in the submenu of this menu.

Specified by:
containsItem in interface IMenuItem
Parameters:
item - the MenuItem to search for in the submenu.
Returns:
true if the given item is contained in the list of subitems.