API Reference 0.3.24dart_web_toolkit_uiTreeItem

TreeItem class

An item that can be contained within a {@link com.google.gwt.user.client.ui.Tree}.

Each tree item is assigned a unique Dom id in order to support ARIA. See {@link com.google.gwt.user.client.ui.Accessibility} for more information.

Example

{@example com.google.gwt.examples.TreeExample}

class TreeItem extends UiObject implements IsTreeItem, HasTreeItems, HasHtml, HasSafeHtml {
 /**
  * The margin applied to child items.
  */
 static double _CHILD_MARGIN = 16.0;

 // By not overwriting the default tree padding and spacing, we traditionally
 // added 7 pixels between our image and content.
 // <2>|<1>image<1>|<2>|<1>content
 // So to preserve the current spacing we must add a 7 pixel pad when no image
 // is supplied.
 static int IMAGE_PAD = 7;

 /**
  * The duration of the animation.
  */
 static int _ANIMATION_DURATION = 200;

 /**
  * The duration of the animation per child {@link TreeItem}. If the per item
  * duration times the number of child items is less than the duration above,
  * the smaller duration will be used.
  */
 static int _ANIMATION_DURATION_PER_ITEM = 75;

 /**
  * The static animation used to open {@link TreeItem TreeItems}.
  */
 static TreeItemAnimation _itemAnimation = new TreeItemAnimation();

 /**
  * The structured table to hold images.
  */

 static dart_html.Element _BASE_INTERNAL_ELEM;
 /**
  * The base tree item element that will be cloned.
  */
 static dart_html.Element _BASE_BARE_ELEM;

 static TreeItemImpl _impl;

 List<TreeItem> _children;
 dart_html.Element _contentElem, _childSpanElem, _imageHolder;

 /**
  * Indicates that this item is a root item in a tree.
  */
 bool isRoot = false;

 bool _open = false;
 TreeItem _parent;
 bool _selected = false;

 Object _userObject;

 Tree _tree;

 Widget _widget;

 TreeItem({this.isRoot : false, SafeHtml html, Widget widget:null}) {
   if (_impl == null) {
     _impl = new TreeItemImpl();
   }
   //
   dart_html.Element elem = Dom.clone(_BASE_BARE_ELEM, true);
   setElement(elem);
   _contentElem = Dom.getFirstChild(elem);
   Dom.setElementAttribute(_contentElem, "id", Dom.createUniqueId());

   // The root item always has children.
   if (isRoot) {
     initChildren();
   }

   // Check widget
   if (widget != null) {
     setWidget(widget);
   }
 }

 /**
  * Adds a child tree item containing the specified html.
  *
  * @param itemHtml the item's HTML
  * @return the item that was added
  */
 TreeItem addSafeHtmlItem(SafeHtml itemHtml) {
   TreeItem ret = new TreeItem(html:itemHtml);
   addItem(ret);
   return ret;
 }

 /**
  * Adds another item as a child to this one.
  *
  * @param item the item to be added
  */
 void addItem(TreeItem item) {
   // If this is the item's parent, removing the item will affect the child
   // count.
   maybeRemoveItemFromParent(item);
   insertItem(getChildCount(), item);
 }

 /**
  * Adds another item as a child to this one.
  *
  * @param isItem the wrapper of item to be added
  */

 void addIsTreeItem(IsTreeItem isItem) {
   TreeItem item = isItem.asTreeItem();
   addItem(item);
 }

 /**
  * Adds a child tree item containing the specified widget.
  *
  * @param widget the widget to be added
  * @return the item that was added
  */

 TreeItem addWidgetItem(Widget widget) {
   TreeItem ret = new TreeItem(widget:widget);
   addItem(ret);
   return ret;
 }

 /**
  * Adds a child tree item containing the specified text.
  *
  * @param itemText the text of the item to be added
  * @return the item that was added
  */

 TreeItem addTextItem(String itemText) {
   TreeItem ret = new TreeItem();
   ret.text = itemText;
   addItem(ret);
   return ret;
 }


 TreeItem asTreeItem() {
   return this;
 }

 /**
  * Gets the child at the specified index.
  *
  * @param index the index to be retrieved
  * @return the item at that index
  */

 TreeItem getChild(int index) {
   if ((index < 0) || (index >= getChildCount())) {
     return null;
   }

   return _children[index];
 }

 /**
  * Gets the number of children contained in this item.
  *
  * @return this item's child count.
  */

 int getChildCount() {
   if (_children == null) {
     return 0;
   }
   return _children.length;
 }

 /**
  * Gets the index of the specified child item.
  *
  * @param child the child item to be found
  * @return the child's index, or <code>-1</code> if none is found
  */

 int getChildIndex(TreeItem child) {
   if (_children == null) {
     return -1;
   }
   return _children.indexOf(child);
 }


 String get html {
   return _contentElem.innerHtml;
 }

 /**
  * Gets this item's parent.
  *
  * @return the parent item
  */
 TreeItem getParentItem() {
   return _parent;
 }

 /**
  * Gets whether this item's children are displayed.
  *
  * @return <code>true</code> if the item is open
  */
 bool getState() {
   return _open;
 }


 String get text {
   return _contentElem.text;
 }

 /**
  * Gets the tree that contains this item.
  *
  * @return the containing tree
  */
 Tree getTree() {
   return _tree;
 }

 /**
  * Gets the user-defined object associated with this item.
  *
  * @return the item's user-defined object
  */
 Object getUserObject() {
   return _userObject;
 }

 /**
  * Gets the <code>Widget</code> associated with this tree item.
  *
  * @return the widget
  */
 Widget getWidget() {
   return _widget;
 }

