how to insert a node to existing check box tree

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.

how to insert a node to existing check box tree

Postby jamindhar » Wed Jun 24, 2009 1:38 am

Hi,

i have a checkbox tree with some nodes. based on some selection i need to insert the node in between the nodes of the checkbox tree. please let me know how to implement this


thanks
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Wed Jun 24, 2009 6:48 am

It depends on which TreeModel you are using. If your TreeModel subclasses AbstractTreeModel, please try AbstractTreeModel#insert() or insertInto().

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

Re: how to insert a node to existing check box tree

Postby jamindhar » Wed Jun 24, 2009 7:57 am

Thanks for your quick reply. sorry i couldnt give you the actual requirement. the following are the requirements for my UI.

1. The ui should display one check box tree with search facility and able to add the nodes in between them. for that we wrote a small piece of code .but we are facing two problems with this code.

1. we could not add the nodes in between the other nodes.
2. when you are selecting a search node .. all the nodes are being selected.


please find the below UI screens and code ..

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.LinkedHashSet;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import multiuser.client.ui.actions.EscapeButtonAction;

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.swing.CheckBoxTree;
import com.jidesoft.swing.JideTitledBorder;
import com.jidesoft.swing.PartialEtchedBorder;
import com.jidesoft.swing.PartialSide;
import com.jidesoft.swing.SearchableUtils;
import com.jidesoft.tree.QuickTreeFilterField;
import com.jidesoft.tree.TreeUtils;


/***
*
*
* @author Krishna_Hotha
* @date 21 may 2009
*
* Class is used to Filter the information to be displayed
* In a tree
*
*/
public class FilterPanel extends JFrame {

/**
* @param args
*
*/
private CheckBoxTree _tree;
private static FilterPanel theInstance=null;

private QuickTreeFilterField filterData=new QuickTreeFilterField();

private LinkedHashSet<Object> selectedPaths=new LinkedHashSet<Object>();



public static FilterPanel getInstance(){
if(theInstance==null){

theInstance=new FilterPanel();
}

return theInstance;
}
private FilterPanel() {
// TODO Auto-generated constructor stub

EscapeButtonAction.trap((JComponent) this.getContentPane(), new EscapeButtonAction(this));
this.setSize(new Dimension(400,400));
}



public JPanel getDemoPanel(){

//JTabbedPane jpane=new JTabbedPane("Graphic");


JPanel childPanel=new JPanel(new BorderLayout(2,2));
JPanel masterPanel = new JPanel(new BorderLayout(6, 6));
//here it will compute and display the data for tree

_tree=displayTree();

masterPanel.add(getSearchPanel(), BorderLayout.BEFORE_FIRST_LINE);
masterPanel.add(getTreePanel());
masterPanel.add(getButtonPanel(),BorderLayout.PAGE_END);
childPanel.add(new JPanel(),BorderLayout.BEFORE_LINE_BEGINS);
childPanel.add(masterPanel,BorderLayout.CENTER);
childPanel.add(new JPanel(),BorderLayout.AFTER_LINE_ENDS);
childPanel.add(new JPanel(),BorderLayout.PAGE_END);
// masterPanel.add(new JPanel());
return childPanel;
}

public JPanel getSearchPanel(){

JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
quickSearchPanel.setBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Find", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP));
filterData=new QuickTreeFilterField(_tree.getModel());
filterData.setHideEmptyParentNode(true);
quickSearchPanel.add(filterData);

_tree = new CheckBoxTree(filterData.getDisplayTreeModel()) ;
_tree.setRootVisible(false);
_tree.setShowsRootHandles(true);

filterData.setTree(_tree);
SearchableUtils.installSearchable(_tree);
TreeUtils.expandAll(_tree, true);


return quickSearchPanel;
}

public JPanel getTreePanel(){

JPanel treePanel = new JPanel(new BorderLayout(2, 2));
treePanel.setBorder(BorderFactory.createCompoundBorder(
new JideTitledBorder(new PartialEtchedBorder(
PartialEtchedBorder.LOWERED, PartialSide.NORTH),
"Value Lever Information", JideTitledBorder.LEADING,
JideTitledBorder.ABOVE_TOP), BorderFactory
.createEmptyBorder(0, 0, 0, 0)));

treePanel.add(new JScrollPane(_tree));

return treePanel;


}
public JPanel getButtonPanel(){

JPanel _buttonPanel = new ButtonPanel();


JButton okButton = new JButton("Ok");
_buttonPanel.add(okButton, ButtonPanel.OTHER_BUTTON);


JButton cancelButton = new JButton("Cancel");
_buttonPanel.add(cancelButton, ButtonPanel.OTHER_BUTTON);


return _buttonPanel;

}



//code is used to display a tree
public CheckBoxTree displayTree(){


DefaultTreeModel treeModel=null;
DefaultMutableTreeNode root = new DefaultMutableTreeNode("VRM90");


for(int i=0;i<3;i++){
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child1");


for(int j=0;j<5;j++){
DefaultMutableTreeNode treeNode=new DefaultMutableTreeNode("subChild"+j);
child1.add(treeNode);
}

root.add(child1);

}


treeModel = new DefaultTreeModel(root);

if(treeModel!=null)
_tree=new CheckBoxTree(treeModel) ;


_tree.setRootVisible(false);
TreeUtils.expandAll(_tree, true);


return _tree;

}

/*
May 25, 2009
TODO// TODO Auto-generated method stub
*/

//static int count=0;



public static void main(String []args){


try
{

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
}
catch (Exception e)
{
e.printStackTrace();
}

FilterPanel fi=FilterPanel.getInstance();

fi.setTitle("VRM Filter Panel");

fi.setResizable(false);



fi.add(fi.getDemoPanel());



fi.setSize(new Dimension(400,400));
fi.setVisible(true);


}









public LinkedHashSet<Object> getSelectedPaths() {
return selectedPaths;
}



public void setSelectedPaths(LinkedHashSet<Object> selectedPaths) {
this.selectedPaths = selectedPaths;
}

}

