Class TreeTag
- java.lang.Object
-
- org.apache.commons.jelly.TagSupport
-
- net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
-
- net.sf.jguiraffe.gui.builder.components.tags.InputComponentTag
-
- net.sf.jguiraffe.gui.builder.components.tags.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
TreeHandlerby the way) is not added to the form per default. This can be changed by setting thenoFieldattribute 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
HierarchicalConfigurationobjects as tree models. With themodelattribute the name of the model variable can be set. The tag will lookup this variable in the currentBeanContext, 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
TreeTagtag 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 BeanContextmust be provided. This variable must be aHierarchicalConfigurationobject.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 TreeIconHandlercan be provided. A bean with the name specified here will be looked up in the current bean context. It must implement theTreeIconHandlerinterface. 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
TreeIconTagtags 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 customTreeIconHandlerobject using theiconHandlerattribute that is responsible for drawing the icons.- Version:
- $Id: TreeTag.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Field Summary
Fields Modifier and Type Field Description static StringICON_BRANCH_COLLAPSEDConstant for the name of the default icon used for collapsed branch nodes.static StringICON_BRANCH_EXPANDEDConstant for the name of the default icon used for expanded branch nodes.static StringICON_LEAFConstant for the name of the default icon used for leaf nodes.
-
Constructor Summary
Constructors Constructor Description TreeTag()Creates a new instance ofTreeTag.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddIcon(String name, Object icon)Adds an icon to this tree.protected ComponentHandler<?>createComponentHandler(ComponentManager manager, boolean create)Creates the component handler for the tree component.protected TreeIconHandlercreateDefaultIconHandler()Returns a defaultTreeIconHandlerobject.StringgetIconHandler()Returns the name of the bean to be used as icon handler for this tree.Map<String,Object>getIcons()Returns a map with the icons defined for this tree.StringgetModel()Returns the name of the variable that serves as tree model.NumberWithUnitgetPreferredScrollHeight()Returns the preferred scroll height.NumberWithUnitgetPreferredScrollWidth()Returns the preferred scroll width.TreeIconHandlergetResolvedIconHandler()Returns theTeeIconHandlerto be used with this tree.org.apache.commons.configuration.HierarchicalConfigurationgetTreeModel()Returns the configuration used as tree model.booleanisEditable()Returns the editable flag.booleanisMultiSelection()Returns the multiple selection flag.booleanisRootVisible()Returns the value of the rootVisible flag.protected voidprocessBeforeBody()Performs pre-processing before the body of this tag is executed.protected TreeIconHandlerresolveIconHandler(String name)Resolves theTreeIconHandlerbean.voidsetEditable(boolean editable)Set method of the editable attribute.voidsetIconHandler(String iconHandler)Set method of the iconHandler attribute.voidsetModel(String model)Sets the name of the variable that serves as tree model.voidsetMultiSelection(boolean multiSelection)Set method for the multiSelection attribute.voidsetRootVisible(boolean rootVisible)Set method of the rootVisible attribute.voidsetScrollHeight(String scrollHeight)Set method of thescrollHeightattribute.voidsetScrollWidth(String scrollWidth)Set method of thescrollWidthattribute.voidsetTreeModel(org.apache.commons.configuration.HierarchicalConfiguration treeModel)Sets the configuration used as tree model.-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.InputComponentTag
addToGroups, checkName, createFieldHandler, getComponent, getComponentHandler, getComponentType, getDisplayName, getFieldValidator, getFormValidator, getGroups, getPropertyName, getReadTransformer, getTypeName, getWriteTransformer, handleGroups, insertField, isNoField, process, setComponentType, setDisplayName, setDisplayNamegrp, setDisplayNameres, setFieldValidator, setFormValidator, setGroups, setNoField, setPropertyName, setReadTransformer, setTypeName, setWriteTransformer
-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.ComponentBaseTag
getBackColor, getBackgroundColor, getConstraints, getFont, getFontRef, getForeColor, getForegroundColor, getName, getToolTipData, insertComponent, setBackColor, setConstraints, setFont, setFontRef, setForeColor, setName, setTooltip, setTooltipres, setTooltipresgrp
-
Methods inherited from class net.sf.jguiraffe.gui.builder.components.tags.FormBaseTag
canProcess, canProcess, convertToClass, convertToNumberWithUnit, convertToNumberWithUnit, doTag, findContainer, getBuilderData, getBuilderData, getIfName, getResourceText, getResourceText, getUnlessName, setIfName, setUnlessName
-
Methods inherited from class org.apache.commons.jelly.TagSupport
findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, findAncestorWithClass, getBody, getBodyText, getBodyText, getContext, getParent, invokeBody, isEscapeText, isTrim, setBody, setContext, setEscapeText, setParent, setTrim, trimBody
-
-
-
-
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
-
-
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 themodelattribute.- 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 thescrollWidthattribute during tag processing. If no preferred scroll width is specified, an object with the value 0 is returned.- Specified by:
getPreferredScrollWidthin interfaceScrollSizeSupport- Returns:
- the preferred scroll width
-
getPreferredScrollHeight
public NumberWithUnit getPreferredScrollHeight()
Returns the preferred scroll height. This value is calculated based on thescrollHeightattribute during tag processing. If no preferred scroll height is specified, an object with the value 0 is returned.- Specified by:
getPreferredScrollHeightin interfaceScrollSizeSupport- Returns:
- the preferred scroll height
-
setScrollWidth
public void setScrollWidth(String scrollWidth)
Set method of thescrollWidthattribute.- Parameters:
scrollWidth- the attribute's value
-
setScrollHeight
public void setScrollHeight(String scrollHeight)
Set method of thescrollHeightattribute.- 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. The default icon handler (which will be used when no custom handler is specified using theTreeIconHandlericonHandlerattribute) uses the following names for icons:- "BRANCH_EXPANDED" for expanded branch nodes
- "BRANCH_COLLAPSED" for collapsed branch nodes and
- "LEAF" for leaf nodes
- 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. Theis 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.TreeIconHandler- Returns:
- a map with the icons defined for this tree
-
getResolvedIconHandler
public TreeIconHandler getResolvedIconHandler()
Returns theTeeIconHandlerto be used with this tree. If an icon handler was specified using theiconHandlerattribute, 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
TreeIconHandlerfor this tree - See Also:
addIcon(String, Object)
-
processBeforeBody
protected void processBeforeBody() throws org.apache.commons.jelly.JellyTagException, FormBuilderExceptionPerforms pre-processing before the body of this tag is executed. This implementation tries to resolve the icon handler if one is specified.- Overrides:
processBeforeBodyin classInputComponentTag- Throws:
FormBuilderException- if an error occursorg.apache.commons.jelly.JellyTagException- if the tag is incorrectly usedInjectionException- 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 theComponentManagerfor actually creating the component.- Specified by:
createComponentHandlerin classInputComponentTag- Parameters:
manager- the component managercreate- the create flag- Returns:
- the component handler for the newly created component
- Throws:
FormBuilderException- if an error occursorg.apache.commons.jelly.JellyTagException- if the tag is used incorrectlyInjectionException- if the model bean cannot be resolved
-
resolveIconHandler
protected TreeIconHandler resolveIconHandler(String name)
Resolves theTreeIconHandlerbean. This method is called if theiconHandlerattribute 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 defaultTreeIconHandlerobject. 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
-
-