com.itmill.toolkit.ui
Class Tree

java.lang.Object
  extended by com.itmill.toolkit.ui.AbstractComponent
      extended by com.itmill.toolkit.ui.AbstractField
          extended by com.itmill.toolkit.ui.AbstractSelect
              extended by com.itmill.toolkit.ui.Tree
All Implemented Interfaces:
Buffered, BufferedValidatable, Container, Container.Hierarchical, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Viewer, Property, Property.Editor, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer, Validatable, Action.Container, ItemClickEvent.ItemClickSource, MethodEventSource, Paintable, Sizeable, VariableOwner, Component, Component.Focusable, Field, EventListener

public class Tree
extends AbstractSelect
implements Container.Hierarchical, Action.Container, ItemClickEvent.ItemClickSource

MenuTree component. MenuTree can be used to select an item (or multiple items) from a hierarchical set of items.

Since:
3.0
Version:
5.3.0
Author:
IT Mill Ltd.

Nested Class Summary
 class Tree.CollapseEvent
          Collapse event
static interface Tree.CollapseListener
          Collapse event listener.
 class Tree.ExpandEvent
          Event to fired when a node is expanded.
static interface Tree.ExpandListener
          Expand event listener.
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractSelect
AbstractSelect.CaptionChangeListener, AbstractSelect.DefaultNewItemHandler, AbstractSelect.Filtering, AbstractSelect.NewItemHandler
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractField
AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Container
Container.Editor, Container.Filterable, Container.Hierarchical, Container.Indexed, Container.ItemSetChangeEvent, Container.ItemSetChangeListener, Container.ItemSetChangeNotifier, Container.Ordered, Container.PropertySetChangeEvent, Container.PropertySetChangeListener, Container.PropertySetChangeNotifier, Container.Sortable, Container.Viewer
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.ui.Field
Field.ValueChangeEvent
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Buffered
Buffered.SourceException
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Property
Property.ConversionException, Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
 
Field Summary
 
Fields inherited from class com.itmill.toolkit.ui.AbstractSelect
ITEM_CAPTION_MODE_EXPLICIT, ITEM_CAPTION_MODE_EXPLICIT_DEFAULTS_ID, ITEM_CAPTION_MODE_ICON_ONLY, ITEM_CAPTION_MODE_ID, ITEM_CAPTION_MODE_INDEX, ITEM_CAPTION_MODE_ITEM, ITEM_CAPTION_MODE_PROPERTY, itemIdMapper, items
 
Constructor Summary
Tree()
          Creates a new empty tree.
Tree(String caption)
          Creates a new empty tree with caption.
Tree(String caption, Container dataSource)
          Creates a new tree with caption and connect it to a Container.
 
Method Summary
 void addActionHandler(Action.Handler actionHandler)
          Adds an action handler.
 void addListener(ItemClickEvent.ItemClickListener listener)
          Register listener to handle ItemClickEvents.
 void addListener(Tree.CollapseListener listener)
          Adds the collapse listener.
 void addListener(Tree.ExpandListener listener)
          Adds the expand listener.
 boolean areChildrenAllowed(Object itemId)
          Tests if the Item with given ID can have any children.
 void changeVariables(Object source, Map variables)
          Called when one or more variables handled by the implementing class are changed.
 boolean collapseItem(Object itemId)
          Collapses an item.
 boolean collapseItemsRecursively(Object startItemId)
          Collapses the items recursively.
 boolean expandItem(Object itemId)
          Expands an item.
 boolean expandItemsRecursively(Object startItemId)
          Expands the items recursively Expands all the children recursively starting from an item.
protected  void fireCollapseEvent(Object itemId)
          Emits collapse event.