Please help me out..
Attachments
ui1.JPG
after selection
ui1.JPG (32.65 KiB) Viewed 50312 times
ui.JPG
after filtering
ui.JPG (25.97 KiB) Viewed 50312 times
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Wed Jun 24, 2009 8:11 am

Please try use DefaultMutableTreeNode#insert() to insert a new node between existing nodes.

I'm sorry that I'm not quite understanding the second question you mentioned. From the image you post, I think it is a normal behavior, that all child nodes are selected when you try to select the parent node.

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

Re: how to insert a node to existing check box tree

Postby RajaRajeswari_V » Wed Jun 24, 2009 10:11 am

Hi,

The second question is

1.we implemented search facility for the sample dialog. if you see the second screen shot in the previous mail ,we can search the node by giving some input in search field and accordingly it is displaying the node information. but when we select the displayed node then all the siblinbs are being selected.that is shown in the first ui screen shot in the previous mail.

please help me out...
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Wed Jun 24, 2009 11:02 am

Do you mean the "Child1" is selected when you select "subChild1"? It is the default behavior for the CheckBoxTree. You could override CheckBoxTree#createHandler() to define your expected mouse clicking behavior.

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

Re: how to insert a node to existing check box tree

Postby RajaRajeswari_V » Wed Jun 24, 2009 12:15 pm

No. if i clicked on subchild1 then all the subchilds i.e subchild2 ,subchild3,subchild4 are getting selected.

For example ..consider the following tree

Child1
subchild1
subchild2
subchild3


if the user is searching for subchild1 ,he will give the same text in the search field . then following view will be displayed in the ui..

Child1
subchild1..

then the user selects the subchild1 then all the subchild2 ,subchild3 are getting selected.

to show this i attached the ui screens also.please help me out..
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: how to insert a node to existing check box tree

Postby RajaRajeswari_V » Wed Jun 24, 2009 12:29 pm

for more clarity if you see ui.jpg which was sent on earlier thread

case 1:

i am searching with child1 text in search field..

then it is showing the following information

child1

subchild1


then i selected the subchild1 ..then the child1 is also get selected which is normal tree behavior

case 2: please see the ui1.jpg

after that i changed the text to child... then the problem is coming ..previously i selected only subchild1 ...but it is showing all the subchild1 & subchild2 & subchild3 as selected..


i hope the problem is clear to you.. please help me out..
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Wed Jun 24, 2009 1:26 pm

Got you. For dependency reason, we will probably have to add a new CheckBoxTreeSelectionModel class for Filterable scenario. Will see if we can find a good solution soon.