 /**
  * Inserts a child tree item at the specified index containing the specified
  * html.
  *
  * @param beforeIndex the index where the item will be inserted
  * @param itemHtml the item's HTML
  * @return the item that was added
  * @throws IndexOutOfBoundsException if the index is out of range
  */
 TreeItem insertSafeHtmlItem(int beforeIndex, SafeHtml itemHtml) {
   TreeItem ret = new TreeItem(html:itemHtml);
   insertItem(beforeIndex, ret);
   return ret;
 }

 /**
  * Inserts an item as a child to this one.
  *
  * @param beforeIndex the index where the item will be inserted
  * @param item the item to be added
  * @throws IndexOutOfBoundsException if the index is out of range
  */
 void insertItem(int beforeIndex, TreeItem item) {
   // Detach item from existing parent.
   maybeRemoveItemFromParent(item);

   // Check the index after detaching in case this item was already the parent.
   int childCount = getChildCount();
   if (beforeIndex < 0 || beforeIndex > childCount) {
     throw new Exception("IndexOutOfBounds");
   }

   if (_children == null) {
     initChildren();
   }

   // Set the margin.
   // Use no margin on top-most items.
   double margin = isRoot ? 0.0 : TreeItem._CHILD_MARGIN;
   if (LocaleInfo.getCurrentLocale().isRTL()) {
     item.getElement().style.marginRight = margin.toString() + Unit.PX.value;
   } else {
     item.getElement().style.marginLeft = margin.toString() + Unit.PX.value;
   }

   // Physical attach.
   dart_html.Element childContainer = isRoot ? _tree.getElement() : _childSpanElem;
   if (beforeIndex == childCount) {
     childContainer.append(item.getElement());
   } else {
     dart_html.Element beforeElem = getChild(beforeIndex).getElement();
     childContainer.insertBefore(item.getElement(), beforeElem);
   }

   // Logical attach.
   // Explicitly set top-level items' parents to null if this is root.
   item.setParentItem(isRoot ? null : this);
   _children.insert(beforeIndex, item);

   // Adopt.
   item.setTree(_tree);

   if (!isRoot && _children.length == 1) {
     updateState(false, false);
   }
 }

 /**
  * Inserts a child tree item at the specified index containing the specified
  * widget.
  *
  * @param beforeIndex the index where the item will be inserted
  * @param widget the widget to be added
  * @return the item that was added
  * @throws IndexOutOfBoundsException if the index is out of range
  */
 TreeItem insertWidgetItem(int beforeIndex, Widget widget) {
   TreeItem ret = new TreeItem(widget:widget);
   insertItem(beforeIndex, ret);
   return ret;
 }

 /**
  * Inserts a child tree item at the specified index containing the specified
  * text.
  *
  * @param beforeIndex the index where the item will be inserted
  * @param itemText the item's text
  * @return the item that was added
  * @throws IndexOutOfBoundsException if the index is out of range
  */
 TreeItem insertTextItem(int beforeIndex, String itemText) {
   TreeItem ret = new TreeItem();
   ret.text = itemText;
   insertItem(beforeIndex, ret);
   return ret;
 }

 /**
  * Determines whether this item is currently selected.
  *
  * @return <code>true</code> if it is selected
  */
 bool isSelected() {
   return _selected;
 }

 /**
  * Removes this item from its tree.
  */
 void remove() {
   if (_parent != null) {
     // If this item has a parent, remove self from it.
     _parent.removeItem(this);
   } else if (_tree != null) {
     // If the item has no parent, but is in the Tree, it must be a top-level
     // element.
     _tree.removeItem(this);
   }
 }

 /**
  * Removes one of this item's children.
  *
  * @param item the item to be removed
  */

 void removeItem(TreeItem item) {
   // Validate.
   if (_children == null || !_children.contains(item)) {
     return;
   }

   // Orphan.
   Tree oldTree = _tree;
   item.setTree(null);

   // Physical detach.
   if (isRoot) {
     //oldTree.getElement().removeChild(item.getElement());
     item.getElement().remove();
   } else {
     //_childSpanElem.removeChild(item.getElement());
     item.getElement().remove();
   }

   // Logical detach.
   item.setParentItem(null);
   _children.remove(item);

   if (!isRoot && _children.length == 0) {
     updateState(false, false);
   }
 }

 /**
  * Removes one of this item's children.
  *
  * @param isItem the wrapper of item to be removed
  */

 void removeIsTreeItem(IsTreeItem isItem) {
   if (isItem != null) {
     TreeItem item = isItem.asTreeItem();
     removeItem(item);
   }
 }

 /**
  * Removes all of this item's children.
  */

 void removeItems() {
   while (getChildCount() > 0) {
     removeItem(getChild(0));
   }
 }


 void set html(String val) {
   setWidget(null);
   _contentElem.innerHtml = val;
 }


 void setSafeHtml(SafeHtml val) {
   html = val.asString();
 }

 /**
  * Selects or deselects this item.
  *
  * @param selected <code>true</code> to select the item, <code>false</code> to
  *          deselect it
  */
 void setSelected(bool selected) {
   if (this._selected == selected) {
     return;
   }
   this._selected = selected;
   UiObject.manageElementStyleName(getContentElem(), "dwt-TreeItem-selected", selected);
 }

 /**
  * Sets whether this item's children are displayed.
  *
  * @param open whether the item is open
  * @param fireEvents <code>true</code> to allow open/close events to be
  */
 void setState(bool open, [bool fireEvents = true]) {
   if (open && getChildCount() == 0) {
     return;
   }

   // Only do the physical update if it changes
   if (this._open != open) {
     this._open = open;
     updateState(true, true);

     if (fireEvents && _tree != null) {
       _tree.fireStateChanged(this, open);
     }
   }
 }


