Runtime

org.eclipse.gmf.runtime.common.ui.dialogs
Class SelectableElement

java.lang.Object
  extended byorg.eclipse.gmf.runtime.common.ui.dialogs.SelectableElement

public class SelectableElement
extends java.lang.Object

An element that contains a hint, a serializable String ID, a String label, and an ImageDescriptor label. SeletableElements keep track of its parent which may or may not be null and a list of children which may be empty. This allows SelectableElement objects to be optionally represented in tree viewers. SelectableElements also keep track of their SelectedType, which describes if the element is selected, unselected, or set to leave. Therefore, SelectableElement objects typically correspond to elements in the UI.

This class contains public convenience methods. For eaxmple, it includes methods to find SelectableElement objects or their hints based on their String ID and a method to make copies of SelectableElement objects.

The SelectableElement class is used in at least 3 places, Show Related Elements Show Hide Relationships, and Browse Diagrams.


Constructor Summary
SelectableElement(java.lang.String aName, ImageDescriptor anIcon, java.lang.Object aHint)
          Deprecated. Use the other constructor.
SelectableElement(java.lang.String anID, java.lang.String aName, ImageDescriptor anIcon, java.lang.Object aHint)
          Constructor to make a new SelectableElement.
 
Method Summary
 void addChild(SelectableElement element)
          Adds a child to this element
static void addHintsToList(java.util.List list, SelectableElement selectableElement)
          Recursively add this SelectableElement's and this SelectableElement's children's hints to a List which is not null.
static int calculateLongestStringLength(SelectableElement selectableElement, Control control)
          Calculates the longest string length of this element's children for the text that will be displayed in the control.
static int calculateNumberOfChildren(SelectableElement selectableElement)
          Returns the number of children including itself.
static boolean doAllChildrenHaveSelectedType(SelectableElement parent, SelectedType selectType)
          Returns if all children have the same selected type
static SelectableElement findById(java.util.List selectableElements, java.lang.String id)
          Return the first element that matches the given id from the List of SelectableElement objects
 SelectableElement findById(java.lang.String theId)
          Return the first element that matches the given id from this SelectableElement and its children
static void getAllChildrenOfType(SelectableElement parent, SelectedType selectType, java.util.List list)
          Return all children that have the SelectedType.
 void getAllHints(java.util.Set hints)
          Retrieve all hints for the subtree rooted at this selectable element.
 SelectableElement getChild(int i)
          Returns a child
 SelectableElement[] getChildren()
          Returns the children of this element as an array
 java.lang.Object getHint()
          Returns the hint, which is an Object.
 void getHints(java.util.List stringRepresentations, java.util.Set hints)
          Retrieves all of the hints from the list of selections.
 void getHintsThatMatchTheseIds(java.util.List list, java.util.List ids)
          Collect the types that match a list of String ids.
 ImageDescriptor getIconImageDescriptor()
          Returns the icon of this element to display to the user.
 java.lang.String getId()
          Returns a string representation of this selectable element.
 java.util.List getLeaveElementTypes()
          Returns a list of LEAVE RelationshipTypes for a SelectableElement.
 java.lang.String getName()
          Returns the name of this element to display to the user.
 int getNumberOfChildren()
          Returns the number of children
 SelectableElement getParent()
          Returns the parent of this element.
 java.util.List getSelectedElementIds()
          Return element IDs, including children, that are SelectedType.SELECTED.
 java.util.List getSelectedElementTypes()
          Returns a list of SELECTED RelationshipTypes for a SelectableElement.
 SelectedType getSelectedType()
          Returns if the element was selected.
 java.util.List getUnSelectedElementTypes()
          Returns a list of UNSELECTED RelationshipTypes for a SelectableElement.
 SelectableElement makeCopy()
          Same idea as the clone method.
 void removeAllChildren()
          Remove all children of this SelectableElement
 void setIconImageDescriptor(ImageDescriptor anIcon)
          Sets the icon of this element to display to the user.
 void setName(java.lang.String aName)
          Sets the name of this element to display to the user.
 void setParent(SelectableElement aParent)
          Sets the parent of this element.
 void setSelectedType(SelectedType aSelectedType)
          Sets whether or not the element is selected.