protected  void fireExpandEvent(Object itemId)
          Emits the expand event.
 void focus()
          Focusing to this component is not supported.
 Collection getChildren(Object itemId)
          Gets the IDs of all Items that are children of the specified Item.
 Object getParent(Object itemId)
          Gets the ID of the parent Item of the specified Item.
 String getTag()
          Gets the UIDL tag corresponding to the component.
 Collection getVisibleItemIds()
          Gets the visible item ids.
 boolean hasChildren(Object itemId)
          Tests if the Item specified with itemId has child Items.
 boolean isExpanded(Object itemId)
          Check is an item is expanded
 boolean isRoot(Object itemId)
          Tests if the Item specified with itemId is a root Item.
 boolean isSelectable()
          Getter for property selectable.
 void paintContent(PaintTarget target)
          Paints any needed component-specific things to the given UIDL stream.
 void removeActionHandler(Action.Handler actionHandler)
          Removes an action handler.
 void removeListener(ItemClickEvent.ItemClickListener listener)
          Removes ItemClickListener.
 void removeListener(Tree.CollapseListener listener)
          Removes the collapse listener.
 void removeListener(Tree.ExpandListener listener)
          Removes the expand listener.
 void requestRepaint()
          Requests that the paintable should be repainted as soon as possible.
 Collection rootItemIds()
          Gets the IDs of all Items in the container that don't have a parent.
 boolean setChildrenAllowed(Object itemId, boolean areChildrenAllowed)
          Sets the given Item's capability to have children.
 void setContainerDataSource(Container newDataSource)
          Sets the Container that serves as the data source of the viewer.
 void setLazyLoading(boolean useLazyLoading)
          Tree does not support lazy options loading mode.
 void setNewItemsAllowed(boolean allowNewOptions)
          Adding new items is not supported.
 void setNullSelectionItemId(Object nullSelectionItemId)
          Tree does not support setNullSelectionItemId.
 boolean setParent(Object itemId, Object newParentId)
           Sets the parent of an Item.
 void setSelectable(boolean selectable)
          Setter for property selectable.
 
Methods inherited from class com.itmill.toolkit.ui.AbstractSelect
addContainerProperty, addItem, addItem, addListener, addListener, attach, containerItemSetChange, containerPropertySetChange, containsId, detach, fireItemSetChange, firePropertySetChange, getCaptionChangeListener, getContainerDataSource, getContainerProperty, getContainerPropertyIds, getItem, getItemCaption, getItemCaptionMode, getItemCaptionPropertyId, getItemIcon, getItemIconPropertyId, getItemIds, getNewItemHandler, getNullSelectionItemId, getType, getType, getValue, isMultiSelect, isNewItemsAllowed, isNullSelectionAllowed, isSelected, removeAllItems, removeContainerProperty, removeItem, removeListener, removeListener, select, setItemCaption, setItemCaptionMode, setItemCaptionPropertyId, setItemIcon, setItemIconPropertyId, setMultiSelect, setNewItemHandler, setNullSelectionAllowed, setValue, setValue, size, unselect
 
Methods inherited from class com.itmill.toolkit.ui.AbstractField
addListener, addListener, addValidator, commit, constructField, discard, fireReadOnlyStatusChange, fireValueChange, getErrorMessage, getPropertyDataSource, getRequiredError, getTabIndex, getValidators, isEmpty, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isReadThrough, isRequired, isValid, isValidationVisible, isWriteThrough, removeListener, removeListener, removeValidator, setCurrentBufferedSourceException, setInternalValue, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setReadThrough, setRequired, setRequiredError, setTabIndex, setValidationVisible, setWriteThrough, toString, validate, valueChange
 
Methods inherited from class com.itmill.toolkit.ui.AbstractComponent
addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getHeight, getHeightUnits, getIcon, getLocale, getParent, getStyle, getStyleName, getWidth, getWidthUnits, getWindow, handleError, isEnabled, isImmediate, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setEnabled, setErrorHandler, setHeight, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setSizeFull, setSizeUndefined, setStyle, setStyleName, setWidth, setWidth, setWidth, setWidthUnits, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.itmill.toolkit.data.Container
addContainerProperty, addItem, addItem, containsId, getContainerProperty, getContainerPropertyIds, getItem, getItemIds, getType, removeAllItems, removeContainerProperty, removeItem, size
 
Methods inherited from interface com.itmill.toolkit.ui.Field
getDescription, setCaption, setDescription
 

Constructor Detail

Tree

public Tree()
Creates a new empty tree.


Tree

public Tree(String caption)
Creates a new empty tree with caption.

Parameters:
caption -

Tree

public Tree(String caption,
            Container dataSource)
Creates a new tree with caption and connect it to a Container.

Parameters:
caption -
dataSource -
Method Detail

isExpanded

public boolean isExpanded(Object itemId)
Check is an item is expanded

Parameters:
itemId - the item id.
Returns:
true iff the item is expanded.

expandItem

public boolean expandItem(Object itemId)
Expands an item.

Parameters:
itemId - the item id.
Returns:
True iff the expand operation succeeded

requestRepaint

public void requestRepaint()
Description copied from interface: Paintable
Requests that the paintable should be repainted as soon as possible.

