Class WTree
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.AbstractInput
-
- com.github.bordertech.wcomponents.WTree
-
- All Implemented Interfaces:
AjaxInternalTrigger,AjaxTarget,AjaxTrigger,BeanAware,BeanBound,BeanProviderBound,DataBound,Diagnosable,Disableable,Input,Labelable,Mandatable,Marginable,SubordinateTarget,SubordinateTrigger,Targetable,WComponent,WebComponent,Serializable
public class WTree extends AbstractInput implements AjaxInternalTrigger, AjaxTarget, AjaxTrigger, SubordinateTrigger, SubordinateTarget, Marginable, Targetable
WTree represents a tree view selection control.- Since:
- 1.1.0
- Author:
- Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWTree.ExpandModeThis is used to control how row expansion should work.static classWTree.SelectModeThis is used to control how row selection should work.static classWTree.TypeThis is used to indicate the type of tree.static classWTree.WTreeComponentModelContains the tree's UI state.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractInput
AbstractInput.InputModel
-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Constructor Summary
Constructors Constructor Description WTree()Construct the WTree.WTree(WTree.Type type)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddPrevExpandedCurrent()Save the currently open rows.protected voidafterPaint(RenderContext renderContext)Subclasses may override this method to output content after the component has been painted.protected booleanbeforeHandleRequest(Request request)Handle before handle request processing.protected voidcheckExpandedCustomNodes()Check if custom nodes that are expanded need their child nodes added from the model.protected voidclearItemIdMaps()Clear the item id maps from, the scratch map.protected voidclearPrevExpandedRows()Clear the previously expanded row keys.protected booleandoHandleRequest(Request request)Set the inputs based on the incoming request.Map<String,List<Integer>>getAllItemIdIndexMap()Map all item idsin the model to their row index.protected WTree.WTreeComponentModelgetComponentModel()Returns the effective component model for this component.Map<String,TreeItemIdNode>getCustomIdNodeMap()Map an item id to its node in the custom tree.TreeItemIdNodegetCustomTree()Map<String,List<Integer>>getExpandedItemIdIndexMap()Map expanded item ids to their row index.Set<String>getExpandedRows()Retrieve the row keys that are expanded.WTree.ExpandModegetExpandMode()StringgetItemIdPrefix()StringgetItemImageUrl(TreeItemImage item, String itemId)Retrieves a URL for the tree item image.MargingetMargin()Get the margin for the component, or null if not set.ActiongetOpenAction()The action when a request to open a tree item is received.StringgetOpenRequestItemId()protected WTree.WTreeComponentModelgetOrCreateComponentModel()Retrieves the model for this component so that it can be modified.protected Set<String>getPrevExpandedRows()Return the item ids that have been expanded.Set<String>getRequestValue(Request request)Provide the value of the component on the Request.List<Integer>getRowIndexForCustomItemId(String itemId)This method is used with a custom tree to map an item id to its row index.Set<String>getSelectedRows()Retrieve the row keys that are selected.WTree.SelectModegetSelectMode()ActiongetShuffleAction()The action used when the tree items are shuffled on the client.StringgetTargetId()The target id returned must be unique across all targetable WComponents within the application.TreeItemModelgetTreeModel()WTree.TypegetType()Set<String>getValue()Returns aSetof the selected options.StringgetValueAsString()Returns a string value of the selected item for this users session.protected booleanhasOpenRequest(Request request)protected voidinitialiseComponentModel()Performs initialisation that is required on this components model, and potentially its children.booleanisEmpty()Indicates whether this input field is empty.protected booleanisOpenItemRequest(Request request)protected booleanisPresent(Request request)Indicates whether this tree was present in the request.booleanisShuffle()protected booleanisShuffleRequest(Request request)protected WTree.WTreeComponentModelnewComponentModel()Creates a new component model.protected voidpreparePaintComponent(Request request)Override preparePaint to register an AJAX operation.voidsetCustomTree(TreeItemIdNode customTree)Set a custom view of the tree nodes.voidsetCustomTree(String json)voidsetExpandedRows(Set<String> itemIds)Set the row keys that are expanded.voidsetExpandMode(WTree.ExpandMode expandMode)Sets the row expansion mode.voidsetMargin(Margin margin)Set the margin for the component, or null for no margin.voidsetOpenAction(Action action)The action when a request to open a tree item is received.voidsetSelectedRows(Set<String> itemIds)Set the row keys that are selected.voidsetSelectMode(WTree.SelectMode selectMode)Sets the row selection mode.voidsetShuffle(boolean shuffle)voidsetShuffleAction(Action action)The action used when the tree items are shuffled on the client.voidsetTreeModel(TreeItemModel treeModel)Sets the tree model which provides row data.voidsetType(WTree.Type type)StringtoString()Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractInput
addValidator, createMandatoryDiagnostic, doHandleChanged, getActionCommand, getActionObject, getActionOnChange, getDefaultSubmitButton, getDiagnostics, getValidators, handleRequest, isChangedInLastRequest, isCurrentAjaxTrigger, isDisabled, isMandatory, isReadOnly, setActionObject, setActionOnChange, setChangedInLastRequest, setDefaultSubmitButton, setDisabled, setMandatory, setMandatory, setReadOnly, showErrorIndicatorsForComponent, showIndicatorsForComponent, showWarningIndicatorsForComponent, validateComponent
-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContext, tidyUpUIContextForTree, validate, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanAware
getBean, getBeanProperty, getBeanValue, setBeanProperty
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanBound
isSearchAncestors, setBean
-
Methods inherited from interface com.github.bordertech.wcomponents.BeanProviderBound
getBeanId, setBeanId, setBeanProvider
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, handleRequest, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
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 aSetof 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 aListof 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:
getValuein interfaceInput- Overrides:
getValuein classAbstractInput- 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:
getValueAsStringin interfaceInput- Overrides:
getValueAsStringin classAbstractInput- Returns:
- the selected item value as a rendered String
-
isEmpty
public boolean isEmpty()
Description copied from class:AbstractInputIndicates whether this input field is empty. An input is considered empty if the value is null or an empty String.- Specified by:
isEmptyin interfaceInput- Overrides:
isEmptyin classAbstractInput- 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:
getMarginin interfaceMarginable- 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:
setMarginin interfaceMarginable- 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.
-
getSelectedRows
public Set<String> getSelectedRows()
Retrieve the row keys that are selected.A row key uniquely identifies each row and is determined by the
TreeItemModel. Refer toTreeItemModel.getItemId(List).- Returns:
- the selected row keys.
-
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 toTreeItemModel.getItemId(List).- Parameters:
itemIds- the keys of selected rows.
-
getExpandedRows
public Set<String> getExpandedRows()
Retrieve the row keys that are expanded.A row key uniquely identifies each row and is determined by the
TreeItemModel. Refer toTreeItemModel.getItemId(List).- Returns:
- the expanded row keys.
-
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 toTreeItemModel.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:
getTargetIdin interfaceTargetable- 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:
getRequestValuein interfaceInput- 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 itemitemId- 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:
initialiseComponentModelin classAbstractWComponent
-
preparePaintComponent
protected void preparePaintComponent(Request request)
Override preparePaint to register an AJAX operation.- Overrides:
preparePaintComponentin classAbstractWComponent- 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:
afterPaintin classAbstractWComponent- Parameters:
renderContext- the context to render to.
-
beforeHandleRequest
protected boolean beforeHandleRequest(Request request)
Handle before handle request processing.- Overrides:
beforeHandleRequestin classAbstractInput- 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 nameAbstractWComponent.getName(). Any empty strings will be ignored.- Specified by:
doHandleRequestin classAbstractInput- 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:
isPresentin classAbstractInput- 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:AbstractWComponentCreates a String representation of this component; usually for debugging purposes.- Overrides:
toStringin classAbstractInput- Returns:
- a String representation of this component, for debugging purposes.
-
newComponentModel
protected WTree.WTreeComponentModel newComponentModel()
Creates a new component model.- Overrides:
newComponentModelin classAbstractInput- Returns:
- a new WTreeComponentModel.
-
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:
getComponentModelin classAbstractInput- 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:
getOrCreateComponentModelin classAbstractInput- Returns:
- the model for this component
-
-