Please help me CheckBoxTree

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Please help me CheckBoxTree

Postby Yoganagaky » Fri Jun 24, 2011 7:51 pm

I have a CheckBoxTree in which each node is an Object
I want to get all the Object is checked.
If I check out of the node that I want to remove Object in the Object List is selected earlier
Please help me. I'm very need
Image
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Fri Jun 24, 2011 10:22 pm

Please invoke CheckBoxTree#getCheckBoxTreeSelectionModel()#getSelectionPaths() to get all selected paths.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby Yoganagaky » Sat Jun 25, 2011 12:51 am

I did so. But they are really not effective in many cases.
Please help me. I'm in a hurry.
Code: Select all
public void getListCheck() {
      TreePath[] path = treeDmTaiKhoan.getCheckBoxTreeSelectionModel()
            .getSelectionPaths();
      for (int i = 0; i < path.length; ++i) {
         TreePath ipath = path[i];
         Object[] inode = ipath.getPath();
         for (int j = 0; j < inode.length; ++j) {
            DefaultTreeNode<DmTaiKhoan> node = (DefaultTreeNode<DmTaiKhoan>) inode[i];
            DmTaiKhoan tk = (DmTaiKhoan) node.getUserObject();
            System.out.println(tk.getMaso() + " - " + tk.getName());
         }

      }
   }

Image
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Sat Jun 25, 2011 7:08 am

I believe you are working on digIn mode, which means that one node is selected means that all its children nodes are selected. Take your screenshot as an example, only 1c9b9ca, 7b6889, 1e8a1f6 will be returned as selected path. So you will know that 1ab28fe, ce5b1c and 341960 are children of 7b6889 so they are also selected indeed.

B.T.W., since the "com.evnit.fmis.entity.simple.DmTaiKhoan@xxx" is printed in the UI, do you have any trouble on converting your Object to String? You might set a tree renderer to help you convert it to a readable format.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby Yoganagaky » Sat Jun 25, 2011 7:36 am

If you select a node on the parent 's CheckBoxTree node is selected. But by no means all of them children nodes are selected.
Although the children have been selected node button all or just select a node of the parent node is selected.
For example. If the parent node has 3 children. If I select a node, the node perent children were selected.
Here I only want to retrieve all the selected node.
as the image above. I want to retrieve all the selected node.
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Sat Jun 25, 2011 8:22 am

If you select one of the parent node, the parent node is displayed as partially selected. The parent node is not in the selection path at that scenario. To retrieve all selected nodes, please refer to the following sample code FYI. Tested in JIDE CheckBoxTreeDemo.
Code: Select all
        _tree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
                TreePath[] paths = e.getPaths();
                for (TreePath path : paths) {
                    eventsModel.addElement((e.isAddedPath(path) ? "Added - " : "Removed - ") + path);
                }
                eventsModel.addElement("---------------");
                eventsList.ensureIndexIsVisible(eventsModel.size() - 1);

                TreePath[] treePaths = _tree.getCheckBoxTreeSelectionModel().getSelectionPaths();
                DefaultListModel selectedModel = new DefaultListModel();
                if (treePaths != null) {
                    for (TreePath path : treePaths) {
                        selectedModel.addElement(path);
                        for (TreePath childPath : getChildrenElement(path)) {
                            selectedModel.addElement(childPath);
                        }
                    }
                }
                selectedList.setModel(selectedModel);
            }

            private List<TreePath> getChildrenElement(TreePath parentPath) {
                List<TreePath> childList = new ArrayList<TreePath>();
                Object parentNode = parentPath.getLastPathComponent();
                int childCount = _tree.getModel().getChildCount(parentNode);
                for (int i = 0; i < childCount; i++) {
                    Object child = _tree.getModel().getChild(parentNode, i);
                    final TreePath childPath = parentPath.pathByAddingChild(child);
                    childList.add(childPath);
                    childList.addAll(getChildrenElement(childPath));
                }
                return childList;
            }
        });

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby Yoganagaky » Sat Jun 25, 2011 6:16 pm

Sorry I need to solve a problem anymore.
My CheckBoxTree mode.
treeDmTaiKhoan.setDigIn ( false);
I want to check if a node is the node Perent its check=true and all children set check=true
But if you check out one of its child node, then it is checked.
I want to set Check for a node with code.
Overall I want to set for a node then periodically check in code
Like the picture below.
Image
Would like to thank the help of his.
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby Yoganagaky » Sun Jun 26, 2011 5:11 am

Please help me
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Sun Jun 26, 2011 8:16 am

Sorry but I have problem understanding your question. Can you please re-elaborate what your question is?

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby Yoganagaky » Sun Jun 26, 2011 6:26 pm

I want to Check for a node set by code.
Yoganagaky
 
Posts: 6
Joined: Fri Jun 24, 2011 7:37 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Mon Jun 27, 2011 6:29 am

If you want to select nodes programmatically, please invoke CheckBoxTreeSelectionModel#addSelectionPaths(). The trick is that, you have to get the TreePath from the JTree's API. For example, getPathForRow(), getPathForLocation(), etc.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby ankur.leonardo » Thu Sep 06, 2012 10:22 pm

But How to traverse all the nodes . If their are three parents and each parent has two children, then if addselectionpath() if asks for (int row) and i dont know the whole path to all children. how can i get that.

i short how to get all the path from root to its various child till end. pls it's urgent :(
ankur.leonardo
 
Posts: 6
Joined: Wed Sep 05, 2012 6:49 am

Re: Please help me CheckBoxTree

Postby JIDE Support » Fri Sep 07, 2012 12:52 pm

Please give the following code a try.
Code: Select all
        // this line to get the node. I assume you could try to figure out the node you want to check. Please change this line accordingly
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) treeModel.getChild(treeModel.getChild(treeModel.getRoot(), 0), 0);
        // you then will be able to use this line to select the path assuming you already know the node
        _tree.getCheckBoxTreeSelectionModel().addSelectionPath(new TreePath(node.getPath()));

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: Please help me CheckBoxTree

Postby ab3421 » Thu Sep 13, 2012 2:26 pm

Has anyone been able to figure this out? How to get all the treepaths of the checkbox tree? Trying to preselect few nodes of checkbox tree and cannot do so using addSelectionPath(new TreePath())..The above method doesn't work for me.
ab3421
 
Posts: 1
Joined: Wed Sep 05, 2012 2:33 pm

Re: Please help me CheckBoxTree

Postby JIDE Support » Thu Sep 13, 2012 3:48 pm

Attached is the test case to show how you could select a tree path programmetically. After launching the demo, clicking the button "Select The Second Leaf Node" will select the node correctly.

Thanks,
Attachments
Library.txt.gz
(152.04 KiB) Downloaded 1819 times
DemoData.java
(39.07 KiB) Downloaded 1677 times
CheckBoxTreeDemo.java
(11.83 KiB) Downloaded 1689 times
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: No registered users and 13 guests

cron