Specified by:
requestRepaint in interface Paintable
Overrides:
requestRepaint in class AbstractComponent

expandItemsRecursively

public boolean expandItemsRecursively(Object startItemId)
Expands the items recursively Expands all the children recursively starting from an item. Operation succeeds only if all expandable items are expanded.

Parameters:
startItemId -
Returns:
True iff the expand operation succeeded

collapseItem

public boolean collapseItem(Object itemId)
Collapses an item.

Parameters:
itemId - the item id.
Returns:
True iff the collapse operation succeeded

collapseItemsRecursively

public boolean collapseItemsRecursively(Object startItemId)
Collapses the items recursively. Collapse all the children recursively starting from an item. Operation succeeds only if all expandable items are collapsed.

Parameters:
startItemId -
Returns:
True iff the collapse operation succeeded

isSelectable

public boolean isSelectable()
Getter for property selectable.

The tree is selectable by default.

Returns:
the Value of property selectable.

setSelectable

public void setSelectable(boolean selectable)
Setter for property selectable.

The tree is selectable by default.

Parameters:
selectable - the New value of property selectable.

getTag

public String getTag()
Gets the UIDL tag corresponding to the component.

Overrides:
getTag in class AbstractSelect
Returns:
the Component UIDL tag as string.
See Also:
AbstractComponent.getTag()

changeVariables

public void changeVariables(Object source,
                            Map variables)
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Overrides:
changeVariables in class AbstractSelect
Parameters:
source - the Source of the variable change. This is the origin of the event. For example in Web Adapter this is the request.
variables - the Mapping from variable names to new variable values.
See Also:
VariableOwner.changeVariables(Object source, Map variables)

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Paints any needed component-specific things to the given UIDL stream.

Overrides:
paintContent in class AbstractSelect
Parameters:
target - the Paint Event.
Throws:
PaintException - if the paint operation failed.
See Also:
AbstractComponent.paintContent(PaintTarget)

areChildrenAllowed

public boolean areChildrenAllowed(Object itemId)
Tests if the Item with given ID can have any children.

Specified by:
areChildrenAllowed in interface Container.Hierarchical
Parameters:
itemId - ID of the Item in the container whose child capability is to be tested
Returns:
true if the specified Item exists in the Container and it can have children, false if it's not found from the container or it can't have children.
See Also:
Container.Hierarchical.areChildrenAllowed(Object)

getChildren

public Collection getChildren(Object itemId)
Gets the IDs of all Items that are children of the specified Item.

Specified by:
getChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose children the caller is interested in
Returns:
An unmodifiable collection containing the IDs of all other Items that are children in the container hierarchy
See Also:
Container.Hierarchical.getChildren(Object)

getParent

public Object getParent(Object itemId)
Gets the ID of the parent Item of the specified Item.

Specified by:
getParent in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose parent the caller wishes to find out.
Returns:
the ID of the parent Item. Will be null if the specified Item is a root element.
See Also:
Container.Hierarchical.getParent(Object)

hasChildren

public boolean hasChildren(Object itemId)
Tests if the Item specified with itemId has child Items.

Specified by:
hasChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item to be tested
Returns:
true if the specified Item has children, false if not (is a leaf)
See Also:
Container.Hierarchical.hasChildren(Object)

isRoot

public boolean isRoot(Object itemId)
Tests if the Item specified with itemId is a root Item.

Specified by:
isRoot in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose root status is to be tested
Returns:
true if the specified Item is a root, false if not
See Also:
Container.Hierarchical.isRoot(Object)

rootItemIds

public Collection rootItemIds()
Gets the IDs of all Items in the container that don't have a parent.

Specified by:
rootItemIds in interface Container.Hierarchical
Returns:
An unmodifiable collection containing IDs of all root elements of the container
See Also:
Container.Hierarchical.rootItemIds()

setChildrenAllowed

public boolean setChildrenAllowed(Object itemId,
                                  boolean areChildrenAllowed)
Sets the given Item's capability to have children.

Specified by:
setChildrenAllowed in interface Container.Hierarchical
Parameters:
itemId - ID of the Item in the container whose child capability is to be set
areChildrenAllowed - boolean value specifying if the Item can have children or not
Returns:
true if the operation succeeded, false if not
See Also:
Container.Hierarchical.setChildrenAllowed(Object, boolean)

setParent

public boolean setParent(Object itemId,
                         Object newParentId)
Description copied from interface: Container.Hierarchical