For now, Please try the following code. I have tested that it could solve your issue although it is not perfect yet. Please let us know if you encounter any issue.

Code: Select all
/*
 * @(#)FilterPanel.java 6/24/2009
 *
 * Copyright 2002 - 2009 JIDE Software Inc. All rights reserved.
 *
 */

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.LinkedHashSet;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.swing.*;
import com.jidesoft.tree.QuickTreeFilterField;
import com.jidesoft.tree.TreeUtils;
import com.jidesoft.tree.FilterableTreeModel;


/**
 * @author Krishna_Hotha
 * @date 21 may 2009
 * <p/>
 * Class is used to Filter the information to be displayed In a tree
 */
public class FilterPanel extends JFrame {

    /**
     * @param args
     */
    private CheckBoxTree _tree;
    private static FilterPanel theInstance = null;

    private QuickTreeFilterField filterData = new QuickTreeFilterField();

    private LinkedHashSet<Object> selectedPaths = new LinkedHashSet<Object>();


    public static FilterPanel getInstance() {
        if (theInstance == null) {

            theInstance = new FilterPanel();
        }

        return theInstance;
    }

    private FilterPanel() {
// TODO Auto-generated constructor stub

//        EscapeButtonAction.trap((JComponent) this.getContentPane(), new EscapeButtonAction(this));
        this.setSize(new Dimension(400, 400));
    }


    public JPanel getDemoPanel() {

//JTabbedPane jpane=new JTabbedPane("Graphic");


        JPanel childPanel = new JPanel(new BorderLayout(2, 2));
        JPanel masterPanel = new JPanel(new BorderLayout(6, 6));
//here it will compute and display the data for tree

        _tree = displayTree();

        masterPanel.add(getSearchPanel(), BorderLayout.BEFORE_FIRST_LINE);
        masterPanel.add(getTreePanel());
        masterPanel.add(getButtonPanel(), BorderLayout.PAGE_END);
        childPanel.add(new JPanel(), BorderLayout.BEFORE_LINE_BEGINS);
        childPanel.add(masterPanel, BorderLayout.CENTER);
        childPanel.add(new JPanel(), BorderLayout.AFTER_LINE_ENDS);
        childPanel.add(new JPanel(), BorderLayout.PAGE_END);
// masterPanel.add(new JPanel());
        return childPanel;
    }

    public JPanel getSearchPanel() {

        JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
        quickSearchPanel.setBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Find", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP));
        filterData = new QuickTreeFilterField(_tree.getModel());
        filterData.setHideEmptyParentNode(true);
        quickSearchPanel.add(filterData);

        _tree = new CheckBoxTree(filterData.getDisplayTreeModel()) {
            @Override
            protected CheckBoxTreeSelectionModel createCheckBoxTreeSelectionModel(TreeModel model) {
                return new CheckBoxTreeSelectionModel(model) {
                    @Override
                    public void addSelectionPaths(TreePath[] paths) {
                        boolean old = isDigIn();
                        if (_tree.getModel() instanceof FilterableTreeModel) {
                            setDigIn(false);
                        }
                        super.addSelectionPaths(paths);
                        if (_tree.getModel() instanceof FilterableTreeModel) {
                            setDigIn(old);
                        }
                    }

                    @Override
                    public boolean isPartiallySelected(TreePath path) {
                        boolean result = super.isPartiallySelected(path);
                        if (!result && super.isPathSelected(path) && _tree.getModel() instanceof FilterableTreeModel && ((DefaultMutableTreeNode) path.getLastPathComponent()).getChildCount() > 0) {
                            if (((FilterableTreeModel) _tree.getModel()).getFilters() != null) {
                                result = true;
                            }
                        }
                        return result;
                    }

                    @Override
                    public boolean isPathSelected(TreePath path, boolean digIn) {
                        if (path == null) {
                            return false;
                        }

                        if (!digIn)
                            return super.isPathSelected(path);

                        TreePath parent = path;
                        while (parent != null && !super.isPathSelected(parent)) {
                            parent = parent.getParentPath();
                        }

                        if (parent != null) {
                            if (parent == path && _tree.getModel() instanceof FilterableTreeModel && ((DefaultMutableTreeNode) parent.getLastPathComponent()).getChildCount() > 0) {
                                return false;
                            }
                            else {
                                return true;
                            }
                        }

                        if (getModel() == null) {
                            return true;
                        }

                        Object node = path.getLastPathComponent();
                        if (getModel().getChildCount(node) == 0) {
                            return false;
                        }

                        // find out if all children are selected
                        boolean allChildrenSelected = true;
                        for (int i = 0; i < getModel().getChildCount(node); i++) {
                            Object childNode = getModel().getChild(node, i);
                            if (!isPathSelected(path.pathByAddingChild(childNode), true)) {
                                allChildrenSelected = false;
                                break;
                            }
                        }
                        // if all children are selected, let's select the parent path only
                        if (_tree.isCheckBoxVisible(path) && allChildrenSelected && !(_tree.getModel() instanceof FilterableTreeModel)) {
                            addSelectionPaths(new TreePath[]{path});
                        }
                        return allChildrenSelected;
                    }
                };
            }
        };
        _tree.setRootVisible(false);
        _tree.setShowsRootHandles(true);

        filterData.setTree(_tree);
        SearchableUtils.installSearchable(_tree);
        TreeUtils.expandAll(_tree, true);


        return quickSearchPanel;
    }

