Class 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
    • Constructor Detail

      • 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,
                           java.lang.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 Detail

      • 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​(java.lang.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
      • clear

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

        public CmsTreeItem getChild​(java.lang.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:
        CmsList.getItem(String)
      • getChildCount

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

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

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

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

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

        Returns:
        a path of IDs separated by slash
      • getTree

        public CmsTree<CmsTreeItemgetTree()
        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.

      • 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
      • 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)
      • 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,​java.lang.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
      • 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.