static void setSelectedTypeForMatchingSelecteableElementAndChildren(SelectableElement parent, SelectedType selectedType, java.util.List list)
          Sets the SelectedType for a SelectableElement and its children that match the IDs in the List of IDs.
static void setSelectedTypeForSelecteableElementAndChildren(SelectableElement parent, SelectedType selectedType)
          Sets the SelectedType for a SelectableElement and its children
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectableElement

public SelectableElement(java.lang.String aName,
                         ImageDescriptor anIcon,
                         java.lang.Object aHint)
Deprecated. Use the other constructor.

Constructor to make a new SelectableElement

Parameters:
aName - the String name of the element
anIcon - the icon Image for the element
aHint - the element type

SelectableElement

public SelectableElement(java.lang.String anID,
                         java.lang.String aName,
                         ImageDescriptor anIcon,
                         java.lang.Object aHint)
Constructor to make a new SelectableElement.

Parameters:
anID - A non-language specific unique identifier for this selectable element.
aName - A user-presentable name for this selectable element.
anIcon - The icon image for the element.
aHint - A hint associated with the selection of this element.
Method Detail

addChild

public void addChild(SelectableElement element)
Adds a child to this element

Parameters:
element - the child to add

removeAllChildren

public void removeAllChildren()
Remove all children of this SelectableElement


getNumberOfChildren

public int getNumberOfChildren()
Returns the number of children

Returns:
int with the number of children this element has

getChild

public SelectableElement getChild(int i)
Returns a child

Parameters:
i - with the index of the child of this element
Returns:
SelectableElement which is child i of this element

getIconImageDescriptor

public ImageDescriptor getIconImageDescriptor()
Returns the icon of this element to display to the user.

Returns:
Image with icon of this element to display to the user

getName

public java.lang.String getName()
Returns the name of this element to display to the user.

Returns:
String with name of this element to display to the user

setIconImageDescriptor

public void setIconImageDescriptor(ImageDescriptor anIcon)
Sets the icon of this element to display to the user.

Parameters:
anIcon - The icon to set

setName

public void setName(java.lang.String aName)
Sets the name of this element to display to the user.

Parameters:
aName - The name to set

getParent

public SelectableElement getParent()
Returns the parent of this element.

Returns:
SelectableElement

setParent

public void setParent(SelectableElement aParent)
Sets the parent of this element.

Parameters:
aParent - The parent to set

getChildren

public SelectableElement[] getChildren()
Returns the children of this element as an array

Returns:
SelectableElement[] array of this element's children.

getSelectedType

public SelectedType getSelectedType()
Returns if the element was selected.

Returns:
selectedType from the SelectedType EnumeratedType

setSelectedType

public void setSelectedType(SelectedType aSelectedType)
Sets whether or not the element is selected. For example, if the element is checked in the interface.

Parameters:
aSelectedType - from the SelectedType EnumeratedType

getHint

public java.lang.Object getHint()
Returns the hint, which is an Object. This could be subclassed if type safety is required.

Returns:
the element type

setSelectedTypeForSelecteableElementAndChildren

public static void setSelectedTypeForSelecteableElementAndChildren(SelectableElement parent,
                                                                   SelectedType selectedType)
Sets the SelectedType for a SelectableElement and its children

Parameters:
parent - sets the SelectedType for this SelectableElement
selectedType - the SelectedType to set for the SelectableElement and its children.

setSelectedTypeForMatchingSelecteableElementAndChildren

public static void setSelectedTypeForMatchingSelecteableElementAndChildren(SelectableElement parent,
                                                                           SelectedType selectedType,
                                                                           java.util.List list)
Sets the SelectedType for a SelectableElement and its children that match the IDs in the List of IDs.

Parameters:
parent - sets the SelectedType for this SelectableElement
selectedType - the SelectedType to set for the SelectableElement and its children.
list - List of IDs, not hints

calculateLongestStringLength

public static int calculateLongestStringLength(SelectableElement selectableElement,
                                               Control control)
Calculates the longest string length of this element's children for the text that will be displayed in the control. This method only works for root SelectableElements.

Parameters:
selectableElement - the SelectableElement to calculate the longest string length. Also looks at its children.
control - the control with the font to use when calculating the font size
Returns:
int with the string length in pixels

calculateNumberOfChildren

