Class TreeTag

  • All Implemented Interfaces:
    ConditionalTag, ScrollSizeSupport, org.apache.commons.jelly.Tag

    public class TreeTag
    extends InputComponentTag
    implements ScrollSizeSupport

    A tag that creates a tree component.

    With this tag a typical tree view for displaying data organized in a hierarchical manner can be created. Per default a tree view is not directly used for entering data into a form. Often only the selection of a tree is relevant, e.g. for identifying an object to be edited. Therefore the component handler created by this tag (a TreeHandler by the way) is not added to the form per default. This can be changed by setting the noField attribute to false. In this respect this tag works analogously to the tag for creating tables.

    The content of the tree is provided by a model which must be specified to this tag. The JGUIraffe framework uses HierarchicalConfiguration objects as tree models. With the model attribute the name of the model variable can be set. The tag will lookup this variable in the current BeanContext, i.e. the whole power of the dependency injection framework is available for defining the model data.

    The following table lists the attributes supported by the TreeTag tag handler class:

    Attribute Description Optional
    model With this attribute the model of the tree is specified. Here the name of a variable that can be found in the current BeanContext must be provided. This variable must be a HierarchicalConfiguration object. No
    editable This boolean property determines whether the tree is read-only or can be edited. The default value is false. If set to true, the nodes of the tree can be edited, which will also update the tree's model. Yes
    multiSelection This boolean property indicates whether the tree should support multi-selection, i.e. multiple nodes can be selected at the same time. If the attribute is missing, false is the default value. Yes
    rootVisible With this boolean attribute the presentation of the tree's root node can be determined. If set to true (which is the default), the root node is visible. Setting this attribute to false the root node won't be drawn. Yes
    iconHandler Using this attribute a custom TreeIconHandler can be provided. A bean with the name specified here will be looked up in the current bean context. It must implement the TreeIconHandler interface. This bean will then be used for determining the icons to be displayed for the single tree nodes. If this attribute is undefined, a default icon handler will be used. Yes
    scrollWidth Here the preferred width of the scroll pane enclosing the tree can be specified as a number with unit (e.g. "1.5cm"). If specified, the scroll pane will have exactly this preferred width. Otherwise, the width is determined by the preferred width of the tree. yes
    scrollHeight Here the preferred height of the scroll pane enclosing the tree can be specified as a number with unit (e.g. "10dlu"). If specified, the scroll pane will have exactly this preferred height. Otherwise, the height is determined by the preferred height of the tree. yes

    With TreeIconTag tags placed in the body of this tag the icons displayed by the tree for its nodes can be specified. You can either override the default icons for leaf and (expanded or collapsed) branch nodes or specify a custom TreeIconHandler object using the iconHandler attribute that is responsible for drawing the icons.

    Version:
    $Id: TreeTag.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Field Detail

      • ICON_BRANCH_EXPANDED

        public static final String ICON_BRANCH_EXPANDED
        Constant for the name of the default icon used for expanded branch nodes.
        See Also:
        Constant Field Values
      • ICON_BRANCH_COLLAPSED

        public static final String ICON_BRANCH_COLLAPSED
        Constant for the name of the default icon used for collapsed branch nodes.
        See Also:
        Constant Field Values
      • ICON_LEAF

        public static final String ICON_LEAF
        Constant for the name of the default icon used for leaf nodes.
        See Also:
        Constant Field Values
    • Constructor Detail

      • TreeTag

        public TreeTag()
        Creates a new instance of TreeTag.
    • Method Detail

      • getTreeModel

        public org.apache.commons.configuration.HierarchicalConfiguration getTreeModel()
        Returns the configuration used as tree model.
        Returns:
        the model of the tree
      • setTreeModel

        public void setTreeModel​(org.apache.commons.configuration.HierarchicalConfiguration treeModel)
        Sets the configuration used as tree model. Per default the model will be obtained from the current bean context; its name is determined using the model attribute.
        Parameters:
        treeModel - the configuration to be used as tree model
      • getModel

        public String getModel()
        Returns the name of the variable that serves as tree model.
        Returns:
        the name of the tree model variable
      • setModel

        public void setModel​(String model)
        Sets the name of the variable that serves as tree model.
        Parameters:
        model - the name of the tree model variable
      • isEditable

        public boolean isEditable()
        Returns the editable flag. This flag determines whether the tree supports updating the model.
        Returns:
        the editable flag
      • setEditable

        public void setEditable​(boolean editable)
        Set method of the editable attribute.
        Parameters:
        editable - the value of the attribute
      • isMultiSelection

        public boolean isMultiSelection()
        Returns the multiple selection flag. If set to true, multiple nodes can be selected concurrently.
        Returns:
        the multiple selection flag
      • setMultiSelection

        public void setMultiSelection​(boolean multiSelection)
        Set method for the multiSelection attribute.
        Parameters:
        multiSelection - the attribute value
      • isRootVisible

        public boolean isRootVisible()
        Returns the value of the rootVisible flag. This flag determines whether the root node of the tree is displayed.
        Returns:
        a flag whether the root node is visible
      • setRootVisible

        public void setRootVisible​(boolean rootVisible)
        Set method of the rootVisible attribute.
        Parameters:
        rootVisible - the value of the attribute
      • getIconHandler

        public String getIconHandler()
        Returns the name of the bean to be used as icon handler for this tree.
        Returns:
        the name of the icon handler bean
      • setIconHandler

        public void setIconHandler​(String iconHandler)
        Set method of the iconHandler attribute.
        Parameters:
        iconHandler - the value of the attribute
      • getPreferredScrollWidth

        public NumberWithUnit getPreferredScrollWidth()
        Returns the preferred scroll width. This value is calculated based on the scrollWidth attribute during tag processing. If no preferred scroll width is specified, an object with the value 0 is returned.
        Specified by:
        getPreferredScrollWidth in interface ScrollSizeSupport
        Returns:
        the preferred scroll width
      • getPreferredScrollHeight

        public NumberWithUnit getPreferredScrollHeight()
        Returns the preferred scroll height. This value is calculated based on the scrollHeight attribute during tag processing. If no preferred scroll height is specified, an object with the value 0 is returned.
        Specified by:
        getPreferredScrollHeight in interface ScrollSizeSupport
        Returns:
        the preferred scroll height
      • setScrollWidth

        public void setScrollWidth​(String scrollWidth)
        Set method of the scrollWidth attribute.
        Parameters:
        scrollWidth - the attribute's value
      • setScrollHeight

        public void setScrollHeight​(String scrollHeight)
        Set method of the scrollHeight attribute.
        Parameters:
        scrollHeight - the attribute's value
      • addIcon

        public void addIcon​(String name,
                            Object icon)
        Adds an icon to this tree. The icon is given a unique name, under which it can be accessed by the tree's TreeIconHandler. The default icon handler (which will be used when no custom handler is specified using the iconHandler attribute) uses the following names for icons: By adding icons with these names the default icons of the tree can be changed. However, if a custom icon handler is used, it is up to this object which icons it supports.
        Parameters:
        name - the name of the icon (must not be null)
        icon - the icon (must not be null)
        Throws:
        IllegalArgumentException - if a required parameter is missing
      • getIcons

        public Map<String,​Object> getIcons()
        Returns a map with the icons defined for this tree. This map will be used for actually rendering the icons for the single nodes. The TreeIconHandler is queried for the name of the icon for the current node. Then this map is consulted for retrieving the corresponding icon. If no icon is found for the name returned by the icon handler, the default icon for this node will be displayed.
        Returns:
        a map with the icons defined for this tree
      • getResolvedIconHandler

        public TreeIconHandler getResolvedIconHandler()
        Returns the TeeIconHandler to be used with this tree. If an icon handler was specified using the iconHandler attribute, it is resolved from the current bean context. Otherwise a default icon handler will be returned that uses the standard icons of the current platform. So the return value is never null.
        Returns:
        the TreeIconHandler for this tree
        See Also:
        addIcon(String, Object)
      • processBeforeBody

        protected void processBeforeBody()
                                  throws org.apache.commons.jelly.JellyTagException,
                                         FormBuilderException
        Performs pre-processing before the body of this tag is executed. This implementation tries to resolve the icon handler if one is specified.
        Overrides:
        processBeforeBody in class InputComponentTag
        Throws:
        FormBuilderException - if an error occurs
        org.apache.commons.jelly.JellyTagException - if the tag is incorrectly used
        InjectionException - if a bean cannot be resolved
      • createComponentHandler

        protected ComponentHandler<?> createComponentHandler​(ComponentManager manager,
                                                             boolean create)
                                                      throws FormBuilderException,
                                                             org.apache.commons.jelly.JellyTagException
        Creates the component handler for the tree component. This implementation will check whether a tree model is defined and obtain it from the bean context if necessary. Then it will delegate to the ComponentManager for actually creating the component.
        Specified by:
        createComponentHandler in class InputComponentTag
        Parameters:
        manager - the component manager
        create - the create flag
        Returns:
        the component handler for the newly created component
        Throws:
        FormBuilderException - if an error occurs
        org.apache.commons.jelly.JellyTagException - if the tag is used incorrectly
        InjectionException - if the model bean cannot be resolved
      • resolveIconHandler

        protected TreeIconHandler resolveIconHandler​(String name)
        Resolves the TreeIconHandler bean. This method is called if the iconHandler attribute is specified. It obtains the bean with the given name from the current bean context.
        Parameters:
        name - the name of the icon handler bean
        Returns:
        the icon handler bean
      • createDefaultIconHandler

        protected TreeIconHandler createDefaultIconHandler()
        Returns a default TreeIconHandler object. This method is called by code>processBeforeBody() if no custom icon handler is specified. It returns a default implementation that uses the default icons of the current platform.
        Returns:
        a default icon handler