    public JPanel getTreePanel() {

        JPanel treePanel = new JPanel(new BorderLayout(2, 2));
        treePanel.setBorder(BorderFactory.createCompoundBorder(
                new JideTitledBorder(new PartialEtchedBorder(
                        PartialEtchedBorder.LOWERED, PartialSide.NORTH),
                        "Value Lever Information", JideTitledBorder.LEADING,
                        JideTitledBorder.ABOVE_TOP), BorderFactory
                .createEmptyBorder(0, 0, 0, 0)));

        treePanel.add(new JScrollPane(_tree));

        return treePanel;


    }

    public JPanel getButtonPanel() {

        JPanel _buttonPanel = new ButtonPanel();


        JButton okButton = new JButton("Ok");
        _buttonPanel.add(okButton, ButtonPanel.OTHER_BUTTON);


        JButton cancelButton = new JButton("Cancel");
        _buttonPanel.add(cancelButton, ButtonPanel.OTHER_BUTTON);


        return _buttonPanel;

    }


    //code is used to display a tree
    public CheckBoxTree displayTree() {


        DefaultTreeModel treeModel = null;
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("VRM90");


        for (int i = 0; i < 3; i++) {
            DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child1");


            for (int j = 0; j < 5; j++) {
                DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode("subChild" + j);
                child1.add(treeNode);
            }

            root.add(child1);

        }


        treeModel = new DefaultTreeModel(root);

        if (treeModel != null)
            _tree = new CheckBoxTree(treeModel);


        _tree.setRootVisible(false);
        TreeUtils.expandAll(_tree, true);


        return _tree;

    }

/*
May 25, 2009
TODO// TODO Auto-generated method stub
*/

//static int count=0;