Sets the parent of an Item. The new parent item must exist and be able to have children. ( Container.Hierarchical.areChildrenAllowed(Object) == true ). It is also possible to detach a node from the hierarchy (and thus make it root) by setting the parent null.

This operation is optional.

Specified by:
setParent in interface Container.Hierarchical
Parameters:
itemId - ID of the item to be set as the child of the Item identified with newParentId
newParentId - ID of the Item that's to be the new parent of the Item identified with itemId
Returns:
true if the operation succeeded, false if not

setContainerDataSource

public void setContainerDataSource(Container newDataSource)
Sets the Container that serves as the data source of the viewer.

Specified by:
setContainerDataSource in interface Container.Viewer
Overrides:
setContainerDataSource in class AbstractSelect
Parameters:
newDataSource - the new data source.
See Also:
Container.Viewer.setContainerDataSource(Container)

addListener

public void addListener(Tree.ExpandListener listener)
Adds the expand listener.

Parameters:
listener - the Listener to be added.

removeListener

public void removeListener(Tree.ExpandListener listener)
Removes the expand listener.

Parameters:
listener - the Listener to be removed.

fireExpandEvent

protected void fireExpandEvent(Object itemId)
Emits the expand event.

Parameters:
itemId - the item id.

addListener

public void addListener(Tree.CollapseListener listener)
Adds the collapse listener.

Parameters:
listener - the Listener to be added.

removeListener

public void removeListener(Tree.CollapseListener listener)
Removes the collapse listener.

Parameters:
listener - the Listener to be removed.

fireCollapseEvent

protected void fireCollapseEvent(Object itemId)
Emits collapse event.

Parameters:
itemId - the item id.

addActionHandler

public void addActionHandler(Action.Handler actionHandler)
Adds an action handler.

Specified by:
addActionHandler in interface Action.Container
Parameters:
actionHandler - the new handler to be added.
See Also:
Action.Container.addActionHandler(Action.Handler)

removeActionHandler

public void removeActionHandler(Action.Handler actionHandler)
Removes an action handler.

Specified by:
removeActionHandler in interface Action.Container
Parameters:
actionHandler - the handler to be removed.
See Also:
Action.Container.removeActionHandler(Action.Handler)

getVisibleItemIds

public Collection getVisibleItemIds()
Gets the visible item ids.

Overrides:
getVisibleItemIds in class AbstractSelect
See Also:
AbstractSelect.getVisibleItemIds()

setNullSelectionItemId

public void setNullSelectionItemId(Object nullSelectionItemId)
                            throws UnsupportedOperationException
Tree does not support setNullSelectionItemId.

Overrides:
setNullSelectionItemId in class AbstractSelect
Parameters:
nullSelectionItemId - the nullSelectionItemId to set.
Throws:
UnsupportedOperationException
See Also:
AbstractSelect.setNullSelectionItemId(java.lang.Object)

setNewItemsAllowed

public void setNewItemsAllowed(boolean allowNewOptions)
                        throws UnsupportedOperationException
Adding new items is not supported.

Overrides:
setNewItemsAllowed in class AbstractSelect
Parameters:
allowNewOptions - the New value of property allowNewOptions.
Throws:
UnsupportedOperationException - if set to true.
See Also:
AbstractSelect.setNewItemsAllowed(boolean)

focus

public void focus()
           throws UnsupportedOperationException
Focusing to this component is not supported.

Specified by:
focus in interface Component.Focusable
Overrides:
focus in class AbstractField
Throws:
UnsupportedOperationException - if invoked.
See Also:
AbstractField.focus()

setLazyLoading

public void setLazyLoading(boolean useLazyLoading)
Tree does not support lazy options loading mode. Setting this true will throw UnsupportedOperationException.

See Also:
com.itmill.toolkit.ui.Select#setLazyLoading(boolean)

addListener

public void addListener(ItemClickEvent.ItemClickListener listener)
Description copied from interface: ItemClickEvent.ItemClickSource
Register listener to handle ItemClickEvents. Note! Click listeners are rather terminal dependent features. This feature is EXPERIMENTAL

Specified by:
addListener in interface ItemClickEvent.ItemClickSource
Parameters:
listener - ItemClickListener to be registered

removeListener

public void removeListener(ItemClickEvent.ItemClickListener listener)
Description copied from interface: ItemClickEvent.ItemClickSource
Removes ItemClickListener.

Specified by:
removeListener in interface ItemClickEvent.ItemClickSource


Copyright © 2000-2009 IT Mill Ltd. All Rights Reserved.