Class CmsTreeItem

java.lang.Object
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Composite
org.opencms.gwt.client.ui.CmsListItem
org.opencms.gwt.client.ui.tree.CmsTreeItem
All Implemented Interfaces:
com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.HasVisibility, com.google.gwt.user.client.ui.IsRenderable, com.google.gwt.user.client.ui.IsWidget, I_CmsDraggable, I_CmsListItem, I_CmsTruncable
Direct Known Subclasses:
CmsCategoryTreeItem, CmsGalleryTreeItem, CmsLazyTreeItem, CmsLazyTreeItem.LoadingItem, CmsModelPageTreeItem

public class CmsTreeItem extends CmsListItem
List tree item implementation.

Implemented as:

 <li class='listTreeItem listTreeItem*state*'>
   <span class='listTreeItemImage'></span>
   <div class='listTreeItemContent'>...*content*</div>
   <ul class='listTreeItemChildren'>
      *children*
   </ul>
 </li>
 
Where state can be opened, closed or leaf.

Since:
8.0.0
  • Field Details

  • Constructor Details

    • CmsTreeItem

      public CmsTreeItem(boolean showOpeners, CmsCheckBox checkbox, com.google.gwt.user.client.ui.Widget mainWidget)
      Creates a new list tree item containing a main widget and a check box.

      Parameters:
      showOpeners - if true, show open/close icons
      checkbox - the check box
      mainWidget - the main widget
    • CmsTreeItem

      public CmsTreeItem(boolean showOpeners, com.google.gwt.user.client.ui.Widget mainWidget)
      Creates a new list tree item containing a main widget.

      Parameters:
      showOpeners - if true, show open/close icons
      mainWidget - the main widget
    • CmsTreeItem

      public CmsTreeItem(boolean showOpeners, com.google.gwt.user.client.ui.Widget mainWidget, String icon)
      Creates a new tree item with a 24px wide icon.

      Parameters:
      showOpeners - if true, show open/close icons
      mainWidget - the main widget
      icon - the icon style name
    • CmsTreeItem

      protected CmsTreeItem(boolean showOpeners)
      Default constructor.

      Parameters:
      showOpeners - if true, the opener icons should be shown
  • Method Details

    • getLastOpenedItem

      protected static CmsTreeItem getLastOpenedItem(CmsTreeItem item, int stopLevel, boolean requiresDropEnabled)
      Returns the last opened item of a tree fragment.

      Parameters:
      item - the tree item
      stopLevel - the level to stop at, set -1 to go to the very last opened item
      requiresDropEnabled - true if it is required the returned element to be drop enabled
      Returns:
      the last visible item of a tree fragment
    • getPathLevel

      protected static int getPathLevel(String path)
      Method determining the path level by counting the number of '/'.

      Example: '/xxx/xxx/' has a path-level of 2.

      Parameters:
      path - the path to test
      Returns:
      the path level
    • add

      public void add(com.google.gwt.user.client.ui.Widget w)
      Unsupported operation.

      Specified by:
      add in interface I_CmsListItem
      Overrides:
      add in class CmsListItem
      Parameters:
      w - the widget to add
      See Also:
    • addChild

      public void addChild(CmsTreeItem item)
      Adds a child list item.

      Parameters:
      item - the child to add
      See Also:
    • clear

      public void clear()
      See Also:
      • HasWidgets.clear()
    • clearChildren

      public void clearChildren()
      Removes all children.

      See Also:
    • closeAllEmptyChildren

      public void closeAllEmptyChildren()
      Closes all empty child entries.

    • getChild

      public CmsTreeItem getChild(int index)
      Returns the child tree item at the given position.

      Parameters:
      index - the position
      Returns:
      the tree item
      See Also:
    • getChild

      public CmsTreeItem getChild(String itemId)
      Returns the tree item with the given id.

      Parameters:
      itemId - the id of the item to retrieve
      Returns:
      the tree item
      See Also:
    • getChildCount

      public int getChildCount()
      Helper method which gets the number of children.

      Returns:
      the number of children
      See Also:
      • ComplexPanel.getWidgetCount()
    • getChildren

      public CmsList<? extends I_CmsListItem> getChildren()
      Returns the children of this list item.

      Returns:
      the children list
    • getDragHelper

      public com.google.gwt.dom.client.Element getDragHelper(I_CmsDropTarget target)
      Description copied from interface: I_CmsDraggable
      Creates the drag helper element and attaches it into the DOM.

      Specified by:
      getDragHelper in interface I_CmsDraggable
      Overrides:
      getDragHelper in class CmsListItem
      Parameters:
      target - the drop target
      Returns:
      the drag helper element
      See Also:
    • getItemPosition

      public int getItemPosition(CmsTreeItem item)
      Returns the given item position.

      Parameters:
      item - the item to get the position for
      Returns:
      the item position
    • getParentItem

      Returns the parent item.

      Returns:
      the parent item
    • getParentTarget

      Description copied from interface: I_CmsDraggable
      Returns the parent drop target or null if there is none.

      Specified by:
      getParentTarget in interface I_CmsDraggable
      Overrides:
      getParentTarget in class CmsListItem
      Returns:
      the parent drop target
      See Also:
    • getPath

      public String getPath()
      Returns the path of IDs for the this item.

      Returns:
      a path of IDs separated by slash
    • getTree

      Gets the tree to which this tree item belongs, or null if it does not belong to a tree.

      Returns:
      a tree or null
    • hideOpeners

      public void hideOpeners()
      Hides the open/close icons for this tree item and its descendants.

    • insertChild

      public void insertChild(CmsTreeItem item, int position)
      Inserts the given item at the given position.

      Parameters:
      item - the item to insert
      position - the position
      See Also:
    • isDropEnabled

      public boolean isDropEnabled()
      Checks if dropping is enabled.

      Returns:
      true if dropping is enabled
    • isOpen

      public boolean isOpen()
      Checks if the item is open or closed.

      Returns:
      true if open
    • onDragCancel

      public void onDragCancel()
      Description copied from interface: I_CmsDraggable
      Executed on drag cancel.

      Specified by:
      onDragCancel in interface I_CmsDraggable
      Overrides:
      onDragCancel in class CmsListItem
      See Also:
    • removeChild

      Removes an item from the list.

      Parameters:
      item - the item to remove
      Returns:
      the removed item
      See Also:
    • removeChild

      public CmsTreeItem removeChild(int index)
      Removes the item identified by the given index from the list.

      Parameters:
      index - the index of the item to remove
      Returns:
      the removed item
      See Also:
      • ComplexPanel.remove(int)
    • removeChild

      public CmsTreeItem removeChild(String itemId)
      Removes an item from the list.

      Parameters:
      itemId - the id of the item to remove
      Returns:
      the removed item
      See Also:
    • removeOpener

      public void removeOpener()
      Removes the opener widget.

    • repositionPlaceholder

      public int repositionPlaceholder(int x, int y, com.google.gwt.dom.client.Element placeholder, CmsDNDHandler.Orientation orientation)
      Positions the drag and drop placeholder as a sibling or descendant of this element.

      Parameters:
      x - the cursor client x position
      y - the cursor client y position
      placeholder - the placeholder
      orientation - the drag and drop orientation
      Returns:
      the placeholder index
    • setDropEnabled

      public void setDropEnabled(boolean enabled)
      Enables/disables dropping.

      Parameters:
      enabled - true to enable, or false to disable
    • setLeafStyle

      public void setLeafStyle(boolean isLeaf)
      Sets the tree item style to leaf, hiding the list opener.

      Parameters:
      isLeaf - true to set to leaf style
    • setOpen

      public void setOpen(boolean open)
      Opens or closes this tree item (i.e. shows or hides its descendants).

      Parameters:
      open - if true, open the tree item, else close it
    • setOpen

      public void setOpen(boolean open, boolean fireEvents)
      Opens or closes this tree item (i.e. shows or hides its descendants).

      Parameters:
      open - if true, open the tree item, else close it
      fireEvents - true if the open/close events should be fired
    • setParentItem

      public void setParentItem(CmsTreeItem parentItem)
      Sets the parent item.

      Parameters:
      parentItem - the parent item to set
    • setTree

      public void setTree(CmsTree<CmsTreeItem> tree)
      Sets the tree to which this tree item belongs.

      This is automatically called when this tree item or one of its ancestors is inserted into a tree.

      Parameters:
      tree - the tree into which the item has been inserted
    • showOpeners

      public void showOpeners()
      Shows the open/close icons for this tree item and its descendants.

    • visit

      public void visit(com.google.common.base.Function<CmsTreeItem,Boolean> visitor)
      Visits all nested tree items with the given visitor function.

      Parameters:
      visitor - the visitor
    • adopt

      protected void adopt(CmsTreeItem item)
      Adopts the given item.

      Parameters:
      item - the item to adopt
    • createOpener

      Creates the button for opening/closing this item.

      Returns:
      a button
    • executeOpen

      protected void executeOpen(boolean fireEvents)
      Executes the open call.

      Parameters:
      fireEvents - if true, open/close events will be fired
    • fireClose

      protected void fireClose()
      Fires the close event.

    • fireOpen

      protected void fireOpen()
      Fires the open event on the tree.

    • insertPlaceholderAsLastChild

      protected int insertPlaceholderAsLastChild(com.google.gwt.dom.client.Element placeholder)
      Inserts the placeholder element as last child of the children list. Setting it's path as the current placeholder path and returning the new index.

      Parameters:
      placeholder - the placeholder element
      Returns:
      the new index
    • onChangeChildren

      protected void onChangeChildren()
      Helper method which is called when the list of children changes.