    public static void main(String[] args) {


        try {

            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        FilterPanel fi = FilterPanel.getInstance();

        fi.setTitle("VRM Filter Panel");

        fi.setResizable(false);


        fi.add(fi.getDemoPanel());


        fi.setSize(new Dimension(400, 400));
        fi.setVisible(true);


    }


    public LinkedHashSet<Object> getSelectedPaths() {
        return selectedPaths;
    }


    public void setSelectedPaths(LinkedHashSet<Object> selectedPaths) {
        this.selectedPaths = selectedPaths;
    }

}


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

Re: how to insert a node to existing check box tree

Postby jamindhar » Wed Jun 24, 2009 9:10 pm

it solved my problem. but again it is giving one more problem.

i can select all the selects all the childs by clicking their parent node. but to remove if i click on the parent node it is not changing it state.. i.e consider the follwoing tree

child1

subchild1
subchild2
subchild3

if click on child1 then all the subchilds are selecting.but if i am trying to unselect child1 it is not working ...please help me out
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Thu Jun 25, 2009 6:44 am

Please try change the line in method isPathSelected() from

Code: Select all
                            if (parent == path && _tree.getModel() instanceof FilterableTreeModel && ((DefaultMutableTreeNode) parent.getLastPathComponent()).getChildCount() > 0) {

to
Code: Select all
                            if (parent == path && _tree.getModel() instanceof FilterableTreeModel && ((DefaultMutableTreeNode) parent.getLastPathComponent()).getChildCount() > 0 && ((FilterableTreeModel) _tree.getModel()).getFilters().length > 0) {


Although it's still not perfect enough, it is what we can do best right now. We will consider add a new selectionModel class to address this issue.

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

Re: how to insert a node to existing check box tree

Postby JIDE Support » Mon Jun 29, 2009 8:58 pm

Just so you know, this bug is fixed in 2.6.7 which was just released.

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

Re: how to insert a node to existing check box tree

Postby jamindhar » Tue Jun 30, 2009 5:47 am

Thank q for considering my request. today i downloaded the jide version and evaluted. it solved my problem but one problem is coming with this code. it is allowing me to select n-1 nodes only.not n node.

For example

Root
child1
child2
child3
are there .i am able to any of two childs . if i am trying to select all the child nodes then it is giving the following exception

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.jidesoft.tree.FilterableCheckBoxTreeSelectionModel.a(Unknown Source)
at com.jidesoft.tree.FilterableCheckBoxTreeSelectionModel.areSiblingsSelected(Unknown Source)
at com.jidesoft.swing.CheckBoxTreeSelectionModel.addSelectionPaths(Unknown Source)
at com.jidesoft.tree.FilterableCheckBoxTreeSelectionModel.addSelectionPaths(Unknown Source)
at javax.swing.tree.DefaultTreeSelectionModel.addSelectionPath(DefaultTreeSelectionModel.java:303)
at com.jidesoft.swing.CheckBoxTree$Handler.toggleSelection(Unknown Source)
at com.jidesoft.swing.CheckBoxTree$Handler.mousePressed(Unknown Source)
at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:262)
at java.awt.Component.processMouseEvent(Component.java:6131)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3265)
please help me out..

Code: Select all
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.LinkedHashSet;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

import com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.swing.*;
import com.jidesoft.tree.FilterableCheckBoxTreeSelectionModel;
import com.jidesoft.tree.QuickTreeFilterField;
import com.jidesoft.tree.TreeUtils;
import com.jidesoft.tree.FilterableTreeModel;


/**
* @author Krishna_Hotha
* @date 21 may 2009
* <p/>
* Class is used to Filter the information to be displayed In a tree
*/
public class FilterTree extends JFrame {

    /**
     * @param args
     */
    private CheckBoxTree _tree;
   
    private static FilterTree theInstance = null;

    private QuickTreeFilterField filterData = new QuickTreeFilterField();

    private LinkedHashSet<Object> selectedPaths = new LinkedHashSet<Object>();


    public static FilterTree getInstance() {
        if (theInstance == null) {

            theInstance = new FilterTree();
        }

        return theInstance;
    }

    public FilterTree() {
// TODO Auto-generated constructor stub

//        EscapeButtonAction.trap((JComponent) this.getContentPane(), new EscapeButtonAction(this));
        this.setSize(new Dimension(400, 400));
    }


    public JPanel getDemoPanel() {

//JTabbedPane jpane=new JTabbedPane("Graphic");


        JPanel childPanel = new JPanel(new BorderLayout(2, 2));
        JPanel masterPanel = new JPanel(new BorderLayout(6, 6));
//here it will compute and display the data for tree

       

        masterPanel.add(getSearchPanel(displayTree()), BorderLayout.BEFORE_FIRST_LINE);
        masterPanel.add(getTreePanel());
        masterPanel.add(getButtonPanel(), BorderLayout.PAGE_END);
        childPanel.add(new JPanel(), BorderLayout.BEFORE_LINE_BEGINS);
        childPanel.add(masterPanel, BorderLayout.CENTER);
        childPanel.add(new JPanel(), BorderLayout.AFTER_LINE_ENDS);
        childPanel.add(new JPanel(), BorderLayout.PAGE_END);
// masterPanel.add(new JPanel());
        return childPanel;
    }