 void set text(String val) {
   setWidget(null);
   _contentElem.text = val;
 }

 /**
  * Sets the user-defined object associated with this item.
  *
  * @param userObj the item's user-defined object
  */
 void setUserObject(Object userObj) {
   _userObject = userObj;
 }

 /**
  * Sets the current widget. Any existing child widget will be removed.
  *
  * @param newWidget Widget to set
  */
 void setWidget(Widget newWidget) {
   // Detach new child from old parent.
   if (newWidget != null) {
     newWidget.removeFromParent();
   }

   // Detach old child from _tree.
   if (_widget != null) {
     try {
       if (_tree != null) {
         _tree.orphan(_widget);
       }
     } finally {
       // Physical detach old child.
       //_contentElem.removeChild(_widget.getElement());
       _widget.getElement().remove();
       _widget = null;
     }
   }

   // Clear out any existing content before adding a widget.
   _contentElem.innerHtml = "";

   // Logical detach old/attach new.
   _widget = newWidget;

   if (newWidget != null) {
     // Physical attach new.
     _contentElem.append(newWidget.getElement());

     // Attach child to tree.
     if (_tree != null) {
       _tree.adopt(_widget, this);
     }

     // Set tabIndex on the widget to -1, so that it doesn't mess up the tab
     // order of the entire tree

     if (Tree.shouldTreeDelegateFocusToElement(_widget.getElement())) {
       _widget.getElement().tabIndex = -1;
     }
   }
 }

 /**
  * Returns a suggested {@link Focusable} instance to use when this tree item
  * is selected. The tree maintains focus if this method returns null. By
  * default, if the tree item contains a focusable widget, that widget is
  * returned.
  *
  * Note, the {@link Tree} will ignore this value if the user clicked on an
  * input element such as a button or text area when selecting this item.
  *
  * @return the focusable item
  */
 Focusable getFocusable() {
   Widget w = getWidget();
   if (w is Focusable) {
     return w as Focusable;
   }
   return null;
 }

 void addTreeItems(List<TreeItem> accum) {
   int size = getChildCount();
   for (int i = 0; i < size; i++) {
     TreeItem item = _children[i];
     accum.add(item);
     item.addTreeItems(accum);
   }
 }

 List<TreeItem> getChildren() {
   return _children;
 }

 dart_html.Element getContentElem() {
   return _contentElem;
 }

 dart_html.Element getImageElement() {
   return Dom.getFirstChild(getImageHolderElement());
 }

 dart_html.Element getImageHolderElement() {
   if (!isFullNode()) {
     convertToFullNode();
   }
   return _imageHolder;
 }

 void initChildren() {
   convertToFullNode();
   _childSpanElem = new dart_html.DivElement();
   getElement().append(_childSpanElem);
   _childSpanElem.style.whiteSpace = "nowrap";
   _children = new List<TreeItem>();
 }

 bool isFullNode() {
   return _imageHolder != null;
 }

 /**
  * Remove a tree item from its parent if it has one.
  *
  * @param item the tree item to remove from its parent
  */
 void maybeRemoveItemFromParent(TreeItem item) {
   if ((item.getParentItem() != null) || (item.getTree() != null)) {
     item.remove();
   }
 }

 void setParentItem(TreeItem parent) {
   this._parent = parent;
 }

 void setTree(Tree newTree) {
   // Early out.
   if (_tree == newTree) {
     return;
   }

   // Remove this item from existing tree.
   if (_tree != null) {
     if (_tree.getSelectedItem() == this) {
       _tree.setSelectedItem(null);
     }

     if (_widget != null) {
       _tree.orphan(_widget);
     }
   }

   _tree = newTree;
   for (int i = 0, n = getChildCount(); i < n; ++i) {
     _children[i].setTree(newTree);
   }
   updateState(false, true);

   if (newTree != null) {
     if (_widget != null) {
       // Add my _widget to the new tree.
       newTree.adopt(_widget, this);
     }
   }
 }

 void updateState(bool animate, bool updateTreeSelection) {
   // If the tree hasn't been set, there is no visual state to update.
   // If the tree is not attached, then update will be called on attach.
   if (_tree == null || _tree.isAttached() == false) {
     return;
   }

   if (getChildCount() == 0) {
     if (_childSpanElem != null) {
       UiObject.setVisible(_childSpanElem, false);
     }
     _tree.showLeafImage(this);
     return;
   }

   // We must use 'display' rather than 'visibility' here,
   // or the children will always take up space.
   if (animate && (_tree != null) && (_tree.isAttached())) {
     _itemAnimation.setItemState(this, _tree.isAnimationEnabled());
   } else {
     _itemAnimation.setItemState(this, false);
   }

   // Change the status image
   if (_open) {
     _tree.showOpenImage(this);
   } else {
     _tree.showClosedImage(this);
   }

   // We may need to update the tree's selection in response to a tree state
   // change. For example, if the tree's currently selected item is a
   // descendant of an item whose branch was just collapsed, then the item
   // itself should become the newly-selected item.
   if (updateTreeSelection) {
     _tree.maybeUpdateSelection(this, this._open);
   }
 }

 void updateStateRecursive() {
   updateStateRecursiveHelper();
   _tree.maybeUpdateSelection(this, this._open);
 }

 void convertToFullNode() {
   _impl.convertToFullNode(this);
 }

 void updateStateRecursiveHelper() {
   updateState(false, false);
   for (int i = 0, n = getChildCount(); i < n; ++i) {
     _children[i].updateStateRecursiveHelper();
   }
 }
}

Extends

UiObject > TreeItem

Implements

HasSafeHtml, HasHtml, HasTreeItems, IsTreeItem

Static Properties

int IMAGE_PAD #