public static int calculateNumberOfChildren(SelectableElement selectableElement)
Returns the number of children including itself. Includes children that are children of children, etc.

Parameters:
selectableElement - the SelectableElement that we will find the number of children for.
Returns:
int the number of children including children that are children of children, etc, and itself.

getSelectedElementTypes

public java.util.List getSelectedElementTypes()
Returns a list of SELECTED RelationshipTypes for a SelectableElement. Checks this SelectableElement and the SelectableElement's children. For each SelectableElement where the selectedType is SELECTED, add the RelationshipType to a list.

Returns:
List

getUnSelectedElementTypes

public java.util.List getUnSelectedElementTypes()
Returns a list of UNSELECTED RelationshipTypes for a SelectableElement. Checks this SelectableElement and the SelectableElement's children. For each SelectableElement where the selectedType is UNSELECTED, add the RelationshipType to a list.

Returns:
List

getLeaveElementTypes

public java.util.List getLeaveElementTypes()
Returns a list of LEAVE RelationshipTypes for a SelectableElement. Checks this SelectableElement and the SelectableElement's children. For each SelectableElement where the selectedType is LEAVE, add the RelationshipType to a list.

Returns:
List

getId

public java.lang.String getId()
Returns a string representation of this selectable element. This is useful if a selectable element must be persisted between invocations of eclipse.

Returns:
String id of this selectableElement

getHints

public void getHints(java.util.List stringRepresentations,
                     java.util.Set hints)
Retrieves all of the hints from the list of selections. The selections are strings that have been produced by the getId() method. Note: this should be invoked from the selectable element root.

Parameters:
stringRepresentations - Strings produced by the SelectableElement.getId() method.
hints - (out) A set used to store all of the hints.

getAllHints

public void getAllHints(java.util.Set hints)
Retrieve all hints for the subtree rooted at this selectable element.

Parameters:
hints - (out) A set used to store all of the hints.

addHintsToList

public static void addHintsToList(java.util.List list,
                                  SelectableElement selectableElement)
Recursively add this SelectableElement's and this SelectableElement's children's hints to a List which is not null. It will not add duplicates into the List, and if the hint is null, it will not be added to the List.

Parameters:
list - not null, add hints to this List
selectableElement - recursively add hints from this SelectableElement and its children

doAllChildrenHaveSelectedType

public static boolean doAllChildrenHaveSelectedType(SelectableElement parent,
                                                    SelectedType selectType)
Returns if all children have the same selected type

Parameters:
parent - we'll be checking the children of this parent
selectType - the SelectedType that all children of the parent are checked for
Returns:
true if all children are checked, false otherwise

getAllChildrenOfType

public static void getAllChildrenOfType(SelectableElement parent,
                                        SelectedType selectType,
                                        java.util.List list)
Return all children that have the SelectedType.

Parameters:
parent - parent selectable element.
selectType - the selected type to match
list - of SelectableElements

getSelectedElementIds

public java.util.List getSelectedElementIds()
Return element IDs, including children, that are SelectedType.SELECTED.

Returns:
List of element IDs, including children, that are SelectedType.SELECTED.

makeCopy

public SelectableElement makeCopy()
Same idea as the clone method. Share the same images, hints, etc. of the original. Just have different SelectableElements.

Returns:
a copy of this selectableElement

getHintsThatMatchTheseIds

public void getHintsThatMatchTheseIds(java.util.List list,
                                      java.util.List ids)
Collect the types that match a list of String ids. Unlike getHints, which doesn't collect children hints.

Parameters:
list - List to add into
ids - List of String ids we are trying to match

findById

public static SelectableElement findById(java.util.List selectableElements,
                                         java.lang.String id)
Return the first element that matches the given id from the List of SelectableElement objects

Parameters:
selectableElements - List of SelectableElement objects to match
id - String id to match
Returns:
the first element that matches the given id from the List of SelectableElement objects or null if nothing matched

findById

public SelectableElement findById(java.lang.String theId)
Return the first element that matches the given id from this SelectableElement and its children

Parameters:
theId - String id to match
Returns:
the first element that matches the given id from this SelectableElement and its children or null if nothing matched

Runtime

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp., Borland Software Corp., and others 2005,2006. All rights reserved.