com.itmill.toolkit.ui
Class Tree

java.lang.Object
  extended by com.itmill.toolkit.terminal.Identifiable
      extended by com.itmill.toolkit.ui.AbstractComponent
          extended by com.itmill.toolkit.ui.AbstractField
              extended by com.itmill.toolkit.ui.Select
                  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, MethodEventSource, Paintable, VariableOwner, Component, Component.Focusable, Field, EventListener

public class Tree
extends Select
implements Container.Hierarchical, Action.Container

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

Since:
3.0
Version:
4.1.4
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.Select
Select.OptionsStream
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractField
AbstractField.ReadOnlyStatusChangeEvent
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.data.Container
Container.Editor, 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.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
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.Select
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
 
Fields inherited from interface com.itmill.toolkit.data.Container
NULL_ITEM_ID
 
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(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 any child Items, that is, is it a leaf Item.
 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(Tree.CollapseListener listener)
          Removes the collapse listener.
 void removeListener(Tree.ExpandListener listener)
          Removes the expand listener.
 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.
 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.Select
addContainerProperty, addItem, addItem, addListener, addListener, attach, containerItemSetChange, containerPropertySetChange, containsId, detach, escapeJSON, fireItemSetChange, firePropertySetChange, getContainerDataSource, getContainerProperty, getContainerPropertyIds, getItem, getItemCaption, getItemCaptionMode, getItemCaptionPropertyId, getItemIcon, getItemIconPropertyId, getItemIds, getNullSelectionItemId, getOptionFilter, getType, getType, getValue, isLazyLoading, isMultiSelect, isNewItemsAllowed, isSelected, removeAllItems, removeContainerProperty, removeItem, removeListener, removeListener, select, setItemCaption, setItemCaptionMode, setItemCaptionPropertyId, setItemIcon, setItemIconPropertyId, setLazyLoading, setMultiSelect, setNullSelectionItemId, setOptionFilter, setValue, size, unselect
 
Methods inherited from class com.itmill.toolkit.ui.AbstractField
addListener, addListener, addValidator, commit, constructField, discard, finalize, fireReadOnlyStatusChange, fireValueChange, getErrorMessage, getFocusableId, getPropertyDataSource, getTabIndex, getValidators, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isReadThrough, isRequired, isValid, isWriteThrough, removeListener, removeListener, removeValidator, setInternalValue, setInvalidAllowed, setInvalidCommitted, setPropertyDataSource, setReadOnly, setReadThrough, setRequired, setTabIndex, setWriteThrough, toString, validate, valueChange
 
Methods inherited from class com.itmill.toolkit.ui.AbstractComponent
addListener, addListener, addListener, addListener, childRequestedRepaint, dependsOn, fireComponentErrorEvent, fireComponentEvent, fireEvent, getApplication, getCaption, getComponentError, getData, getDescription, getDirectDependencies, getIcon, getLocale, getParent, getStyle, getWindow, isEnabled, isImmediate, isVisible, paint, removeDirectDependency, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDescription, setEnabled, setIcon, setImmediate, setLocale, setParent, setStyle, setVisible
 
Methods inherited from class com.itmill.toolkit.terminal.Identifiable
getDebugId, getUIID, setDebugId, setUIID
 
Methods inherited from class java.lang.Object
clone, equals, 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
 
Methods inherited from interface com.itmill.toolkit.ui.Component
addListener, childRequestedRepaint, getApplication, getCaption, getIcon, getLocale, getParent, getStyle, getWindow, isEnabled, isVisible, removeListener, setEnabled, setParent, setStyle, setVisible
 
Methods inherited from interface com.itmill.toolkit.terminal.Paintable
addListener, paint, removeListener, requestRepaint, requestRepaintRequests
 
Methods inherited from interface com.itmill.toolkit.terminal.VariableOwner
dependsOn, getDirectDependencies, isImmediate, removeDirectDependency
 

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

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 Select
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 Select
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 Select
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 any child Items, that is, is it a leaf Item.

Specified by:
hasChildren in interface Container.Hierarchical
Parameters:
itemId - ID of the Item whose leaf status is to be tested
Returns:
true if the specified Item is a leaf, false if not
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)
Description copied from interface: Container.Hierarchical

Sets the given Item's capability to have children. If the Item identified with itemId already has children and areChildrenAllowed is false this method fails and false is returned.

The children must be first explicitly removed with Container.Hierarchical.setParent(Object itemId, Object newParentId)or Container.removeItem(Object itemId).

This operation is optional. If it is not implemented, the method always returns false.

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

setParent

public boolean setParent(Object itemId,
                         Object newParentId)
Sets the parent of an Item.

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
See Also:
Container.Hierarchical.setParent(Object, Object)

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 Select
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 Select
See Also:
Select.getVisibleItemIds()

setNewItemsAllowed

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

Overrides:
setNewItemsAllowed in class Select
Parameters:
allowNewOptions - the New value of property allowNewOptions.
Throws:
UnsupportedOperationException - if set to true.
See Also:
Select.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.

Overrides:
setLazyLoading in class Select
See Also:
Select.setLazyLoading(boolean)


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