static int IMAGE_PAD = 7

Constructors

new TreeItem({bool isRoot: false, SafeHtml html, Widget widget: null}) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
TreeItem({this.isRoot : false, SafeHtml html, Widget widget:null}) {
 if (_impl == null) {
   _impl = new TreeItemImpl();
 }
 //
 dart_html.Element elem = Dom.clone(_BASE_BARE_ELEM, true);
 setElement(elem);
 _contentElem = Dom.getFirstChild(elem);
 Dom.setElementAttribute(_contentElem, "id", Dom.createUniqueId());

 // The root item always has children.
 if (isRoot) {
   initChildren();
 }

 // Check widget
 if (widget != null) {
   setWidget(widget);
 }
}

Properties

String get html #

Gets this object's contents as HTML.

@return the object's HTML

docs inherited from HasHtml
String get html {
 return _contentElem.innerHtml;
}

void set html(String val) #

Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using {@link #setText(String)} whenever possible.

@param html the object's new HTML

docs inherited from HasHtml
void set html(String val) {
 setWidget(null);
 _contentElem.innerHtml = val;
}

bool isRoot #

Indicates that this item is a root item in a tree.

bool isRoot = false

String get text #

Gets this object's text.

@return the object's text

docs inherited from HasText
String get text {
 return _contentElem.text;
}

void set text(String val) #

Sets this object's text.

@param text the object's new text

docs inherited from HasText
void set text(String val) {
 setWidget(null);
 _contentElem.text = val;
}

String get title #

inherited from UiObject

Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

@return the object's title

String get title => getElement().title;

void set title(String value) #

inherited from UiObject

Sets the element's title.

void set title(String value) {
 getElement().title = value;
}

bool get visible #

inherited from UiObject

Determines whether or not this object is visible. Note that this does not necessarily take into account whether or not the receiver's parent is visible, or even if it is attached to the Document. The default implementation of this trait in UIObject is based on the value of a dom element's style object's display attribute.

@return <code>true</code> if the object is visible

bool get visible => isVisible(getElement());

void set visible(bool visible) #

inherited from UiObject

Sets whether this object is visible.

@param visible <code>true</code> to show the object, <code>false</code> to

     hide it
void set visible(bool visible) {
 setVisible(getElement(), visible);
}

Methods

void addIsTreeItem(IsTreeItem isItem) #

Adds another item as a child to this one.

@param isItem the wrapper of item to be added

void addIsTreeItem(IsTreeItem isItem) {
 TreeItem item = isItem.asTreeItem();
 addItem(item);
}

void addItem(TreeItem item) #

Adds another item as a child to this one.

@param item the item to be added

void addItem(TreeItem item) {
 // If this is the item's parent, removing the item will affect the child
 // count.
 maybeRemoveItemFromParent(item);
 insertItem(getChildCount(), item);
}

TreeItem addSafeHtmlItem(SafeHtml itemHtml) #

Adds a child tree item containing the specified html.

@param itemHtml the item's HTML @return the item that was added

TreeItem addSafeHtmlItem(SafeHtml itemHtml) {
 TreeItem ret = new TreeItem(html:itemHtml);
 addItem(ret);
 return ret;
}

void addStyleDependentName(String styleSuffix) #

inherited from UiObject

Adds a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:

getStylePrimaryName() + '-' + styleSuffix

@param styleSuffix the suffix of the dependent style to be added. @see #setStylePrimaryName(String) @see #removeStyleDependentName(String) @see #setStyleDependentName(String, boolean) @see #addStyleName(String)

void addStyleDependentName(String styleSuffix) {
 setStyleDependentName(styleSuffix, true);
}

void addStyleName(String style) #

inherited from UiObject

Adds a secondary or dependent style name to this object. A secondary style name is an additional style name that is, in HTML/CSS terms, included as a space-separated token in the value of the CSS <code>class</code> attribute for this object's root element.

The most important use for this method is to add a special kind of secondary style name called a dependent style name. To add a dependent style name, use {@link #addStyleDependentName(String)}, which will prefix the 'style' argument with the result of {@link #k()} (followed by a '-'). For example, suppose the primary style name is gwt-TextBox. If the following method is called as obj.setReadOnly(true):

public void setReadOnly(boolean readOnly) {
  isReadOnlyMode = readOnly;

// Create a dependent style name. String readOnlyStyle = "readonly";

if (readOnly) {

addStyleDependentName(readOnlyStyle);

} else {

removeStyleDependentName(readOnlyStyle);

} }</pre>

then both of the CSS style rules below will be applied:

// This rule is based on the primary style name and is always active. .gwt-TextBox { font-size: 12pt; }

// This rule is based on a dependent style name that is only active // when the widget has called addStyleName(getStylePrimaryName() + // "-readonly"). .gwt-TextBox-readonly { background-color: lightgrey; border: none; }</pre>

The code can also be simplified with {@link #setStyleDependentName(String, boolean)}:

public void setReadOnly(boolean readOnly) {
  isReadOnlyMode = readOnly;
  setStyleDependentName("readonly", readOnly);
}

Dependent style names are powerful because they are automatically updated whenever the primary style name changes. Continuing with the example above, if the primary style name changed due to the following call:

setStylePrimaryName("my-TextThingy");

then the object would be re-associated with following style rules, removing those that were shown above.

.my-TextThingy {
  font-size: 20pt;
}

.my-TextThingy-readonly { background-color: red; border: 2px solid yellow; }</pre>

Secondary style names that are not dependent style names are not automatically updated when the primary style name changes.

@param style the secondary style name to be added @see UIObject @see #removeStyleName(String)

void addStyleName(String style) {
 setStyleName(style, true);
}

TreeItem addTextItem(String itemText) #

Adds a child tree item containing the specified text.

@param itemText the text of the item to be added @return the item that was added

TreeItem addTextItem(String itemText) {
 TreeItem ret = new TreeItem();
 ret.text = itemText;
 addItem(ret);
 return ret;
}

void addTreeItems(List<TreeItem> accum) #

void addTreeItems(List<TreeItem> accum) {
 int size = getChildCount();
 for (int i = 0; i < size; i++) {
   TreeItem item = _children[i];
   accum.add(item);
   item.addTreeItems(accum);
 }
}

TreeItem addWidgetItem(Widget widget) #

Adds a child tree item containing the specified widget.

@param widget the widget to be added @return the item that was added

TreeItem addWidgetItem(Widget widget) {
 TreeItem ret = new TreeItem(widget:widget);
 addItem(ret);
 return ret;
}

TreeItem asTreeItem() #

Returns the {@link TreeItem} aspect of the receiver.

docs inherited from IsTreeItem
TreeItem asTreeItem() {
 return this;
}

void clearAndSetStyleName(String style) #

inherited from UiObject

Clears all of the object's style names and sets it to the given style. You should normally use {@link #setStylePrimaryName(String)} unless you wish to explicitly remove all existing styles.

@param style the new style name @see #setStylePrimaryName(String)

void clearAndSetStyleName(String style) {
 setElementStyleName(getStyleElement(), style);
}

void convertToFullNode() #

void convertToFullNode() {
 _impl.convertToFullNode(this);
}

double extractLengthValue(String s) #

inherited from UiObject

Intended to be used to pull the value out of a CSS length. If the value is "auto" or "inherit", 0 will be returned.

@param s The CSS length string to extract @return The leading numeric portion of <code>s</code>, or 0 if "auto" or

    "inherit" are passed in.
double extractLengthValue(String s) {
 if (s == "auto" || s == "inherit" || s == "") {
   return 0.0;
 } else {
   // numberRegex divides the string into a leading numeric portion
   // followed by an arbitrary portion.
   if(numberRegex.hasMatch(s)) {
     // Extract the leading numeric portion of string
     s = numberRegex.firstMatch(s)[0];
   }
   return double.parse(s);
 }
}

int getAbsoluteLeft() #

inherited from UiObject

Gets the object's absolute left position in pixels, as measured from the browser window's client area.

@return the object's absolute left position

int getAbsoluteLeft() {
 return Dom.getAbsoluteLeft(getElement());
}

int getAbsoluteTop() #

inherited from UiObject

Gets the object's absolute top position in pixels, as measured from the browser window's client area.

@return the object's absolute top position

int getAbsoluteTop() {
 return Dom.getAbsoluteTop(getElement());
}

TreeItem getChild(int index) #

Gets the child at the specified index.

@param index the index to be retrieved @return the item at that index

TreeItem getChild(int index) {
 if ((index < 0) || (index >= getChildCount())) {
   return null;
 }

 return _children[index];
}

int getChildCount() #

Gets the number of children contained in this item.

@return this item's child count.

int getChildCount() {
 if (_children == null) {
   return 0;
 }
 return _children.length;
}

int getChildIndex(TreeItem child) #

Gets the index of the specified child item.

@param child the child item to be found @return the child's index, or <code>-1</code> if none is found

int getChildIndex(TreeItem child) {
 if (_children == null) {
   return -1;
 }
 return _children.indexOf(child);
}

List<TreeItem> getChildren() #

List<TreeItem> getChildren() {
 return _children;
}

Element getContentElem() #

dart_html.Element getContentElem() {
 return _contentElem;
}

Element getElement() #

inherited from UiObject

Gets this object's browser element.

dart_html.Element getElement() {
 assert (_element != null); // : MISSING_ELEMENT_ERROR;
 return _element;
}

Focusable getFocusable() #

Returns a suggested {@link Focusable} instance to use when this tree item is selected. The tree maintains focus if this method returns null. By default, if the tree item contains a focusable widget, that widget is returned.

Note, the {@link Tree} will ignore this value if the user clicked on an input element such as a button or text area when selecting this item.

@return the focusable item

Focusable getFocusable() {
 Widget w = getWidget();
 if (w is Focusable) {
   return w as Focusable;
 }
 return null;
}

Element getImageElement() #

dart_html.Element getImageElement() {
 return Dom.getFirstChild(getImageHolderElement());
}

Element getImageHolderElement() #

dart_html.Element getImageHolderElement() {
 if (!isFullNode()) {
   convertToFullNode();
 }
 return _imageHolder;
}

int getOffsetHeight() #

inherited from UiObject

Gets the object's offset height in pixels. This is the total height of the object, including decorations such as border and padding, but not margin.

@return the object's offset height

int getOffsetHeight() {
 return getElement().offset.height; // Dom.getElementPropertyInt(getElement(), "offsetHeight");
}

int getOffsetWidth() #

inherited from UiObject

Gets the object's offset width in pixels. This is the total width of the object, including decorations such as border and padding, but not margin.

@return the object's offset width

int getOffsetWidth() {
 return getElement().offset.width; // Dom.getElementPropertyInt(getElement(), "offsetWidth");
}

TreeItem getParentItem() #

Gets this item's parent.

@return the parent item

TreeItem getParentItem() {
 return _parent;
}

bool getState() #

Gets whether this item's children are displayed.

@return <code>true</code> if the item is open

bool getState() {
 return _open;
}

Element getStyleElement() #

inherited from UiObject

Template method that returns the element to which style names will be applied. By default it returns the root element, but this method may be overridden to apply styles to a child element.

@return the element to which style names will be applied

dart_html.Element getStyleElement() {
 return getElement();
}

String getStyleName() #

inherited from UiObject

Gets all of the object's style names, as a space-separated list. If you wish to retrieve only the primary style name, call {@link #getStylePrimaryName()}.

@return the objects's space-separated style names @see #getStylePrimaryName()

String getStyleName() {
 return getElementStyleName(getStyleElement());
}

String getStylePrimaryName() #

inherited from UiObject

Gets the primary style name associated with the object.

@return the object's primary style name @see #setStyleName(String) @see #addStyleName(String) @see #removeStyleName(String)

String getStylePrimaryName() {
 return getElementStylePrimaryName(getStyleElement());
}

Tree getTree() #

Gets the tree that contains this item.

@return the containing tree

Tree getTree() {
 return _tree;
}

Object getUserObject() #

Gets the user-defined object associated with this item.

@return the item's user-defined object

Object getUserObject() {
 return _userObject;
}

Widget getWidget() #

Gets the <code>Widget</code> associated with this tree item.

@return the widget

Widget getWidget() {
 return _widget;
}

void initChildren() #

void initChildren() {
 convertToFullNode();
 _childSpanElem = new dart_html.DivElement();
 getElement().append(_childSpanElem);
 _childSpanElem.style.whiteSpace = "nowrap";
 _children = new List<TreeItem>();
}

void insertItem(int beforeIndex, TreeItem item) #

Inserts an item as a child to this one.

@param beforeIndex the index where the item will be inserted @param item the item to be added @throws IndexOutOfBoundsException if the index is out of range

void insertItem(int beforeIndex, TreeItem item) {
 // Detach item from existing parent.
 maybeRemoveItemFromParent(item);

 // Check the index after detaching in case this item was already the parent.
 int childCount = getChildCount();
 if (beforeIndex < 0 || beforeIndex > childCount) {
   throw new Exception("IndexOutOfBounds");
 }

 if (_children == null) {
   initChildren();
 }

 // Set the margin.
 // Use no margin on top-most items.
 double margin = isRoot ? 0.0 : TreeItem._CHILD_MARGIN;
 if (LocaleInfo.getCurrentLocale().isRTL()) {
   item.getElement().style.marginRight = margin.toString() + Unit.PX.value;
 } else {
   item.getElement().style.marginLeft = margin.toString() + Unit.PX.value;
 }

 // Physical attach.
 dart_html.Element childContainer = isRoot ? _tree.getElement() : _childSpanElem;
 if (beforeIndex == childCount) {
   childContainer.append(item.getElement());
 } else {
   dart_html.Element beforeElem = getChild(beforeIndex).getElement();
   childContainer.insertBefore(item.getElement(), beforeElem);
 }

 // Logical attach.
 // Explicitly set top-level items' parents to null if this is root.
 item.setParentItem(isRoot ? null : this);
 _children.insert(beforeIndex, item);

 // Adopt.
 item.setTree(_tree);

 if (!isRoot && _children.length == 1) {
   updateState(false, false);
 }
}

TreeItem insertSafeHtmlItem(int beforeIndex, SafeHtml itemHtml) #

Inserts a child tree item at the specified index containing the specified html.

@param beforeIndex the index where the item will be inserted @param itemHtml the item's HTML @return the item that was added @throws IndexOutOfBoundsException if the index is out of range

TreeItem insertSafeHtmlItem(int beforeIndex, SafeHtml itemHtml) {
 TreeItem ret = new TreeItem(html:itemHtml);
 insertItem(beforeIndex, ret);
 return ret;
}

TreeItem insertTextItem(int beforeIndex, String itemText) #

Inserts a child tree item at the specified index containing the specified text.

@param beforeIndex the index where the item will be inserted @param itemText the item's text @return the item that was added @throws IndexOutOfBoundsException if the index is out of range

TreeItem insertTextItem(int beforeIndex, String itemText) {
 TreeItem ret = new TreeItem();
 ret.text = itemText;
 insertItem(beforeIndex, ret);
 return ret;
}

TreeItem insertWidgetItem(int beforeIndex, Widget widget) #

Inserts a child tree item at the specified index containing the specified widget.

@param beforeIndex the index where the item will be inserted @param widget the widget to be added @return the item that was added @throws IndexOutOfBoundsException if the index is out of range

TreeItem insertWidgetItem(int beforeIndex, Widget widget) {
 TreeItem ret = new TreeItem(widget:widget);
 insertItem(beforeIndex, ret);
 return ret;
}

bool isFullNode() #

bool isFullNode() {
 return _imageHolder != null;
}

bool isSelected() #

Determines whether this item is currently selected.

@return <code>true</code> if it is selected

bool isSelected() {
 return _selected;
}

void maybeRemoveItemFromParent(TreeItem item) #

Remove a tree item from its parent if it has one.

@param item the tree item to remove from its parent

void maybeRemoveItemFromParent(TreeItem item) {
 if ((item.getParentItem() != null) || (item.getTree() != null)) {
   item.remove();
 }
}

void remove() #

Removes this item from its tree.

void remove() {
 if (_parent != null) {
   // If this item has a parent, remove self from it.
   _parent.removeItem(this);
 } else if (_tree != null) {
   // If the item has no parent, but is in the Tree, it must be a top-level
   // element.
   _tree.removeItem(this);
 }
}

void removeIsTreeItem(IsTreeItem isItem) #

Removes one of this item's children.

@param isItem the wrapper of item to be removed

void removeIsTreeItem(IsTreeItem isItem) {
 if (isItem != null) {
   TreeItem item = isItem.asTreeItem();
   removeItem(item);
 }
}

void removeItem(TreeItem item) #

Removes one of this item's children.

@param item the item to be removed

void removeItem(TreeItem item) {
 // Validate.
 if (_children == null || !_children.contains(item)) {
   return;
 }

 // Orphan.
 Tree oldTree = _tree;
 item.setTree(null);

 // Physical detach.
 if (isRoot) {
   //oldTree.getElement().removeChild(item.getElement());
   item.getElement().remove();
 } else {
   //_childSpanElem.removeChild(item.getElement());
   item.getElement().remove();
 }

 // Logical detach.
 item.setParentItem(null);
 _children.remove(item);

 if (!isRoot && _children.length == 0) {
   updateState(false, false);
 }
}

void removeItems() #

Removes all of this item's children.

void removeItems() {
 while (getChildCount() > 0) {
   removeItem(getChild(0));
 }
}

void removeStyleDependentName(String styleSuffix) #

inherited from UiObject

Removes a dependent style name by specifying the style name's suffix.

@param styleSuffix the suffix of the dependent style to be removed @see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleDependentName(String, boolean)

void removeStyleDependentName(String styleSuffix) {
 setStyleDependentName(styleSuffix, false);
}

void removeStyleName(String style) #

inherited from UiObject

Removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.

@param style the secondary style name to be removed @see #addStyleName(String) @see #setStyleName(String, boolean)

void removeStyleName(String style) {
 setStyleName(style, false);
}

void replaceElement(Element elem) #

inherited from UiObject

Replaces this object's browser element.

This method exists only to support a specific use-case in Image, and should not be used by other classes.

@param elem the object's new element

void replaceElement(dart_html.Element elem) {
 if (_element != null && _element.parent != null) {
   // replace this.element in its parent with elem.
   _element.replaceWith(elem);
 }

 this._element = elem;
}

void setElement(Element elem) #

inherited from UiObject

Sets this object's browser element. UIObject subclasses must call this method before attempting to call any other methods, and it may only be called once.

@param elem the object's element

void setElement(dart_html.Element elem) {
 assert (_element == null);
 this._element = elem;
}

void setHeight(String height) #

inherited from UiObject

Sets the object's height. This height does not include decorations such as border, margin, and padding.

@param height the object's new height, in CSS units (e.g. "10px", "1em")

void setHeight(String height) {
 // This exists to deal with an inconsistency in IE's implementation where
 // it won't accept negative numbers in length measurements
 assert (extractLengthValue(height.trim().toLowerCase()) >= 0); // : "CSS heights should not be negative";
 Dom.setStyleAttribute(getElement(), "height", height);
}

void setParentItem(TreeItem parent) #

void setParentItem(TreeItem parent) {
 this._parent = parent;
}

void setPixelSize(int width, int height) #

inherited from UiObject

Sets the object's size, in pixels, not including decorations such as border, margin, and padding.

@param width the object's new width, in pixels @param height the object's new height, in pixels

void setPixelSize(int width, int height) {
 if (width >= 0) {
   setWidth(width.toString() + "px");
 }
 if (height >= 0) {
   setHeight(height.toString() + "px");
 }
}

void setSafeHtml(SafeHtml val) #

void setSafeHtml(SafeHtml val) {
 html = val.asString();
}

void setSelected(bool selected) #

Selects or deselects this item.

@param selected <code>true</code> to select the item, <code>false</code> to

     deselect it
void setSelected(bool selected) {
 if (this._selected == selected) {
   return;
 }
 this._selected = selected;
 UiObject.manageElementStyleName(getContentElem(), "dwt-TreeItem-selected", selected);
}

void setSize(String width, String height) #

inherited from UiObject

Sets the object's size. This size does not include decorations such as border, margin, and padding.

@param width the object's new width, in CSS units (e.g. "10px", "1em") @param height the object's new height, in CSS units (e.g. "10px", "1em")

void setSize(String width, String height) {
 setWidth(width);
 setHeight(height);
}

void setState(bool open, [bool fireEvents = true]) #

Sets whether this item's children are displayed.

@param open whether the item is open @param fireEvents <code>true</code> to allow open/close events to be

void setState(bool open, [bool fireEvents = true]) {
 if (open && getChildCount() == 0) {
   return;
 }

 // Only do the physical update if it changes
 if (this._open != open) {
   this._open = open;
   updateState(true, true);

   if (fireEvents && _tree != null) {
     _tree.fireStateChanged(this, open);
   }
 }
}

void setStyleDependentName(String styleSuffix, bool add) #

inherited from UiObject

Adds or removes a dependent style name by specifying the style name's suffix. The actual form of the style name that is added is:

getStylePrimaryName() + '-' + styleSuffix

@param styleSuffix the suffix of the dependent style to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to

     remove it

@see #setStylePrimaryName(Element, String) @see #addStyleDependentName(String) @see #setStyleName(String, boolean) @see #removeStyleDependentName(String)

void setStyleDependentName(String styleSuffix, bool add) {
 setStyleName(getStylePrimaryName() + '-' + styleSuffix, add);
}

void setStyleName(String style, bool add) #

inherited from UiObject

Adds or removes a style name. This method is typically used to remove secondary style names, but it can be used to remove primary stylenames as well. That use is not recommended.

@param style the style name to be added or removed @param add <code>true</code> to add the given style, <code>false</code> to

     remove it

@see #addStyleName(String) @see #removeStyleName(String)

void setStyleName(String style, bool add) {
 manageElementStyleName(getStyleElement(), style, add);
}

void setStylePrimaryName(String style) #

inherited from UiObject

Sets the object's primary style name and updates all dependent style names.

@param style the new primary style name @see #addStyleName(String) @see #removeStyleName(String)

void setStylePrimaryName(String style) {
 setElementStylePrimaryName(getStyleElement(), style);
}

void setTree(Tree newTree) #

void setTree(Tree newTree) {
 // Early out.
 if (_tree == newTree) {
   return;
 }

 // Remove this item from existing tree.
 if (_tree != null) {
   if (_tree.getSelectedItem() == this) {
     _tree.setSelectedItem(null);
   }

   if (_widget != null) {
     _tree.orphan(_widget);
   }
 }

 _tree = newTree;
 for (int i = 0, n = getChildCount(); i < n; ++i) {
   _children[i].setTree(newTree);
 }
 updateState(false, true);

 if (newTree != null) {
   if (_widget != null) {
     // Add my _widget to the new tree.
     newTree.adopt(_widget, this);
   }
 }
}

void setUserObject(Object userObj) #

Sets the user-defined object associated with this item.

@param userObj the item's user-defined object

void setUserObject(Object userObj) {
 _userObject = userObj;
}

void setWidget(Widget newWidget) #

Sets the current widget. Any existing child widget will be removed.

@param newWidget Widget to set

void setWidget(Widget newWidget) {
 // Detach new child from old parent.
 if (newWidget != null) {
   newWidget.removeFromParent();
 }

 // Detach old child from _tree.
 if (_widget != null) {
   try {
     if (_tree != null) {
       _tree.orphan(_widget);
     }
   } finally {
     // Physical detach old child.
     //_contentElem.removeChild(_widget.getElement());
     _widget.getElement().remove();
     _widget = null;
   }
 }

 // Clear out any existing content before adding a widget.
 _contentElem.innerHtml = "";

 // Logical detach old/attach new.
 _widget = newWidget;

 if (newWidget != null) {
   // Physical attach new.
   _contentElem.append(newWidget.getElement());

   // Attach child to tree.
   if (_tree != null) {
     _tree.adopt(_widget, this);
   }

   // Set tabIndex on the widget to -1, so that it doesn't mess up the tab
   // order of the entire tree

   if (Tree.shouldTreeDelegateFocusToElement(_widget.getElement())) {
     _widget.getElement().tabIndex = -1;
   }
 }
}

void setWidth(String width) #

inherited from UiObject

Sets the object's width. This width does not include decorations such as border, margin, and padding.

@param width the object's new width, in CSS units (e.g. "10px", "1em")

void setWidth(String width) {
 // This exists to deal with an inconsistency in IE's implementation where
 // it won't accept negative numbers in length measurements
 assert (extractLengthValue(width.trim().toLowerCase()) >= 0); // : "CSS widths should not be negative";
 Dom.setStyleAttribute(getElement(), "width", width);
}

void sinkBitlessEvent(String eventTypeName) #

inherited from UiObject

Sinks a named event. Note that only {@link Widget widgets} may actually receive events, but can receive events from all objects contained within them.

@param eventTypeName name of the event to sink on this element @see com.google.gwt.user.client.Event

void sinkBitlessEvent(String eventTypeName) {
 Dom.sinkBitlessEvent(getElement(), eventTypeName);
}

void sinkEvents(int eventBitsToAdd) #

inherited from UiObject

Adds a set of events to be sunk by this object. Note that only {@link Widget widgets} may actually receive events, but can receive events from all objects contained within them.

@param eventBitsToAdd a bitfield representing the set of events to be added

     to this element's event set

@see com.google.gwt.user.client.Event

void sinkEvents(int eventBitsToAdd) {
 Dom.sinkEvents(getElement(), eventBitsToAdd | Dom.getEventsSunk(getElement()));
}

String toString() #

inherited from UiObject

This method is overridden so that any object can be viewed in the debugger as an HTML snippet.

@return a string representation of the object

String toString() {
 if (_element == null) {
   return "(null handle)";
 }
 return getElement().toString();
}

void unsinkEvents(int eventBitsToRemove) #

inherited from UiObject

Removes a set of events from this object's event list.

@param eventBitsToRemove a bitfield representing the set of events to be

     removed from this element's event set

@see #sinkEvents @see com.google.gwt.user.client.Event

void unsinkEvents(int eventBitsToRemove) {
 Dom.sinkEvents(getElement(), Dom.getEventsSunk(getElement()) & (~eventBitsToRemove));
}

void updateState(bool animate, bool updateTreeSelection) #

void updateState(bool animate, bool updateTreeSelection) {
 // If the tree hasn't been set, there is no visual state to update.
 // If the tree is not attached, then update will be called on attach.
 if (_tree == null || _tree.isAttached() == false) {
   return;
 }

 if (getChildCount() == 0) {
   if (_childSpanElem != null) {
     UiObject.setVisible(_childSpanElem, false);
   }
   _tree.showLeafImage(this);
   return;
 }

 // We must use 'display' rather than 'visibility' here,
 // or the children will always take up space.
 if (animate && (_tree != null) && (_tree.isAttached())) {
   _itemAnimation.setItemState(this, _tree.isAnimationEnabled());
 } else {
   _itemAnimation.setItemState(this, false);
 }

 // Change the status image
 if (_open) {
   _tree.showOpenImage(this);
 } else {
   _tree.showClosedImage(this);
 }

 // We may need to update the tree's selection in response to a tree state
 // change. For example, if the tree's currently selected item is a
 // descendant of an item whose branch was just collapsed, then the item
 // itself should become the newly-selected item.
 if (updateTreeSelection) {
   _tree.maybeUpdateSelection(this, this._open);
 }
}

void updateStateRecursive() #

void updateStateRecursive() {
 updateStateRecursiveHelper();
 _tree.maybeUpdateSelection(this, this._open);
}

void updateStateRecursiveHelper() #

void updateStateRecursiveHelper() {
 updateState(false, false);
 for (int i = 0, n = getChildCount(); i < n; ++i) {
   _children[i].updateStateRecursiveHelper();
 }
}