-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a dynamic tree with checkbox. I am using AbstractTreeModel to render the tree nodes. I am not using any tree renderer for the same.
Currently I am facing problems in getting the check and uncheck event of the tree.
I need to know the treeitem object when tree check box is selected or deselected, depending on which i will put my logic like below a - If parent is selected all the child nodes should be selected. b - If all the child are unchecked, parent should be unchecked. c - If any of the child is checked then parent should remain checked. d - While opening a collapsed node which is checked, all the opened child should be checked.
Is there any way to implement this in ZK
Hello Satyajit, if i understood right you can get the childs or parents from the selected treeitem, is not very dificult and you can check them. methods: getChildren(), getParent(). With that you can implement your logic.
Thanks for the response
Yes you are right. I can get the childs or parents from the selected node(only checked nodes). My problem is how to know which treeitem is Unchecked by the user at runtime(which was checked before)as method getSelectedItems() only returns the selected treeitems not the deselected items. If it will be possible to handle onCheck and onUnCheck events of treeitem/corresponding checkbox, selecting or deselecting all the child nodes will be possible.
Again in an ondemand tree, a parent node whose child are not yet opened/rendered, and its check box is checked(by user at runtime). Now user is expanding the parent node(that means child nodes will be loaded now by executing query), my requirement is all the newly loaded child nodes of the parent (which is previously checked) should also be checked(their check boxes should be auto checked). If parent is not checked child nodes should open as unchecked
public void doAfterCompose(Window comp) throws Exception {
super.doAfterCompose(comp);
treePai.addEventListener(Events.ON_SELECT, new CheckUncheckEventListener());
}
class CheckUncheckEventListener implements EventListener {
public void onEvent(Event event) throws Exception {
SelectEvent evt = (SelectEvent)event;
Treeitem t = (Treeitem)evt.getReference();
Treerow r = t.getTreerow();
String sCodigo = ((Treecell)r.getChildren().get(1)).getLabel();
CheckUncheckItens(t, t.isSelected());
}
public void CheckUncheckItens(Component component, boolean check) {
if (component == null)
return;
if (component instanceof Treeitem) {
Treeitem t = (Treeitem) component;
t.setSelected(check);
CheckUncheckItens(t.getTreechildren(), check);
} else if (component instanceof Treechildren) {
for (Component c : component.getChildren()) {
CheckUncheckItens(c, check);
}
}
return;
}
}
Asked: 2014-05-23 11:32:27 +0800
Seen: 59 times
Last updated: Oct 10 '16
Problem binding values to a composite component
How to access static member field of a class in zul without zscript
How can i load a constant in .zul
MVVM Validator: class not found ? [closed]
MVVM tab box - delay @load until tab pane displayed?
mvvm, load or save with after or before for seach command
how to fire an event when a variable value loaded through VM
is there any event trigger from zk component on binding ?
ZK team plans to dispose of Composer EventQueues no longer in scope? [closed]