0

How to catch tree check and uncheck event

asked 2014-05-23 11:32:27 +0800

Satyajit gravatar image Satyajit
1

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

delete flag offensive retag edit

3 Answers

Sort by ยป oldest newest most voted
0

answered 2014-05-27 01:28:39 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

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.

link publish delete flag offensive edit
0

answered 2014-05-27 06:35:46 +0800

Satyajit gravatar image Satyajit
1

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

link publish delete flag offensive edit
0

answered 2016-10-10 17:00:45 +0800

aspinformatica gravatar image aspinformatica
0
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;
    }       
}
link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2014-05-23 11:32:27 +0800

Seen: 52 times

Last updated: Oct 10 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More