Class WTree

    • Constructor Detail

      • WTree

        public WTree()
        Construct the WTree.
      • WTree

        public WTree​(WTree.Type type)
        Parameters:
        type - the tree type.
    • Method Detail

      • getValue

        public Set<String> getValue()
        Returns a Set of the selected options. If no options have been selected, then it returns an empty list.

        As getValue calls WBeanComponent.getData() for the currently selected options, it usually expects getData to return null (for no selection) or a List of selected options. If the data returned by getData is not null and is not a List, then setData will either (1) if the data is an array, convert the array to a List or (2) create a List and add the data as the selected option.

        getValue will verify the selected option/s are valid. If a selected option does not exist, then it will throw an IllegalArgumentException.

        Specified by:
        getValue in interface Input
        Overrides:
        getValue in class AbstractInput
        Returns:
        the selected options in the given UI context.
      • getValueAsString

        public String getValueAsString()
        Returns a string value of the selected item for this users session. If multiple selections have been made, this will be a comma separated list of string values. If no value is selected, null is returned.
        Specified by:
        getValueAsString in interface Input
        Overrides:
        getValueAsString in class AbstractInput
        Returns:
        the selected item value as a rendered String
      • isEmpty

        public boolean isEmpty()
        Description copied from class: AbstractInput
        Indicates whether this input field is empty. An input is considered empty if the value is null or an empty String.
        Specified by:
        isEmpty in interface Input
        Overrides:
        isEmpty in class AbstractInput
        Returns:
        true if nothing selected
      • getType

        public WTree.Type getType()
        Returns:
        the tree type.
      • setType

        public void setType​(WTree.Type type)
        Parameters:
        type - the tree type
      • getMargin

        public Margin getMargin()
        Get the margin for the component, or null if not set.
        Specified by:
        getMargin in interface Marginable
        Returns:
        the margin for the component, or null if not set
      • setMargin

        public void setMargin​(Margin margin)
        Set the margin for the component, or null for no margin.
        Specified by:
        setMargin in interface Marginable
        Parameters:
        margin - the margin for the component
      • getTreeModel

        public TreeItemModel getTreeModel()
        Returns:
        the tree model
      • setTreeModel

        public void setTreeModel​(TreeItemModel treeModel)
        Sets the tree model which provides row data.
        Parameters:
        treeModel - the tree model.
      • getOpenAction

        public Action getOpenAction()
        The action when a request to open a tree item is received.
        Returns:
        the open action
      • setOpenAction

        public void setOpenAction​(Action action)
        The action when a request to open a tree item is received.
        Parameters:
        action - the open action
      • isShuffle

        public boolean isShuffle()
        Returns:
        true if allow the client to shuffle items
      • setShuffle

        public void setShuffle​(boolean shuffle)
        Parameters:
        shuffle - true if allow the client to shuffle items
      • getShuffleAction

        public Action getShuffleAction()
        The action used when the tree items are shuffled on the client.
        Returns:
        the shuffle action
      • setShuffleAction

        public void setShuffleAction​(Action action)
        The action used when the tree items are shuffled on the client.
        Parameters:
        action - the shuffle action
      • getCustomTree

        public TreeItemIdNode getCustomTree()
        Returns:
        the root node of a custom tree structure
      • setCustomTree

        public void setCustomTree​(String json)
        Parameters:
        json - the json representing a custom tree structure
      • setCustomTree

        public void setCustomTree​(TreeItemIdNode customTree)
        Set a custom view of the tree nodes.

        When using custom trees it is important to implement the correct logic in getItemRowIndex(itemId) in the model to match between the row item id ands its row index.

        Parameters:
        customTree - the root node of a custom tree structure
      • getSelectMode

        public WTree.SelectMode getSelectMode()
        Returns:
        the row selection mode.
      • setSelectMode

        public void setSelectMode​(WTree.SelectMode selectMode)
        Sets the row selection mode.
        Parameters:
        selectMode - the row selection mode to set.
      • getExpandMode

        public WTree.ExpandMode getExpandMode()
        Returns:
        the row expansion mode.
      • setExpandMode

        public void setExpandMode​(WTree.ExpandMode expandMode)
        Sets the row expansion mode.
        Parameters:
        expandMode - the expand mode to set.
      • setSelectedRows

        public void setSelectedRows​(Set<String> itemIds)
        Set the row keys that are selected.

        A row key uniquely identifies each row and is determined by the TreeItemModel. Refer to TreeItemModel.getItemId(List).

        Parameters:
        itemIds - the keys of selected rows.
      • setExpandedRows

        public void setExpandedRows​(Set<String> itemIds)
        Set the row keys that are expanded.

        A row key uniquely identifies each row and is determined by the TreeItemModel. Refer to TreeItemModel.getItemId(List).

        Parameters:
        itemIds - the keys of expanded rows.
      • getTargetId

        public String getTargetId()
        The target id returned must be unique across all targetable WComponents within the application. In a portal environment, the target ids must also be unique across portlets. Most components should just return their component id.
        Specified by:
        getTargetId in interface Targetable
        Returns:
        the target id for this targetable.
      • getRequestValue

        public Set<String> getRequestValue​(Request request)
        Provide the value of the component on the Request.

        If the component is not on the request, the components current value will be provided.

        Specified by:
        getRequestValue in interface Input
        Parameters:
        request - the request being responded to.
        Returns:
        the value of this component on the Request, or its current state if it is not on the request.
      • getItemImageUrl

        public String getItemImageUrl​(TreeItemImage item,
                                      String itemId)
        Retrieves a URL for the tree item image.

        This method is used by the WTree Renderer.

        Parameters:
        item - the tree item
        itemId - the tree item id
        Returns:
        the URL to access the tree item image.
      • getItemIdPrefix

        public String getItemIdPrefix()
        Returns:
        the prefix to use on the tree item ids
      • clearItemIdMaps

        protected void clearItemIdMaps()
        Clear the item id maps from, the scratch map.
      • getCustomIdNodeMap

        public Map<String,​TreeItemIdNode> getCustomIdNodeMap()
        Map an item id to its node in the custom tree. As this can be expensive save the map onto the scratch pad.
        Returns:
        the map between the custom item ids and their node item.
      • getAllItemIdIndexMap

        public Map<String,​List<Integer>> getAllItemIdIndexMap()
        Map all item idsin the model to their row index. As this can be expensive save the map onto the scratch pad.

        This can be very expensive and should be avoided. This will load all the nodes in a tree (including those already not expanded).

        Returns:
        the map between the all the item ids in the tree model and row indexes
      • getExpandedItemIdIndexMap

        public Map<String,​List<Integer>> getExpandedItemIdIndexMap()
        Map expanded item ids to their row index. As this can be expensive save the map onto the scratch pad.
        Returns:
        the mapping between an item id and its row index. Only expanded items.
      • getRowIndexForCustomItemId

        public List<Integer> getRowIndexForCustomItemId​(String itemId)
        This method is used with a custom tree to map an item id to its row index.

        The default implementation can be expensive as it looks at all the nodes in the tree to find the item id.

        An alternative implementation projects could override to use is if the TreeModel used by the project is using the string version of the row index, override this method to use TreeItemUtil.rowIndexStringToList(java.lang.String).

        Parameters:
        itemId - the item id
        Returns:
        the row index for the item id
      • initialiseComponentModel

        protected void initialiseComponentModel()

        Performs initialisation that is required on this components model, and potentially its children. Subclasses can override.

        Note that the user's component model will automatically be populated from the shared model.

        Overrides:
        initialiseComponentModel in class AbstractWComponent
      • preparePaintComponent

        protected void preparePaintComponent​(Request request)
        Override preparePaint to register an AJAX operation.
        Overrides:
        preparePaintComponent in class AbstractWComponent
        Parameters:
        request - the request being responded to.
      • checkExpandedCustomNodes

        protected void checkExpandedCustomNodes()
        Check if custom nodes that are expanded need their child nodes added from the model.
      • afterPaint

        protected void afterPaint​(RenderContext renderContext)
        Subclasses may override this method to output content after the component has been painted. When overriding this method, it is good practice to call the superclass implementation before emitting any additional content.
        Overrides:
        afterPaint in class AbstractWComponent
        Parameters:
        renderContext - the context to render to.
      • beforeHandleRequest

        protected boolean beforeHandleRequest​(Request request)
        Handle before handle request processing.
        Overrides:
        beforeHandleRequest in class AbstractInput
        Parameters:
        request - the request being responded to.
        Returns:
        true to continue
      • isOpenItemRequest

        protected boolean isOpenItemRequest​(Request request)
        Parameters:
        request - the request being processed
        Returns:
        true if its an open item request
      • isShuffleRequest

        protected boolean isShuffleRequest​(Request request)
        Parameters:
        request - the request being processed
        Returns:
        true if its a shuffle items request
      • hasOpenRequest

        protected boolean hasOpenRequest​(Request request)
        Parameters:
        request - the request being processed
        Returns:
        true if has open request
      • doHandleRequest

        protected boolean doHandleRequest​(Request request)
        Set the inputs based on the incoming request. The text input values are set as an array of strings on the parameter with this name AbstractWComponent.getName(). Any empty strings will be ignored.
        Specified by:
        doHandleRequest in class AbstractInput
        Parameters:
        request - the current request.
        Returns:
        true if the inputs have changed, otherwise return false
      • isPresent

        protected boolean isPresent​(Request request)

        Indicates whether this tree was present in the request.

        Overrides:
        isPresent in class AbstractInput
        Parameters:
        request - the request being responded to.
        Returns:
        true if this tree was present in the request, false if not.
      • getPrevExpandedRows

        protected Set<String> getPrevExpandedRows()
        Return the item ids that have been expanded.

        Note - Only used for when the tree is in LAZY mode

        Returns:
        the previously expanded item ids
      • addPrevExpandedCurrent

        protected void addPrevExpandedCurrent()
        Save the currently open rows.

        Note - Only used for when the tree is in LAZY mode

      • clearPrevExpandedRows

        protected void clearPrevExpandedRows()
        Clear the previously expanded row keys.

        Note - Only used for when the tree is in LAZY mode

      • getOpenRequestItemId

        public String getOpenRequestItemId()
        Returns:
        the item id to open, or null
      • toString

        public String toString()
        Description copied from class: AbstractWComponent
        Creates a String representation of this component; usually for debugging purposes.
        Overrides:
        toString in class AbstractInput
        Returns:
        a String representation of this component, for debugging purposes.
      • getComponentModel

        protected WTree.WTreeComponentModel getComponentModel()
        Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.
        Overrides:
        getComponentModel in class AbstractInput
        Returns:
        the effective component model
      • getOrCreateComponentModel

        protected WTree.WTreeComponentModel getOrCreateComponentModel()
        Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.
        Overrides:
        getOrCreateComponentModel in class AbstractInput
        Returns:
        the model for this component