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 class
WTree.ExpandMode
This is used to control how row expansion should work.static class
WTree.SelectMode
This is used to control how row selection should work.static class
WTree.Type
This is used to indicate the type of tree.static class
WTree.WTreeComponentModel
Contains 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 void
addPrevExpandedCurrent()
Save the currently open rows.protected void
afterPaint(RenderContext renderContext)
Subclasses may override this method to output content after the component has been painted.protected boolean
beforeHandleRequest(Request request)
Handle before handle request processing.protected void
checkExpandedCustomNodes()
Check if custom nodes that are expanded need their child nodes added from the model.protected void
clearItemIdMaps()
Clear the item id maps from, the scratch map.protected void
clearPrevExpandedRows()
Clear the previously expanded row keys.protected boolean
doHandleRequest(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.WTreeComponentModel
getComponentModel()
Returns the effective component model for this component.Map<String,TreeItemIdNode>
getCustomIdNodeMap()
Map an item id to its node in the custom tree.TreeItemIdNode
getCustomTree()
Map<String,List<Integer>>
getExpandedItemIdIndexMap()
Map expanded item ids to their row index.Set<String>
getExpandedRows()
Retrieve the row keys that are expanded.WTree.ExpandMode
getExpandMode()
String
getItemIdPrefix()
String
getItemImageUrl(TreeItemImage item, String itemId)
Retrieves a URL for the tree item image.Margin
getMargin()
Get the margin for the component, or null if not set.Action
getOpenAction()
The action when a request to open a tree item is received.String
getOpenRequestItemId()
protected WTree.WTreeComponentModel
getOrCreateComponentModel()
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.SelectMode
getSelectMode()
Action
getShuffleAction()
The action used when the tree items are shuffled on the client.String
getTargetId()
The target id returned must be unique across all targetable WComponents within the application.TreeItemModel
getTreeModel()
WTree.Type
getType()
Set<String>
getValue()
Returns aSet
of the selected options.String
getValueAsString()
Returns a string value of the selected item for this users session.protected boolean
hasOpenRequest(Request request)
protected void
initialiseComponentModel()
Performs initialisation that is required on this components model, and potentially its children.boolean
isEmpty()
Indicates whether this input field is empty.protected boolean
isOpenItemRequest(Request request)
protected boolean
isPresent(Request request)
Indicates whether this tree was present in the request.boolean
isShuffle()
protected boolean
isShuffleRequest(Request request)
protected WTree.WTreeComponentModel
newComponentModel()
Creates a new component model.protected void
preparePaintComponent(Request request)
Override preparePaint to register an AJAX operation.void
setCustomTree(TreeItemIdNode customTree)
Set a custom view of the tree nodes.void
setCustomTree(String json)
void
setExpandedRows(Set<String> itemIds)
Set the row keys that are expanded.void
setExpandMode(WTree.ExpandMode expandMode)
Sets the row expansion mode.void
setMargin(Margin margin)
Set the margin for the component, or null for no margin.void
setOpenAction(Action action)
The action when a request to open a tree item is received.void
setSelectedRows(Set<String> itemIds)
Set the row keys that are selected.void
setSelectMode(WTree.SelectMode selectMode)
Sets the row selection mode.void
setShuffle(boolean shuffle)
void
setShuffleAction(Action action)
The action used when the tree items are shuffled on the client.void
setTreeModel(TreeItemModel treeModel)
Sets the tree model which provides row data.void
setType(WTree.Type type)
String
toString()
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 aSet
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 aList
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 interfaceInput
- Overrides:
getValue
in 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:
getValueAsString
in interfaceInput
- Overrides:
getValueAsString
in classAbstractInput
- 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 interfaceInput
- Overrides:
isEmpty
in 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:
getMargin
in 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:
setMargin
in 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:
getTargetId
in 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:
getRequestValue
in 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:
initialiseComponentModel
in classAbstractWComponent
-
preparePaintComponent
protected void preparePaintComponent(Request request)
Override preparePaint to register an AJAX operation.- Overrides:
preparePaintComponent
in 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:
afterPaint
in classAbstractWComponent
- Parameters:
renderContext
- the context to render to.
-
beforeHandleRequest
protected boolean beforeHandleRequest(Request request)
Handle before handle request processing.- Overrides:
beforeHandleRequest
in 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:
doHandleRequest
in 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:
isPresent
in 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:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractInput
- Returns:
- a String representation of this component, for debugging purposes.
-
newComponentModel
protected WTree.WTreeComponentModel newComponentModel()
Creates a new component model.- Overrides:
newComponentModel
in 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:
getComponentModel
in 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:
getOrCreateComponentModel
in classAbstractInput
- Returns:
- the model for this component
-
-