Class Tree
- All Implemented Interfaces:
Serializable,Cloneable,Component,Scope,ComponentCtrl,Paginated
Event:
SelectEventis sent when user changes the selection.- onAfterRender is sent when the model's data has been rendered.(since 5.0.4)
Default getZclass(): z-tree. (since 3.5.0)
Custom Attributes:
- org.zkoss.zul.tree.rightSelect
- Specifies whether the selection shall be toggled when user right clicks on
item, if the checkmark (
isCheckmark()) is enabled. Notice that you could specify this attribute in any of its ancestor's attributes. It will be inherited. - org.zkoss.zul.tree.autoSort .(since 5.0.7)
- Specifies whether to sort the model when the following cases:
setModel(org.zkoss.zul.TreeModel<?>)is called andTreecol.setSortDirection(java.lang.String)is set.Treecol.setSortDirection(java.lang.String)is called.- Model receives
TreeDataEventandTreecol.setSortDirection(java.lang.String)is set.
TreeDataEvent, you can specifies the value as "ignore.change". Notice that you could specify this attribute in any of its ancestor's attributes. It will be inherited.
[Since 6.0.0]
To retrieve what are selected in Tree with a TreeSelectableModel,
you shall use TreeSelectableModel.isPathSelected(int[])
to check whether the current path is selected in TreeSelectableModel
rather than using getSelectedItems(). That is, you shall operate on
the item of the TreeSelectableModel rather than on the Treeitem
of the Tree if you use the TreeSelectableModel and TreeModel.
TreeSelectableModel selModel = ((TreeSelectableModel)getModel());
int[][] paths = selModel.getSelectionPaths();
List<E> selected = new ArrayList<E>();
AbstractTreeModel model = (AbstractTreeModel) selModel;
for (int i = 0; i < paths.length; i++) {
selected.add(model.getChild(paths[i]));
}
[Since 6.0.0]
If the TreeModel in Tree implements a TreeSelectableModel, the
multiple selections status is applied from the method of
TreeSelectableModel.isMultiple()
DefaultTreeModel selModel = new DefaultTreeModel(treeNode);
selModel.setMultiple(true);
tree.setModel(selModel);
[Since 6.0.0]
To retrieve what are opened nodes in Tree with a TreeOpenableModel,
you shall use TreeOpenableModel.isPathOpened(int[])
to check whether the current path is opened in TreeOpenableModel
rather than using Treeitem.isOpen(). That is, you shall operate on
the item of the TreeOpenableModel rather than on the Treeitem
of the Tree if you use the TreeOpenableModel and TreeModel.
TreeOpenableModel openModel = ((TreeOpenableModel)getModel());
int[][] paths = openModel.getOpenPaths();
List<E> opened = new ArrayList<E>();
AbstractTreeModel model = (AbstractTreeModel) openModel;
for (int i = 0; i < paths.length; i++) {
opened.add(model.getChild(paths[i]));
}
[Since 7.0.0] (EE version only)
It is used only if live data (setModel(TreeModel) and
not paging (getPagingChild()).
- Author:
- tomyeh
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.zkoss.zul.impl.MeshElement
MeshElement.InternalPagingNested classes/interfaces inherited from class org.zkoss.zk.ui.HtmlBasedComponent
HtmlBasedComponent.ExtraCtrlNested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children, AbstractComponent.ForwardInfo, AbstractComponent.TargetInfo -
Field Summary
FieldsFields inherited from class org.zkoss.zul.impl.MeshElement
CSS_FLEX_AUTO_DISABLED_COUNTFields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
_zclassFields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPEFields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl
AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddItemToSelection(Treeitem item) Selects the given item, without deselecting any other items that are already selected..voidbeforeChildAdded(Component newChild, Component refChild) Default: does nothing.voidclear()Clears all child tree items (Treeitem.voidClears the selection.clone()Clones the component.intReturns the active page (starting from 0).protected ObjectgetAssociatedNode(Treeitem ti, Tree t) Return a node which is an associated Treeitem ti in a Tree treeprotected ComponentgetChildByNode(Object node) Return the Tree or Treeitem component by a given associated node in model, or null if the treeitem is not instantiated (i.e., rendered) yet.protected ComponentgetChildByPath(int[] path) Return the Tree or Treeitem component by a path, or null if corresponding Treeitem is not instantiated (i.e., rendered) yet.Returns the frozen child.getHeads()Returns a collection of heads, includinggetTreecols()and auxiliary heads (Auxhead) (never null).Returns the inner width of this component.intReturns the number of childTreeitem.<T> TreeitemRenderer<T>Returns the renderer to render each item, or null if the default renderer is used.getItems()Returns a readonly list of all descendingTreeitem(children's children and so on).<T> TreeModel<T>getModel()Returns the list model associated with this tree, or null if this tree is not associated with any tree data model.getName()Returns the name of this component.Returns a list of HTML tag names that shall not cause the tree item being selected if they are clicked.intReturns the page size, a.k.a., the number items per page.Returns the paging controller, or null if not available.Returns the child paging controller that is created automatically, or null if mold is not "paging", or the controller is specified externally bysetPaginal(org.zkoss.zul.ext.Paginal).getPropertyAccess(String prop) Returns the corresponding property access object from the given property name, if any.intgetRows()Returns the rows.intReturns the number of items being selected.Returns the selected item.Returns all selected items.Returns the seltype.Returns the treechildren that this tree owns (might null).Returns the treecols that this tree owns (might null).Returns the treefoot that this tree owns (might null).Returns the ZK Cascading Style class for this component.booleaninsertBefore(Component newChild, Component refChild) Inserts a child before the reference child.protected booleanbooleanReturns whether the check mark shall be displayed in front of each item.booleanReturns whether multiple selections are allowed.protected booleanbooleanisVflex()Returns whether to grow and shrink vertical to fit their given space, so called vertical flexibility.voidvoidonChildAdded(Component child) Default: handles special event listeners.voidonChildRemoved(Component child) Default: handles special event listeners.voidHandles a private event, onInitRender.voidonPageAttached(Page newpage, Page oldpage) Default: handles special event listeners.voidonPageDetached(Page page) Default: handles special event listeners.protected Paginalpgi()Returns the instance of the @{link Paginal}protected voidredrawChildren(Writer out) Redraws children (and then recursively descendants).voidDeselects the given item without deselecting other items.voidrenderItem(Treeitem item) Renders the specifiedTreeitem, if not loaded yet, withgetItemRenderer().voidrenderItem(Treeitem item, Object node) Renders the specifiedTreeitem, if not loaded yet, withgetItemRenderer().renderItemByNode(Object node) Load the treeitems by the given node.renderItemByPath(int[] path) Load the treeitems by giving a path of the treeitems top open.voidrenderItems(Set<? extends Treeitem> items) Renders the specifiedTreeitemif not loaded yet, withgetItemRenderer().protected voidrenderProperties(ContentRenderer renderer) Renders the content of this component, excluding the enclosing tags and children.voidSelects all items.voidselectItem(Treeitem item) Deselects all of the currently selected items and selects the given item.voidProcesses an AU request.voidsessionDidActivate(Page page) Notification that the session, which owns this component, has just been activated (a.k.a., deserialized).voidsessionWillPassivate(Page page) Notification that the session, which owns this component, is about to be passivated (a.k.a., serialized).voidsetActivePage(int pg) Sets the active page (starting from 0).voidsetActivePage(Treeitem item) Sets the active page in which the specified item is.voidsetCheckmark(boolean checkmark) Sets whether the check mark shall be displayed in front of each item.voidSets the height.voidsetInnerWidth(String innerWidth) Sets the inner width of this component.voidsetItemRenderer(String clsnm) Sets the renderer by use of a class name.voidsetItemRenderer(TreeitemRenderer<?> renderer) Sets the renderer which is used to render each item ifgetModel()is not null.voidSets the tree model associated with this tree.voidSets the mold to render this component.voidsetMultiple(boolean multiple) Sets whether multiple selections are allowed.voidSets the name of this component.voidsetNonselectableTags(String tags) Sets a list of HTML tag names that shall not cause the tree item being selected if they are clicked.voidsetPageSize(int pgsz) Sets the page size, a.k.a., the number items per page.voidsetPaginal(Paginal pgi) voidsetRows(int rows) Sets the rows.voidsetSelectedItem(Treeitem item) Deselects all of the currently selected items and selects the given item.voidsetSeltype(String seltype) Sets the seltype.voidsetVflex(boolean vflex) Sets whether to grow and shrink vertical to fit their given space, so called vertical flexibility.voidSets vertical flexibility hint of this component.voidsmartUpdate(String attr, Object value) Smart-updates a property of the peer widget associated with the component, running at the client, with the given value.voidtoggleItemSelection(Treeitem item) If the specified item is selected, it is deselected.Methods inherited from class org.zkoss.zul.impl.MeshElement
checkBeforeSetRows, evalCSSFlex, getPageCount, getPagingPosition, getSpan, isAutopaging, isPagingDisabled, isSizedByContent, isSpan, setAutopaging, setPagingDisabled, setPagingPosition, setSizedByContent, setSpan, setSpanMethods inherited from class org.zkoss.zul.impl.XulElement
getContext, getCtrlKeys, getPopup, getTooltip, setContext, setContext, setContextAttributes, setCtrlKeys, setPopup, setPopup, setPopupAttributes, setTooltip, setTooltip, setTooltipAttributesMethods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
addSclass, focus, getAction, getClientAction, getDraggable, getDroppable, getExtraCtrl, getHeight, getHflex, getLeft, getRenderdefer, getSclass, getSkeleton, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setSkeleton, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectlyMethods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getStubonlyDescendants, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, invalidate, isChildable, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onParentChanged, onWrongValue, query, queryAll, redraw, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setPage, setPageBefore, setParent, setStubonly, setStubonly, setStubonlyDescendants, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize
-
Field Details
-
DEFAULT_THROTTLE_MILLIS
public static final int DEFAULT_THROTTLE_MILLIS- See Also:
-
-
Constructor Details
-
Tree
public Tree()
-
-
Method Details
-
onPageAttached
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onPageAttachedin interfaceComponentCtrl- Overrides:
onPageAttachedin classAbstractComponent- Parameters:
newpage- the new page (never null).oldpage- the previous page, if any, or null if it didn't belong to any page.- See Also:
-
onPageDetached
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onPageDetachedin interfaceComponentCtrl- Overrides:
onPageDetachedin classAbstractComponent- Parameters:
page- the previous page (never null)- See Also:
-
setMold
Sets the mold to render this component.- Specified by:
setMoldin interfaceComponent- Overrides:
setMoldin classAbstractComponent- Parameters:
mold- the mold. If null or empty, "default" is assumed. Allowed values: default, paging- See Also:
-
getPaginal
Returns the paging controller, or null if not available. Note: the paging controller is used only ifAbstractComponent.getMold()is "paging".If mold is "paging", this method never returns null, because a child paging controller is created automatically (if not specified by developers with
setPaginal(org.zkoss.zul.ext.Paginal)).If a paging controller is specified (either by
setPaginal(org.zkoss.zul.ext.Paginal), or bysetMold(java.lang.String)with "paging"), the tree will rely on the paging controller to handle long-content instead of scrolling.- Since:
- 3.0.7
-
setPaginal
-
getPagingChild
Returns the child paging controller that is created automatically, or null if mold is not "paging", or the controller is specified externally bysetPaginal(org.zkoss.zul.ext.Paginal).- Since:
- 3.0.7
-
getPageSize
public int getPageSize()Returns the page size, a.k.a., the number items per page.- Overrides:
getPageSizein classMeshElement- Throws:
IllegalStateException- ifgetPaginal()returns null, i.e., mold is not "paging" and no external controller is specified.- Since:
- 2.4.1
-
setPageSize
Sets the page size, a.k.a., the number items per page.Note: mold is "paging" and no external controller is specified.
- Overrides:
setPageSizein classMeshElement- Throws:
WrongValueException- Since:
- 2.4.1
-
pgi
Description copied from class:MeshElementReturns the instance of the @{link Paginal}- Specified by:
pgiin classMeshElement
-
getTreecols
Returns the treecols that this tree owns (might null). -
getTreefoot
Returns the treefoot that this tree owns (might null). -
getFrozen
Returns the frozen child.- Since:
- 7.0.0
-
getTreechildren
Returns the treechildren that this tree owns (might null). -
getHeads
Returns a collection of heads, includinggetTreecols()and auxiliary heads (Auxhead) (never null).- Since:
- 3.0.0
-
getRows
public int getRows()Returns the rows. Zero means no limitation.Default: 0.
-
setRows
Sets the rows.Note: Not allowed to set rows and height/vflex at the same time
- Throws:
WrongValueException
-
setHeight
Description copied from class:HtmlBasedComponentSets the height. If null, the best fit is used.- Overrides:
setHeightin classHtmlBasedComponent
-
getName
Returns the name of this component.Default: null.
The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.
Don't use this method if your application is purely based on ZK's event-driven model.
-
setName
Sets the name of this component.The name is used only to work with "legacy" Web application that handles user's request by servlets. It works only with HTTP/HTML-based browsers. It doesn't work with other kind of clients.
Don't use this method if your application is purely based on ZK's event-driven model.
- Parameters:
name- the name of this component.
-
setNonselectableTags
Sets a list of HTML tag names that shall not cause the tree item being selected if they are clicked.Default: null (it means button, input, textarea and a). If you want to select no matter which tag is clicked, please specify an empty string.
- Parameters:
tags- a list of HTML tag names that will not cause the tree item being selected if clicked. Specify null to use the default and "" to indicate none.- Since:
- 5.0.5
-
getNonselectableTags
Returns a list of HTML tag names that shall not cause the tree item being selected if they are clicked.Refer to
setNonselectableTags(java.lang.String)for details.- Since:
- 5.0.5
-
isCheckmark
public boolean isCheckmark()Returns whether the check mark shall be displayed in front of each item.Default: false.
-
setCheckmark
public void setCheckmark(boolean checkmark) 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. -
isVflex
public boolean isVflex()Returns whether to grow and shrink vertical to fit their given space, so called vertical flexibility.Note: this attribute is ignored if
setRows(int)is specifiedDefault: false.
-
setVflex
public void setVflex(boolean vflex) Sets whether to grow and shrink vertical to fit their given space, so called vertical flexibility.Note: this attribute is ignored if
setRows(int)is specified -
setVflex
Description copied from class:HtmlBasedComponentSets vertical flexibility hint of this component.Number flex indicates how this component's container distributes remaining empty space among its children vertically. Flexible component grow and shrink to fit their given space. Flexible components with larger flex values will be made larger than components with lower flex values, at the ratio determined by all flexible components. The actual flex value is not relevant unless there are other flexible components within the same container. Once the default sizes of components in a container are calculated, the remaining space in the container is divided among the flexible components, according to their flex ratios.
Specify a flex value of negative value, 0, or "false" has the same effect as leaving the flex attribute out entirely. Specify a flex value of "true" has the same effect as a flex value of 1.
Special flex hint, "min", indicates that the minimum space shall be given to this flexible component to enclose all of its children components. That is, the flexible component grow and shrink to fit its children components.
- Overrides:
setVflexin classHtmlBasedComponent- Parameters:
flex- the vertical flex hint.- See Also:
-
setInnerWidth
Sets the inner width of this component. The inner width is the width of the inner table. By default, it is 100%. That is, it is the same as the width of this component. However, it is changed when the user is sizing the column's width.Application developers rarely call this method, unless they want to preserve the widths of sizable columns changed by the user. To preserve the widths, the developer have to store the widths of all columns and the inner width (
getInnerWidth()), and then restore them when re-creating this component.- Parameters:
innerWidth- the inner width. If null, "100%" is assumed.- Since:
- 3.0.0
-
getInnerWidth
Returns the inner width of this component. The inner width is the width of the inner table.Default: "100%"
- Since:
- 3.0.0
- See Also:
-
getSeltype
Returns the seltype.Default: "single".
-
setSeltype
Sets the seltype. "single","multiple" is supported.- Throws:
WrongValueException
-
isMultiple
public boolean isMultiple()Returns whether multiple selections are allowed.Default: false.
-
setMultiple
public void setMultiple(boolean multiple) Sets whether multiple selections are allowed.Notice that, if a model is assigned, it will change the model's state (by
TreeSelectableModel.setMultiple(boolean)). -
setActivePage
Sets the active page in which the specified item is. The active page will become the page that contains the specified item.- Parameters:
item- the item to show. If the item is null, invisible, or doesn't belong to the same tree, nothing happens.- Since:
- 3.0.4
-
setActivePage
Description copied from class:MeshElementSets the active page (starting from 0).- Overrides:
setActivePagein classMeshElement- Throws:
WrongValueException
-
smartUpdate
Description copied from class:AbstractComponentSmart-updates a property of the peer widget associated with the component, running at the client, with the given value.The second invocation with the same property will replace the previous call. In other words, the same property will be set only once in each execution. If you prefer to send both updates to the client, use
AbstractComponent.smartUpdate(String, Object, boolean)instead.This method has no effect if
AbstractComponent.invalidate()is ever invoked (in the same execution), sinceAbstractComponent.invalidate()assumes the whole content shall be redrawn and all smart updates to this components can be ignored,Once
AbstractComponent.invalidate()is called, all invocations toAbstractComponent.smartUpdate(String, Object)will then be ignored, andAbstractComponent.redraw(java.io.Writer)will be invoked later.It can be called only in the request-processing and event-processing phases; excluding the redrawing phase.
There are two ways to draw a component, one is to invoke
Component.invalidate(), and the other isAbstractComponent.smartUpdate(String, Object). WhileComponent.invalidate()causes the whole content to redraw,AbstractComponent.smartUpdate(String, Object)let component developer control which part to redraw.- Overrides:
smartUpdatein classAbstractComponentvalue- the new value. If it isDeferredValue, the value will be retrieved (by callingDeferredValue.getValue()) in the rendering phase. It is useful if the value can not be determined now.For some old application servers (example, Websphere 5.1),
Execution.encodeURL(java.lang.String)cannot be called in the event processing thread. So, the developers have to useDeferredValueor disable the use of the event processing thread (by use ofdisable-event-threadin zk.xml).If you want to generate the JavaScript code directly (i.e., the value is a valid JavaScript snippet), you can use
JavaScriptValue. Notice that the JavaScript code will be evaluated before assigning it to the widget.If the value is a Date object, a special pattern will be generated (a.k.a., marshaling) to ensure it can be unmarshalled back correctly at the client. Notice that it is marshalled to a string based on
TimeZones.getCurrent(), and then unmarshalled back at the client. In other words, if the client is in different time-zone, the value returned by getTime() might be different. However, the value will remain the same if the client marshalled the Date object back. In other words, it assumes the browser's time zone from enduser's perspective (not really browser's setting) shall be the same asTimeZones.getCurrent().If the value is a component, a special pattern will be generated to ensure it can be unmarshalled back correctly at the client.
In addition, the value can be any kind of objects that the client accepts (marshaled by JSON) (see also
JSONAware).- See Also:
-
getItems
Returns a readonly list of all descendingTreeitem(children's children and so on).Note: the performance of the size method of returned collection is no good.
-
getItemCount
public int getItemCount()Returns the number of childTreeitem. The same asgetItems().size().Note: the performance of this method is no good.
-
selectItem
Deselects all of the currently selected items and selects the given item.It is the same as
setSelectedItem(org.zkoss.zul.Treeitem).- Parameters:
item- the item to select. If null, all items are deselected.
-
addItemToSelection
Selects the given item, without deselecting any other items that are already selected.. -
removeItemFromSelection
Deselects the given item without deselecting other items. -
toggleItemSelection
If the specified item is selected, it is deselected. If it is not selected, it is selected. Other items in the tree that are selected are not affected, and retain their selected state. -
clearSelection
public void clearSelection()Clears the selection. -
selectAll
public void selectAll()Selects all items. -
getSelectedItem
Returns the selected item. -
setSelectedItem
Deselects all of the currently selected items and selects the given item.It is the same as
selectItem(org.zkoss.zul.Treeitem). -
getSelectedItems
Returns all selected items. -
getSelectedCount
public int getSelectedCount()Returns the number of items being selected. -
clear
public void clear()Clears all child tree items (Treeitem.Note: after clear,
getTreechildren()won't be null, but it has no child -
getZclass
Description copied from class:HtmlBasedComponentReturns the ZK Cascading Style class for this component. It usually depends on the implementation of the mold (AbstractComponent.getMold()).Default: null (the default value depends on element).
HtmlBasedComponent.setZclass(java.lang.String)) will completely replace the default style of a component. In other words, the default style of a component is associated with the default value ofHtmlBasedComponent.getZclass(). Once it is changed, the default style won't be applied at all. If you want to perform small adjustments, useHtmlBasedComponent.setSclass(java.lang.String)instead.- Overrides:
getZclassin classHtmlBasedComponent- See Also:
-
beforeChildAdded
Description copied from class:AbstractComponentDefault: does nothing.- Specified by:
beforeChildAddedin interfaceComponentCtrl- Overrides:
beforeChildAddedin classAbstractComponent- Parameters:
newChild- the child to be added (never null).refChild- another child component that the new child will be inserted before it. If null, the new child will be the last child.- See Also:
-
insertBefore
Description copied from interface:ComponentInserts a child before the reference child.You could use
Component.setParent(org.zkoss.zk.ui.Component)orComponent.appendChild(org.zkoss.zk.ui.Component)instead of this method, unless you want to control where to put the child.Note:
Component.setParent(org.zkoss.zk.ui.Component)always calls backComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)and/orComponent.removeChild(org.zkoss.zk.ui.Component), whileComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.removeChild(org.zkoss.zk.ui.Component)always calls backComponent.setParent(org.zkoss.zk.ui.Component), if the parent is changed. Thus, you don't need to override bothComponent.insertBefore(org.zkoss.zk.ui.Component, org.zkoss.zk.ui.Component)andComponent.setParent(org.zkoss.zk.ui.Component), if you want to customize the behavior.If you would like to monitor if a component is attached or detached from a page, you could register a desktop listener implementing
UiLifeCycle.- Specified by:
insertBeforein interfaceComponent- Overrides:
insertBeforein classAbstractComponent- Parameters:
newChild- the new child to be inserted.refChild- the child before which you want the new child being inserted. If null, the new child is append to the end.- Returns:
- true if newChild is added successfully or moved; false if it already has the specified child and the order doesn't change.
-
onChildAdded
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onChildAddedin interfaceComponentCtrl- Overrides:
onChildAddedin classAbstractComponent- See Also:
-
onChildRemoved
Description copied from class:AbstractComponentDefault: handles special event listeners.- Specified by:
onChildRemovedin interfaceComponentCtrl- Overrides:
onChildRemovedin classAbstractComponent- See Also:
-
clone
Description copied from interface:ComponentClones the component. All of its children and descendants are cloned. Also, ID are preserved.- Specified by:
clonein interfaceComponent- Overrides:
clonein classXulElement- Returns:
- the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
-
sessionWillPassivate
Description copied from interface:ComponentCtrlNotification that the session, which owns this component, is about to be passivated (a.k.a., serialized).Note: only root components are notified by this method.
- Specified by:
sessionWillPassivatein interfaceComponentCtrl- Overrides:
sessionWillPassivatein classAbstractComponent
-
sessionDidActivate
Description copied from interface:ComponentCtrlNotification that the session, which owns this component, has just been activated (a.k.a., deserialized).Note: only root components are notified by this method.
- Specified by:
sessionDidActivatein interfaceComponentCtrl- Overrides:
sessionDidActivatein classAbstractComponent
-
getChildByNode
Return the Tree or Treeitem component by a given associated node in model, or null if the treeitem is not instantiated (i.e., rendered) yet. It returns this tree if the given node is the root node (i.e.,TreeModel.getRoot()).- Throws:
IllegalStateException- if no model is assigned (setModel(org.zkoss.zul.TreeModel<?>)).- Since:
- 3.0.0
- See Also:
-
getChildByPath
Return the Tree or Treeitem component by a path, or null if corresponding Treeitem is not instantiated (i.e., rendered) yet. It returns this tree if the given node is the root node. (i.e.,TreeModel.getRoot()).- Since:
- 6.0.0
-
setModel
Sets the tree model associated with this tree.Note: changing a render will not cause the tree to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(getModel())), or fire an
TreeDataEventevent.- Parameters:
model- the tree model to associate, or null to dissociate any previous model.- Throws:
UiException- if failed to initialize with the model- Since:
- 3.0.0
-
onInitRender
public void onInitRender()Handles a private event, onInitRender. It is used only for implementation, and you rarely need to invoke it explicitly.- Since:
- 6.0.0
-
getModel
Returns the list model associated with this tree, or null if this tree is not associated with any tree data model.- Returns:
- the list model associated with this tree
- Since:
- 3.0.0
-
setItemRenderer
Sets the renderer which is used to render each item ifgetModel()is not null.Note: changing a render will not cause the tree to re-render. If you want it to re-render, you could assign the same model again (i.e., setModel(getModel())), or fire an
TreeDataEventevent.- Parameters:
renderer- the renderer, or null to use the default.- Throws:
UiException- if failed to initialize with the model- Since:
- 5.0.6
-
setItemRenderer
public void setItemRenderer(String clsnm) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InstantiationException, InvocationTargetException Sets the renderer by use of a class name. It creates an instance automatically. -
getItemRenderer
Returns the renderer to render each item, or null if the default renderer is used.- Returns:
- the renderer to render each item, or null if the default
- Since:
- 5.0.6
-
renderItem
Renders the specifiedTreeitem, if not loaded yet, withgetItemRenderer().It does nothing if
getModel()returns null.To unload treeitem, use
Treeitem.unload().- Since:
- 3.0.0
- See Also:
-
renderItem
Renders the specifiedTreeitem, if not loaded yet, withgetItemRenderer().It does nothing if
getModel()returns null.Note: Since the corresponding node is given, This method has better performance than renderItem(Treeitem item) due to not searching for its corresponding node.
To unload treeitem, use
Treeitem.unload().- Since:
- 3.0.0
- See Also:
-
renderItems
Renders the specifiedTreeitemif not loaded yet, withgetItemRenderer().It does nothing if
getModel()returns null.To unload treeitem, with
Treeitem.unload().- Since:
- 3.0.0
- See Also:
-
getAssociatedNode
Return a node which is an associated Treeitem ti in a Tree tree- Since:
- 3.0.0
-
renderItemByNode
Load the treeitems by the given node. This method must be used with a tree model, and the node is one of the value returned byTreeModel.getChild(E, int).Notice that this method has to search the model one-by-one. The performance might not be good, so use
renderItemByPath(int[])if possible.- Returns:
- the treeitem that is associated with the give node, or null no treeitem is associated (including the give node is the root).
- Throws:
IllegalStateException- if no model is assigned (setModel(org.zkoss.zul.TreeModel<?>)).- Since:
- 5.0.6, #getChildByNode
-
renderItemByPath
Load the treeitems by giving a path of the treeitems top open.
Note: By using this method, all treeitems in path will be rendered and opened (Treeitem.setOpen(boolean)). If you want to visit the rendered item in paging mold, please invokesetActivePage(Treeitem).- Parameters:
path- - an index path. The first element is the index at the first level of the tree structure.- Returns:
- the treeitem from tree by given path
- Since:
- 3.0.0
-
redrawChildren
Description copied from class:AbstractComponentRedraws children (and then recursively descendants).Default: it invokes
AbstractComponent.redraw(java.io.Writer)for all its children.If a derived class renders only a subset of its children (such as paging/cropping), it could override
AbstractComponent.redrawChildren(java.io.Writer).- Overrides:
redrawChildrenin classAbstractComponent- Throws:
IOException- See Also:
-
renderProperties
Description copied from class:HtmlBasedComponentRenders the content of this component, excluding the enclosing tags and children.- Overrides:
renderPropertiesin classMeshElement- Throws:
IOException
-
isAutohidePaging
protected boolean isAutohidePaging()- Specified by:
isAutohidePagingin classMeshElement
-
isSelectOnHighlightDisabled
protected boolean isSelectOnHighlightDisabled() -
getPropertyAccess
Description copied from interface:ComponentCtrlReturns the corresponding property access object from the given property name, if any.- Specified by:
getPropertyAccessin interfaceComponentCtrl- Overrides:
getPropertyAccessin classXulElement- Parameters:
prop- the name of the property- Returns:
- null it means not to support for the property name.
-
service
Processes an AU request.Default: in addition to what are handled by
HtmlBasedComponent.service(AuRequest, boolean), it also handles onSelect.- Specified by:
servicein interfaceComponentCtrl- Overrides:
servicein classHtmlBasedComponenteverError- whether any error ever occurred before processing this request.- Since:
- 5.0.0
- See Also:
-
getActivePage
public int getActivePage()Description copied from class:MeshElementReturns the active page (starting from 0).- Overrides:
getActivePagein classMeshElement
-
onAfterRender
public void onAfterRender()
-