Interface ITree
- All Superinterfaces:
IAnyGroup<ITree>,IComponent<ITree>,IComposite<ITree,,IMeshComposite> IHtmlBasedComponent<ITree>,IMeshElement<ITree>,IXulElement<ITree>
Tree component.
A tree consists of three parts, the set of columns, the set of footers,
and the tree body. The set of columns is defined by a number of ITreecol
components, one for each column. Each column will appear as a header at the top
of the tree. The second part, the set of footers is defined by a number of
ITreefooter components, one for each column also.
Each column will appear as a footer at the bottom of the tree.
The third part, the tree body, contains the data to appear in the tree and
is created with a ITreechildren component.
Although ITreecols is optional, if it exists, notice that
the number of its child (ITreecol) should equal the number of ITreecell,
so that tree can display its content correctly. If ITreecols contains
no ITreecol, the tree will display nothing in its content.
Support @Action
| Name | Action Type |
|---|---|
| onSelect | ActionData: SelectData
Notifies one that the user has selected a new item in the tree. |
| onFocus | Denotes when a component gets the focus. Remember event listeners
execute at the server, so the focus at the client might be changed when
the event listener for onFocus got executed. |
| onBlur | Denotes when a component loses the focus. Remember event listeners
execute at the server, so the focus at the client might be changed
when the event listener for onBlur got executed. |
| onPageSize | ActionData: PageSizeData
Notifies the paging size has been changed when the autopaging ( iTree.withAutopaging(boolean)) is enabled and a user changed
the size of the content. |
Support Molds
| Name | Snapshot |
|---|---|
"default" |
![]() |
"paging" |
![]() |
Support Application Library Properties
-
To turn on the auto-sort facility to sort the model for this component, you have to specify
withAutosort(Autosort)toITree.Autosort.ENABLEorITree.Autosort.IGNORE_CHANGE.Or configure it from zk.xml by setting library properties. For example,
<library-property/> <name>org.zkoss.zul.tree.autoSort</name/> <value>true</value/> </library-property/> -
To set to prefer to deselect all other items and select the item being clicked when
isCheckmark()is enabled, you have to specifywithCheckmarkDeselectOther(boolean)totrue.Or configure it from zk.xml by setting library properties. For example,
<library-property/> <name>org.zkoss.zul.tree.checkmarkDeselectOthers</name/> <value>true</value/> </library-property/> -
To set whether to disable select functionality when highlighting text content with mouse dragging or not, you have to specify
withSelectOnHighlightDisabled(boolean)totrue.Or configure it from zk.xml by setting library properties. For example,
<library-property/> <name>org.zkoss.zul.tree.selectOnHighlight.disabled</name/> <value>true</value/> </library-property/> -
To set whether to disable the selection will be toggled when the user right clicks item, only if
isCheckmark()is enabled. You have to specifywithRightSelect(boolean)tofalse.Or configure it from zk.xml by setting library properties. For example,
<library-property/> <name>org.zkoss.zul.tree.rightSelect</name/> <value>false</value/> </library-property/> -
To set the millisecond of scrolling throttling in Tree render on-demand (ROD), you have to specify
withThrottleMillis(int)(ZK EE only).Or configure it from zk.xml by setting library properties. For example,
<library-property/> <name>org.zkoss.zul.tree.throttleMillis</name/> <value>300</value/> </library-property/>
Example
2-Column Tree
@RichletMapping("")
public IComponent index() {
return IWindow.ofTitle("tree demo").withBorder("normal").withWidth("500px")
.withChildren(
ITree.ofId("tree").withRows(5).withTreecols(
ITreecols.of(
ITreecol.of("Name"),
ITreecol.of("Description")
)).withTreechildren(ITreechildren.of(
ITreeitem.ofTreecells(
ITreecell.of("Item 1"),
ITreecell.of("Item 1 description")
),
ITreeitem.ofTreecells(
ITreecell.of("Item 2"),
ITreecell.of("Item 2 description"))
.withTreechildren(
ITreechildren.of(
ITreeitem.of("Item 2.1"),
ITreeitem.ofTreecells(
ITreecell.of("Item 2.2"),
ITreecell.of("Item 2.2 is something who cares")),
ITreeitem.of("Item 3")))))
.withTreefoot(
ITreefoot.of(
ITreefooter.of("Count"),
ITreefooter.of("Summary")
)
)
);
}
Default Selection
@RichletMapping("/defaultSelection")
public IComponent defaultSelection() {
return ITree.of(
ITreeitem.of("David"),
ITreeitem.of("Thomas"),
ITreeitem.of("Steven").withSelected(true)
).withWidth("300px");
}
Frozen Component
@RichletMapping("/frozen")
public IComponent frozen() {
return ITree.ofId("tree").withRows(5).withWidth("600px").withFrozen(
IFrozen.ofColumns(2).withStart(1)
).withTreecols(
ITreecols.of(
ITreecol.of("ID").withHflex("min"),
ITreecol.of("Priority").withHflex("min"),
ITreecol.of("Status").withHflex("min"),
ITreecol.of("Summary").withHflex("min"),
ITreecol.of("Detail").withHflex("min")
).withSizable(true)
).withTreechildren(
ITreechildren.of(
ITreeitem.ofTreecells(
ITreecell.of("0001"),
ITreecell.of("1"),
ITreecell.of("closed"),
ITreecell.of("Fix login issue"),
ITreecell.of("Login does not work at all")
),
ITreeitem.ofTreecells(
ITreecell.of("0002"),
ITreecell.of("3"),
ITreecell.of("open"),
ITreecell.of("Button style broken"),
ITreecell.of("Check main.css")
).withTreechildren(
ITreechildren.of(
ITreeitem.ofTreecells(
ITreecell.of("00021"),
ITreecell.of("1"),
ITreecell.of("closed"),
ITreecell.of("Fix logout issue"),
ITreecell.of("Logout does not work at all")
)
)
),
ITreeitem.ofTreecells(
ITreecell.of("0003"),
ITreecell.of("2"),
ITreecell.of("open"),
ITreecell.of("Client search result"),
ITreecell.of("Search service returns incomplete result")
)
)
);
}
Scrollable Tree
A tree will be scrollable if you specify the rows attribute or the height attribute and there is not enough space to display all the tree items.
@RichletMapping("/scrollable")
public IComponent scrollable() {
return ITree.DEFAULT.withRows(4).withTreecols(
ITreecols.of(
ITreecol.of("Name"),
ITreecol.of("Description")
)
).withTreechildren(
ITreechildren.of(
ITreeitem.ofTreecells(
ITreecell.of("Item 1"),
ITreecell.of("Item 1 description")
),
ITreeitem.ofTreecells(
ITreecell.of("Item 2"),
ITreecell.of("Item 2 description")
).withTreechildren(
ITreechildren.of(
ITreeitem.of("Item 2.1",
ITreeitem.of("Item 2.1.1"),
ITreeitem.of("Item 2.1.2")
),
ITreeitem.ofTreecells(
ITreecell.of("Item 2.2"),
ITreecell.of("Item 2.2 is something who cares")
)
)
),
ITreeitem.of("Item 3")
)
);
}
Create-on-Open for Tree Controls
As illustrated below, you could listen to the onOpen event, and then
load the children of a tree item. You can do the same thing using group boxes.
@RichletMapping("/createOnOpen")
public IComponent createOnOpen() {
return ITree.DEFAULT.withWidth("400px")
.withTreecols(
ITreecols.of(
ITreecol.of("Subject"),
ITreecol.of("From")
)
).withTreechildren(
ITreechildren.of(
ITreeitem.ofTreecells(
ITreecell.of("Intel Snares XML"),
ITreecell.of("David Needle")
).withTreechildren(
ITreechildren.DEFAULT
).withOpen(false).withAction(this::doCreateOnOpen)
)
);
}
@Action(type = Events.ON_OPEN)
public void doCreateOnOpen(Self self, @ActionVariable(targetId = ActionTarget.SELF, field = "empty") boolean isEmpty) {
if (isEmpty) {
UiAgent.getCurrent()
.replaceChildren(self.findChild(ITreechildren.class),
ITreeitem.of("New added"));
}
}
As you can see above, the field "empty" of the ActionVariable
is used to detect whether the treeitem has an empty children, which receives the
returned result from ITreeitem.isEmpty() at client widget.
Mouse-less Entry Tree
- Press UP and DOWN to move the selection up and down by one tree item.
- Press PgUp and PgDn to move the selection up and down by one page.
- Press HOME to move the selection to the first item, and END to the last item.
- Press RIGHT to open a tree item, and LEFT to close a tree item.
- Press Ctrl+UP and Ctrl+DOWN to move the focus up and down by one tree item without changing the selection.
- Press SPACE to select the item in focus
- Author:
- jumperchen
- See Also:
-
Tree
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumSpecifies whether to sort the model when the following cases: WithTreeModelcase andITreecol.withSortDirection(String)is set.ITreecol.withSortDirection(String)is called. Model receivesTreeDataEventandITreecol.withSortDirection(String)is set. If you want to ignore sorting when receiving TreeDataEvent, you can specify the value asITree.Autosort.IGNORE_CHANGE.static classBuilds instances of typeITree.static classBuilds an updater of typeITreeforUiAgent.smartUpdate(Locator, SmartUpdater).Nested classes/interfaces inherited from interface org.zkoss.stateless.sul.IMeshElement
IMeshElement.PagingPosition -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptiondefault StringReturns whether to sort all items when model or sort direction be changed.Returns theIAuxheadcomponent, if any.Returns aIFrozencomponent to enable a frozen column or row facility.default Collection<ITreeitem>getItems()Returns a readonly list of all descendingITreeitem(children's children and so on).Returns a list of HTML tag names that shall not cause the tree item being selected if they are clicked.default intgetRows()Returns the number of the rows to display at screen.default intReturns the millisecond of scrolling throttling in Tree render on-demand (ROD).Returns the rootITreechildren, which contains all tree items in a hierarchical set of rows of components.Returns theITreecolscomponent, if any.Returns theITreefootcomponent, if any.default StringReturns the client widget class.default booleanReturns whether the check mark shall be displayed in front of each item.default booleanReturns whether to toggle the selection if clicking on a tree item with a checkmark.default booleanReturns whether multiple selections are allowed.default booleanReturns whether to toggle a list item selection on right click, only ifisCheckmark()is enabled.default booleanReturns whether to disable select functionality when highlighting text content with mouse dragging or not.static ITreeReturns the instance with the given tree items which belong to root level.static ITreeReturns the instance with the given tree items which belong to root level.static ITreeReturns the instance with the given id.static ITreeofTreecols(Iterable<? extends ITreecol<IAnyGroup>> children) Returns the instance with the given tree columns.static ITreeofTreecols(ITreecol<IAnyGroup>... children) Returns the instance with the given tree columns.static ITreeofTreecols(ITreecols treecols) Returns the instance with the given tree columns.static ITreeofTreefoot(ITreefoot treefoot) Returns the instance with the given tree foot.static ITreeofTreefooters(Iterable<? extends ITreefooter<IAnyGroup>> children) Returns the instance with the given tree footers.static ITreeofTreefooters(ITreefooter<IAnyGroup>... children) Returns the instance with the given tree footers.default ITreewithAllComponents(Iterable<? extends IMeshComposite> elements) Copy the current immutable object with elements that replace the content ofchildren.withAutosort(String autosort) Returns a copy ofthisimmutable component with the specifiedautosort.default ITreewithAutosort(ITree.Autosort autosort) Returns a copy ofthisimmutable component with the specifiedautosort.withAuxhead(Iterable<? extends IAuxhead> auxhead) Returns a copy ofthisimmutable component with the specifiedauxhead.default ITreewithAuxhead(IAuxhead... auxhead) Returns a copy ofthisimmutable component with the specifiedauxhead.withCheckmark(boolean checkmark) Returns a copy ofthisimmutable component with the specifiedcheckmark.withCheckmarkDeselectOther(boolean checkmarkDeselectOther) Returns a copy ofthisimmutable component with the specifiedcheckmarkDeselectOther.withFrozen(IFrozen frozen) Returns a copy ofthisimmutable component with the specifiedfrozen.withMultiple(boolean multiple) Returns a copy ofthisimmutable component with the specifiedmultiple.withNonselectableTags(String nonselectableTags) Returns a copy ofthisimmutable component with the specifiedname.withRightSelect(boolean rightSelect) Returns a copy ofthisimmutable component with the specifiedrightSelect.withRows(int rows) Returns a copy ofthisimmutable component with the specifiedrows.withSelectOnHighlightDisabled(boolean selectOnHighlightDisabled) Returns a copy ofthisimmutable component with the specifiedselectOnHighlightDisabled.withThrottleMillis(int throttleMillis) Returns a copy ofthisimmutable component with the specifiedthrottleMillis.withTreechildren(ITreechildren treechildren) Returns a copy ofthisimmutable component with the specifiedtreechildren.withTreecols(ITreecols treecols) Returns a copy ofthisimmutable component with the specifiedtreecols.withTreefoot(ITreefoot treefoot) Returns a copy ofthisimmutable component with the specifiedtreefoot.Methods inherited from interface org.zkoss.stateless.sul.IComponent
getAction, getActions, getClientAttributes, getId, getMold, getWidgetListeners, getWidgetOverrides, isVisible, withAction, withAction, withAction, withAction, withAction, withAction, withAction, withAction, withAction, withAction, withAction, withActions, withActions, withClientAttribute, withClientAttributes, withId, withMold, withVisible, withWidgetClass, withWidgetListener, withWidgetListeners, withWidgetOverride, withWidgetOverridesMethods inherited from interface org.zkoss.stateless.sul.IHtmlBasedComponent
getClientAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZIndex, isFocus, withClientAction, withDraggable, withDroppable, withFocus, withHeight, withHflex, withLeft, withRenderdefer, withSclass, withSkeleton, withStyle, withTabindex, withTabindex, withTooltiptext, withTop, withVflex, withWidth, withZclass, withZIndexMethods inherited from interface org.zkoss.stateless.sul.IMeshElement
getPagingChild, getPagingPosition, getSpan, isAutopaging, isNativeScrollbar, isSizedByContent, withAutopaging, withNativeScrollbar, withPagingChild, withPagingPosition, withPagingPosition, withSizedByContent, withSpan, withSpanMethods inherited from interface org.zkoss.stateless.sul.IXulElement
getContext, getCtrlKeys, getPopup, getTooltip, withContext, withCtrlKeys, withPopup, withTooltip
-
Field Details
-
DEFAULT
Constant for default attributes of this immutable component. -
PAGING
Constant for"paging"mold attributes of this immutable component.
-
-
Method Details
-
getWidgetClass
Returns the client widget class.Default:
"zul.sel.Tree"- Specified by:
getWidgetClassin interfaceIComponent<ITree>
-
getTreecols
Returns theITreecolscomponent, if any.Default:
null -
withTreecols
Returns a copy ofthisimmutable component with the specifiedtreecols.Sets the
ITreecolscomponent as the set of columns of the tree- Parameters:
treecols- TheITreecolscomponent to contain all tree columnsDefault:
null.- Returns:
- A modified copy of the
thisobject
-
getTreefoot
Returns theITreefootcomponent, if any.Default:
null -
withTreefoot
Returns a copy ofthisimmutable component with the specifiedtreefoot.Sets the
ITreefootcomponent as the set of footers of the tree- Parameters:
treefoot- TheITreefootcomponent to contain all tree footersDefault:
null.- Returns:
- A modified copy of the
thisobject
-
getItems
Returns a readonly list of all descendingITreeitem(children's children and so on).Note: the performance of the size method of returned collection is no good.
-
withAllComponents
Description copied from interface:ICompositeCopy the current immutable object with elements that replace the content ofchildren. A shallow reference equality check is used to prevent copying of the same value by returningthis.- Specified by:
withAllComponentsin interfaceIComposite<ITree,IMeshComposite> - Parameters:
elements- An iterable of children elements to set- Returns:
- A modified copy of
thisobject
-
getAuxhead
Returns theIAuxheadcomponent, if any.Default:
null -
withAuxhead
Returns a copy ofthisimmutable component with the specifiedauxhead.Sets the
IAuxheadcomponent as the set of auxiliary headers of the tree- Parameters:
auxhead- TheIAuxheadcomponent to contain all auxiliary headers of the treeDefault:
null.- Returns:
- A modified copy of the
thisobject
-
withAuxhead
Returns a copy ofthisimmutable component with the specifiedauxhead.Sets the
IAuxheadcomponent as the set of auxiliary headers of the tree- Parameters:
auxhead- TheIAuxheadcomponent to contain all auxiliary headers of the treeDefault:
null.- Returns:
- A modified copy of the
thisobject
-
getTreechildren
Returns the rootITreechildren, which contains all tree items in a hierarchical set of rows of components.Default:
null -
withTreechildren
Returns a copy ofthisimmutable component with the specifiedtreechildren.Sets the
ITreechildrencomponent that the tree owns- Parameters:
treechildren- TheITreechildrencomponent to contain all tree items in a hierarchical set of rows of components.Default:
null.- Returns:
- A modified copy of the
thisobject
-
getFrozen
Returns aIFrozencomponent to enable a frozen column or row facility.Default:
null -
withFrozen
Returns a copy ofthisimmutable component with the specifiedfrozen.Sets the
IFrozencomponent that the tree owns to enable a frozen column or row facility.- Parameters:
frozen- TheIFrozencomponentDefault:
null.- Returns:
- A modified copy of the
thisobject
-
getRows
default int getRows()Returns the number of the rows to display at screen. Zero means no limitation.Default:
0 -
withRows
Returns a copy ofthisimmutable component with the specifiedrows.Sets the number of the rows of the tree to display at a screen, which means the height of the tree is based on the calculation of the number of the rows by multiplying with each row height.
Note: Not allowed to setrowsandheight/vflexat the same time.- Parameters:
rows- The number of rows to display.Default:
0. (Meaning no limitation)- Returns:
- A modified copy of the
thisobject
-
getAutosort
Returns whether to sort all items when model or sort direction be changed.Default:
false, if the"org.zkoss.zul.tree.autoSort"library property is not set in zk.xml.Note: it's meaningless if
TreeModelis not set. -
withAutosort
Returns a copy ofthisimmutable component with the specifiedautosort.Sets to enable the auto-sort facility to sort the model for this component. Meaningless if
TreeModelis not set.- Parameters:
autosort- The allowed values arenull,"false","true", and"ignore.change".Default:
null.- Returns:
- A modified copy of the
thisobject
-
withAutosort
Returns a copy ofthisimmutable component with the specifiedautosort.Sets to enable the auto-sort facility to sort the model for this component. Meaningless if
TreeModelis not set.- Parameters:
autosort- TheITree.Autosortattribute.- Returns:
- A modified copy of the
thisobject - See Also:
-
isMultiple
default boolean isMultiple()Returns whether multiple selections are allowed.Default:
false. -
withMultiple
Returns a copy ofthisimmutable component with the specifiedmultiple.Sets whether multiple selections are allowed.
Notice that, if a model is assigned, it will change the model's state (by
TreeSelectableModel.setMultiple(boolean)).- Parameters:
multiple- True to allow multiple selections.Default:
false.- Returns:
- A modified copy of the
thisobject
-
isCheckmark
default boolean isCheckmark()Returns whether the check mark shall be displayed in front of each item.Default:
false. -
withCheckmark
Returns a copy ofthisimmutable component with the specifiedcheckmark.Sets whether the check mark shall be displayed in front of each item.
The check mark is a checkbox if
isMultiple()returns true. It is a radio button ifisMultiple()returns false.- Parameters:
checkmark- True to enable the check mark in front of each item.Default:
false.- Returns:
- A modified copy of the
thisobject
-
getNonselectableTags
Returns a list of HTML tag names that shall not cause the tree item being selected if they are clicked.Default:
null(it meansbutton,input,textareaandaHTML elements). If you want to select no matter which tag is clicked, please specify an empty string. Specifynullto use the default and""to indicate none. -
withNonselectableTags
Returns a copy ofthisimmutable component with the specifiedname.Sets a list of HTML tag names that shall not cause the tree item being selected if they are clicked.
Default:
null(it meansbutton,input,textareaandaHTML elements). If you want to select no matter which tag is clicked, please specify an empty string.- Parameters:
nonselectableTags- A list of HTML tag names that will not cause the tree item being selected if clicked. Specifynullto use the default and""to indicate none.- Returns:
- A modified copy of the
thisobject
-
isCheckmarkDeselectOther
default boolean isCheckmarkDeselectOther()Returns whether to toggle the selection if clicking on a tree item with a checkmark. Meaningless ifisCheckmark()is falseDefault:
false, if the"org.zkoss.zul.tree.checkmarkDeselectOthers"library property is not set in zk.xml. -
withCheckmarkDeselectOther
Returns a copy ofthisimmutable component with the specifiedcheckmarkDeselectOther.Sets
trueto prefer to deselect all other items and select the item being clicked. IfisCheckmark()is enabled.Default:
false(not to deselect other items).- Parameters:
checkmarkDeselectOther- True to deselect other items and select the item being clicked.Default:
false- Returns:
- A modified copy of the
thisobject
-
isSelectOnHighlightDisabled
default boolean isSelectOnHighlightDisabled()Returns whether to disable select functionality when highlighting text content with mouse dragging or not.Default:
false, if the"org.zkoss.zul.tree.selectOnHighlight.disabled"library property is not set in zk.xml. -
withSelectOnHighlightDisabled
Returns a copy ofthisimmutable component with the specifiedselectOnHighlightDisabled.Sets whether to disable select functionality when highlighting text content with mouse dragging or not.
- Parameters:
selectOnHighlightDisabled- True to disable select functionality when highlighting text content with mouse dragging or not.Default:
false- Returns:
- A modified copy of the
thisobject
-
isRightSelect
default boolean isRightSelect()Returns whether to toggle a list item selection on right click, only ifisCheckmark()is enabled.Default:
true, if the"org.zkoss.zul.tree.rightSelect"library property is not set in zk.xml. -
withRightSelect
Returns a copy ofthisimmutable component with the specifiedrightSelect.Sets whether to enable the selection will be toggled when the user right clicks item, only if
isCheckmark()is enabled.- Parameters:
rightSelect- False not to select/deselect item on right clickDefault:
true- Returns:
- A modified copy of the
thisobject
-
getThrottleMillis
default int getThrottleMillis()Returns the millisecond of scrolling throttling in Tree render on-demand (ROD).Default:
Tree.DEFAULT_THROTTLE_MILLIS, if the""org.zkoss.zul.tree.throttleMillis"property is not set in zk.xml when run with ZK EE. -
withThrottleMillis
Returns a copy ofthisimmutable component with the specifiedthrottleMillis.Sets the millisecond of scrolling throttling in Tree render on-demand (ROD).
- Parameters:
throttleMillis- The millisecond of scrolling throttlingDefault:
Tree.DEFAULT_THROTTLE_MILLIS- Returns:
- A modified copy of the
thisobject
-
of
Returns the instance with the given tree items which belong to root level.- Parameters:
children- The tree items of the root level.
-
of
Returns the instance with the given tree items which belong to root level.- Parameters:
children- The tree items of the root level.
-
ofTreecols
Returns the instance with the given tree columns.- Parameters:
treecols- TheITreecolscomponent to contain all tree columns.
-
ofTreecols
Returns the instance with the given tree columns.- Parameters:
children- The children ofITreecolscomponent.
-
ofTreecols
Returns the instance with the given tree columns.- Parameters:
children- The children ofITreecolscomponent.
-
ofTreefoot
Returns the instance with the given tree foot.- Parameters:
treefoot- TheITreefootcomponent to contain all tree footers.
-
ofId
Returns the instance with the given id.- Parameters:
id- The id to identify this component.
-
