org.cafesip.gwtcomp.client.ui
Class SuperTree

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Tree
              extended by org.cafesip.gwtcomp.client.ui.SuperTree
All Implemented Interfaces:
HasAllFocusHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasBlurHandlers, HasFocusHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasCloseHandlers<TreeItem>, HasOpenHandlers<TreeItem>, HasSelectionHandlers<TreeItem>, HasHandlers, EventListener, Focusable, HasAnimation, HasFocus, HasWidgets, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents, SourcesTreeEvents, Iterable<Widget>

public class SuperTree
extends Tree

An extension of the GWT Tree that allows multiple selection of tree items and includes comprehensive support for context-sensitive popup menu among other things. The main feature of the objects is the ability for the application to define different popup menus at every unique level of the tree. For example, if a tree is displaying countries, its states and cities within a state, it is possible to define a different popup menu at the country-level, state-level and city-level without having to attach a popup menu for individual items although that is possible as well. In order to utilize the feature, the application must use SuperTreeItem instead of the GWT TreeItem object to define the tree hierarchy. Each object of the type SuperTreeItem has an integer "type" attribute that must be specified. A level is specified as a string formatted as W.X.Y.Z.... where W, X, Y, Z are types. The dots are used to specify the hierarchy. For example, if the country has the type 1, state has the type 2 and the city has the type 3, the level 1.2.3 is used to specify a context menu for the city that is placed in the tree as Country->State->City. The context-menu is popped up by using the right-click. Note that the application must not use the type value of 0. That value is reserved for objects of the type TreeItem.

If the tree has multi-selection enabled, the user can select more than one tree item by clicking on the tree item while pressing the CTRL key. The user can select multiple items belonging to the same level only. Therefore, in conjuction with the the context-senstive popup menu, the user can select multiple items of the same level and popup the menu.

The application can also define their own tree listener for listening to tree selection, tree expand and collapse and popup events. For more details, see the SuperTreeListener class.

CSS Style Rules:

Screen-Shots:

Author:
Amit Chatterjee

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.Tree
Tree.Resources
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
SuperTree()
          A constructor for this class.
SuperTree(Tree.Resources images)
          A constructor for this class.
 
Method Summary
 TreeItem addItem(String itemText)
           
 void addItem(SuperTreeItem item)
          Add a SuperTree object to the root of the tree.
 void addItem(TreeItem item)
           
 TreeItem addItem(Widget widget)
           
 void addTreeListener(SuperTreeListener listener)
          Add a tree listener.
static String getLevel(TreeItem item)
          Convenience method for finding the level of any given tree items.
 TreeItem getSelectedItem()
           
 TreeItem[] getSelectedItems()
          Returns the selected items.
 boolean isMultiSelectionEnabled()
          Returns if multi-selection is enabled.
protected static void preventBrowserContextMenu(JavaScriptObject element)
           
 void removeContextMenu(String level)
          Remove the context menu at a given level.
 void removeTreeListener(SuperTreeListener listener)
          Removes the tree listener.
 void setContextMenu(String level, PopupMenu contextMenu)
          Sets the context menu for a given level.
 void setMultiSelectionEnabled(boolean multiSelectionEnabled)
          Enables or disables multi-selection.
 void setSelectedItem(TreeItem item)
           
 void setSelectedItem(TreeItem item, boolean fireEvents)
           
 
Methods inherited from class com.google.gwt.user.client.ui.Tree
add, addBlurHandler, addCloseHandler, addFocusHandler, addFocusListener, addKeyboardListener, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addMouseDownHandler, addMouseListener, addMouseMoveHandler, addMouseOutHandler, addMouseOverHandler, addMouseUpHandler, addMouseWheelHandler, addOpenHandler, addSelectionHandler, addTreeListener, clear, doAttachChildren, doDetachChildren, ensureSelectedItemVisible, getItem, getItemCount, getTabIndex, isAnimationEnabled, isKeyboardNavigationEnabled, iterator, onBrowserEvent, onEnsureDebugId, onLoad, remove, removeFocusListener, removeItem, removeItems, removeKeyboardListener, removeMouseListener, removeTreeListener, setAccessKey, setAnimationEnabled, setFocus, setTabIndex, treeItemIterator
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addDomHandler, addHandler, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onDetach, onUnload, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

SuperTree

public SuperTree()
A constructor for this class.


SuperTree

public SuperTree(Tree.Resources images)
A constructor for this class.

Parameters:
images - the image bundle.
Method Detail

preventBrowserContextMenu

protected static void preventBrowserContextMenu(JavaScriptObject element)

addItem

public TreeItem addItem(String itemText)
Overrides:
addItem in class Tree
See Also:

Note that all the items in the tree are converted to GWT HTML object before adding to the tree. Therefore, the GWT Tree.getText() method will return a null.


addItem

public void addItem(SuperTreeItem item)
Add a SuperTree object to the root of the tree.

Parameters:
item - item to add.

addItem

public void addItem(TreeItem item)
Overrides:
addItem in class Tree
See Also:
Tree.addItem(com.google.gwt.user.client.ui.TreeItem)

addItem

public TreeItem addItem(Widget widget)
Overrides:
addItem in class Tree
See Also:
Tree.addItem(com.google.gwt.user.client.ui.Widget)

addTreeListener

public void addTreeListener(SuperTreeListener listener)
Add a tree listener.

Parameters:
listener - the listener object.

getLevel

public static String getLevel(TreeItem item)
Convenience method for finding the level of any given tree items. Note that although an object of the type TreeItem is passed as a parameter, normally, an object of the type SuperTreeItem must be used. An object of the type TreeItem is assumed to have the tye 0.

Parameters:
item - a tree item.
Returns:
the level

getSelectedItem

public TreeItem getSelectedItem()
Overrides:
getSelectedItem in class Tree
See Also:

Note that if multi-selection is enabled, this method returns the item selected first. For trees with multi-selection, the getSelectedItems() method must be used.


getSelectedItems

public TreeItem[] getSelectedItems()
Returns the selected items.

Returns:
selected items.

isMultiSelectionEnabled

public boolean isMultiSelectionEnabled()
Returns if multi-selection is enabled.

Returns:
Returns the multiSelectionEnabled.

removeContextMenu

public void removeContextMenu(String level)
Remove the context menu at a given level.

Parameters:
level -

removeTreeListener

public void removeTreeListener(SuperTreeListener listener)
Removes the tree listener.

Parameters:
listener - listener to remove.

setContextMenu

public void setContextMenu(String level,
                           PopupMenu contextMenu)
Sets the context menu for a given level.

Parameters:
level - the level to set
contextMenu - the context menu object.

setMultiSelectionEnabled

public void setMultiSelectionEnabled(boolean multiSelectionEnabled)
Enables or disables multi-selection.

Parameters:
multiSelectionEnabled - The multiSelectionEnabled to set.

setSelectedItem

public void setSelectedItem(TreeItem item)
Overrides:
setSelectedItem in class Tree
See Also:
Tree.setSelectedItem(com.google.gwt.user.client.ui.TreeItem)

setSelectedItem

public void setSelectedItem(TreeItem item,
                            boolean fireEvents)
Overrides:
setSelectedItem in class Tree
See Also:
Tree.setSelectedItem(com.google.gwt.user.client.ui.TreeItem, boolean)


Copyright © 2010 Cafesip.org. All Rights Reserved.