Issues with Filterable 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.

Issues with Filterable CheckBoxTree

Postby KkOo » Wed May 12, 2010 5:19 am

Hello there,

I am trying to use CheckBoxTree along with QuickTreeFilterField and i am facing little annoying issues.
Say i have this tree :

- Child1
    - sChild11
    - sChild12
    - sChild13
- Child2
    - sChild21
    - sChild22

First issue is:
- check sChild22
- filter the tree by "sChild1"
- check sChild12
- clear the filter
After clearing the field, we can see that we lost the previous check :(

Second issue is:
- filter by "sChild2"
- check Child2
- clear the filter
Again, after clearing, we can see that all the tree got checked :?

It seems that i was able to fix the second problem by overwriting CheckBoxTreeSelectionModel#areSiblingsSelected(TreePath path).
But I dont know how to handle the first one. I tried to pass the original tree model to the constructor of CheckBoxTreeSelectionModel but it doesnt work.
You can see both of theses attempt in the code bellow:

Code: Select all
CheckBoxTree tree = new CheckBoxTree((Hashtable) values) {

    protected CheckBoxTreeSelectionModel createCheckBoxTreeSelectionModel(TreeModel model) {
        return new CheckBoxTreeSelectionModel(rawTreeModel) {

            @Override
            protected boolean areSiblingsSelected(TreePath path) {
                if (filterField.getDisplayTreeModel().isFiltersApplied())
                    return false;
                return super.areSiblingsSelected(path);
            }
        };
    }
};
rawTreeModel = tree.getModel();


Anyone could advise me ?

Thanks !
KkOo
 
Posts: 7
Joined: Wed May 12, 2010 4:47 am

Re: Issues with Filterable CheckBoxTree

Postby KkOo » Wed May 12, 2010 8:30 am

Sorry for the quick post.
I used the the FilterableCheckBoxTreeSelectionModel instead and the problem 1 gone away.

But the second one is still here...
KkOo
 
Posts: 7
Joined: Wed May 12, 2010 4:47 am

Re: Issues with Filterable CheckBoxTree

Postby KkOo » Wed May 12, 2010 9:04 am

Dont mind me, If i use the latest version of jide evreything is working correctly :)
Sorry for disturbing you guys
KkOo
 
Posts: 7
Joined: Wed May 12, 2010 4:47 am

Re: Issues with Filterable CheckBoxTree

Postby JIDE Support » Wed May 12, 2010 10:55 am

I don't really see the problem in a test case we received from another user. It is very similar to what you have.

Code: Select all
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 com.jidesoft.dialog.ButtonPanel;
import com.jidesoft.swing.*;
import com.jidesoft.tree.QuickTreeFilterField;
import com.jidesoft.tree.TreeUtils;
import com.jidesoft.tree.FilterableCheckBoxTreeSelectionModel;


public class FilterableCheckBoxTreeSelection extends JFrame {

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

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


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

            theInstance = new FilterableCheckBoxTreeSelection();
        }

        return theInstance;
    }

    private FilterableCheckBoxTreeSelection() {
// 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));
        QuickTreeFilterField filterData = new QuickTreeFilterField(_tree.getModel());
        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);


        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;
        DefaultMutableTreeNode root = new DefaultMutableTreeNode("VRM90");


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


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

            root.add(child1);

        }


        treeModel = new DefaultTreeModel(root);

        _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();
        }

        FilterableCheckBoxTreeSelection fi = FilterableCheckBoxTreeSelection.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;
    }

}
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 64 guests