    public JPanel getSearchPanel(DefaultTreeModel dfdm) {

        JPanel quickSearchPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
        quickSearchPanel.setBorder(new JideTitledBorder(new PartialEtchedBorder(PartialEtchedBorder.LOWERED, PartialSide.NORTH), "Find", JideTitledBorder.LEADING, JideTitledBorder.ABOVE_TOP));
        filterData = new QuickTreeFilterField(dfdm);
        filterData.setHideEmptyParentNode(true);
        quickSearchPanel.add(filterData);

       _tree = new CheckBoxTree(filterData.getDisplayTreeModel()) {
            @Override
            protected CheckBoxTreeSelectionModel createCheckBoxTreeSelectionModel(TreeModel model) {
                return new FilterableCheckBoxTreeSelectionModel(model) ;
            }
                 
                   
        };
        _tree.setRootVisible(false);
        _tree.setShowsRootHandles(true);

        filterData.setTree(_tree);
        SearchableUtils.installSearchable(_tree);
        TreeUtils.expandAll(_tree, true);


        return quickSearchPanel;
    }

    public JPanel getTreePanel() {

        JPanel treePanel = new JPanel(new BorderLayout(2, 2));
        treePanel.setBorder(BorderFactory.createCompoundBorder(
                new JideTitledBorder(new PartialEtchedBorder(
                        PartialEtchedBorder.LOWERED, PartialSide.NORTH),
                        "Value Lever Information", JideTitledBorder.LEADING,
                        JideTitledBorder.ABOVE_TOP), BorderFactory
                .createEmptyBorder(0, 0, 0, 0)));

        treePanel.add(new JScrollPane(_tree));

        return treePanel;


    }

    public JPanel getButtonPanel() {

        JPanel _buttonPanel = new ButtonPanel();


        JButton okButton = new JButton("Ok");
        _buttonPanel.add(okButton, ButtonPanel.OTHER_BUTTON);

        okButton.addActionListener(new ActionListener(){

         public void actionPerformed(ActionEvent e) {
            // TODO Auto-generated method stub
            
            DefaultTreeModel dpdm=(DefaultTreeModel)filterData.getTreeModel();
             if (_tree.getSelectionPath() != null) {
                       TreePath treePath = _tree.getSelectionPath();
                       DefaultMutableTreeNode node = (DefaultMutableTreeNode) treePath.getLastPathComponent();
                      
                       dpdm.insertNodeInto(new DefaultMutableTreeNode("he"), node, 0);
             }
            //dpdm.nodeChanged( new DefaultMutableTreeNode(dpdm.getRoot().toString()));
            
            /*_tree.setModel(dpdm);
            _tree.updateUI();*/
         }
           
           
        });
        JButton cancelButton = new JButton("Cancel");
        _buttonPanel.add(cancelButton, ButtonPanel.OTHER_BUTTON);


        return _buttonPanel;

    }


    //code is used to display a tree
    public DefaultTreeModel displayTree() {


        DefaultTreeModel treeModel = null;
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("VRM90");


        for (int i = 0; i < 3; i++) {
            DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child1");


            for (int j = 0; j < 5; j++) {
                DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode("subChild" + j);
                child1.add(treeNode);
            }

            root.add(child1);

        }


        treeModel = new DefaultTreeModel(root);

       

        return treeModel;

    }

/*
May 25, 2009
TODO// TODO Auto-generated method stub
*/

//static int count=0;


    public static void main(String[] args) {


        try {

            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        FilterTree fi = FilterTree.getInstance();

        fi.setTitle("VRM Filter Panel");

        fi.setResizable(false);


        fi.add(fi.getDemoPanel());


        fi.setSize(new Dimension(400, 400));
        fi.setVisible(true);


    }


    public LinkedHashSet<Object> getSelectedPaths() {
        return selectedPaths;
    }


    public void setSelectedPaths(LinkedHashSet<Object> selectedPaths) {
        this.selectedPaths = selectedPaths;
    }

}


Attachments
test.JPG
test.JPG (31.82 KiB) Viewed 50288 times
jamindhar
 
Posts: 18
Joined: Mon Aug 25, 2008 11:53 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Tue Jun 30, 2009 7:13 am

Will fix it in next release. Please try the following code for now to work around.

Code: Select all
        _tree = new CheckBoxTree(filterData.getDisplayTreeModel()) {
            @Override
            protected CheckBoxTreeSelectionModel createCheckBoxTreeSelectionModel(TreeModel model) {
                return new FilterableCheckBoxTreeSelectionModel(model) {
                    @Override
                    protected boolean areSiblingsSelected(TreePath path) {
                        return path.getParentPath() != null && super.areSiblingsSelected(path);
                    }
                };
            }
        };


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

Re: how to insert a node to existing check box tree

Postby RajaRajeswari_V » Tue Jun 30, 2009 8:30 am

but as per my knowledge areSiblingsSelected(TreePath path) method is private right?.then the following code will give the error.please clarify
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Tue Jun 30, 2009 8:32 am

It was changed to "protected" since 2.6.7 to implement this class. I have tested this code before I post it. Please give it a try.

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

Re: how to insert a node to existing check box tree

Postby RajaRajeswari_V » Tue Jun 30, 2009 9:14 am

its working fine.but it is giving problem when i unselected the filtered item..

For example

Child1
Subchild1
Subchild2
Subchild3


step 1: select child1 it will selects all the childs...

step 2: search for subchild3

step 3: Then it will display child1>subchild1 with selected state..

step4 : then unselect selected state for subchild 1 and search for different sub child ..then all the subchilds are unselected :(

Please help me out
RajaRajeswari_V
 
Posts: 25
Joined: Tue Apr 28, 2009 8:33 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Tue Jun 30, 2009 12:48 pm

It is as expected. It also happens if you use normal table selection model. We don't have a mechanism to restore the selection before filtering so far and I'm afraid we will not have a short term plan for this either.

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

Re: how to insert a node to existing check box tree

Postby JIDE Support » Mon Jul 20, 2009 10:30 pm

Just so you know, this is fixed in 2.7.0 which was just released.

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

Re: how to insert a node to existing check box tree

Postby vibhor » Fri Mar 26, 2010 1:59 am

Hi ,
I am facing a similar issue .When I make selections in my Checkboxtree and type something in the search panel,the tree changes .When i clear the text in the search panel the tree reappears but the selections disappear . I tried with jide 2.8.5
and 2.6.1 but of no use.
Please help me with this.
vibhor
 
Posts: 5
Joined: Wed Mar 24, 2010 10:54 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Sat Mar 27, 2010 8:44 am

We will fix it in both 2.8.6 and 2.9.0.

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

Re: how to insert a node to existing check box tree

Postby vibhor » Mon Mar 29, 2010 3:13 am

Hi,
In the thread below, you have mentioned that it is fixed in 2.7.0 but it is still giving the same issues. Please let me know when this can be fixed or suggest some workaround.
vibhor
 
Posts: 5
Joined: Wed Mar 24, 2010 10:54 pm

Re: how to insert a node to existing check box tree

Postby JIDE Support » Mon Mar 29, 2010 3:55 pm

Sorry for the confusion. However, we did mention the NPE issue which was fixed in 2.7.0. Please check out the change log for 2.7.0 at http://www.jidesoft.com/history/. In the previous post, you would see that we didn't find a good solution for this issue at that time.

(Grids) Fixed the NPE issue while selecting the last node while CheckBoxTree implements FilterableCheckBoxTreeSelectionModel.

Thanks for triggering this issue out again. We were able to re-consider this issue and figured out a solution eventually. Will let you know when 2.8.6 or 2.9.0 is released. They should be ready in two weeks.

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

Re: how to insert a node to existing check box tree

Postby JIDE Support » Tue Apr 06, 2010 3:22 pm

Just so you know, 2.8.6 is released. In this release, if you use FilterableCheckBoxTreeSelectionModel, the issue vibhor raised has been solved.

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

Re: how to insert a node to existing check box tree

Postby vibhor » Sun Apr 18, 2010 10:57 pm

Hi,
I downloaded the 2.8.6 version of jide. I tried running a simple example by making some changes in the G15.QuickFilter example.I changed the tree to CheckBox Tree and changed the selectionModel to FilterableCheckBoxTreeSelectionModel. Two Observations:

1) There is a treeModelListener attached to the tree which updtaes the label whenever the tree is filtered. The selections are retianed only if i use this. If i remove it the selections are gone. Please help me understand what does this code exactly do.

2) When i set the digIn to false and filter the tree , i am able to select/deselect the Child
POC.java
(6.67 KiB) Downloaded 1358 times
but not the Parent . It was not the same in earlier version. If my tree is:

*Root
->First
->Second
->Third
->Child1
->Child2
->Child3

If i filter Child1, then i am able to select/deselect Child1 but not its parent(Third). Please help me with this.

Thanks
Vibhor
vibhor
 
Posts: 5
Joined: Wed Mar 24, 2010 10:54 pm

Next

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

Who is online

Users browsing this forum: No registered users and 73 guests