CheckBoxTree support

Request new features and improvements you want to see in WebLaF.
I will answer any request so don't hesitate and post it!

Re: CheckBoxTree support

Postby Abu Abdullah » Sat Oct 19, 2013 9:06 am

How can we Listen to the checkbox state changes. There is no Listener attached to the TreeCheckingModel
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Mon Oct 21, 2013 2:00 pm

Good point.

I have added the listener into both - tree and TreeCheckingModel.
You can simply specify the listener for the tree and it will be passed into the model.
Here is an example demostrating new listener:
Code: Select all
public class ForQuickTests
{
    public static void main ( String[] args )
    {
        WebLookAndFeel.install ();

        WebCheckBoxTree webCheckBoxTree = new WebCheckBoxTree ();
        webCheckBoxTree.addCheckStateChangeListener ( new CheckStateChangeListener<DefaultMutableTreeNode> ()
        {
            @Override
            public void checkStateChanged ( List<CheckStateChange<DefaultMutableTreeNode>> checkStateChanges )
            {
                for ( CheckStateChange change : checkStateChanges )
                {
                    System.out.println ( change.getNode () + ": " + change.getOldState () + " -> " + change.getNewState () );
                }
                System.out.println ( "========================" );
            }
        } );

        TestFrame.show ( new WebScrollPane ( webCheckBoxTree, false ) );
    }
}


This listener will be available in next (v1.25) version.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby Abu Abdullah » Sun Oct 27, 2013 1:43 pm

Hi,

tree.getCheckedNodes(true) results is not optimized

Code: Select all

   public Test()
   {
     DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
     DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child 1");
     root.add(child1);
     DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child 2");
     root.add(child2);
   
     final WebCheckBoxTree tree = new WebCheckBoxTree(root);
    tree.addCheckStateChangeListener ( new CheckStateChangeListener<DefaultMutableTreeNode> ()
            {
                @Override
                public void checkStateChanged ( List<CheckStateChange<DefaultMutableTreeNode>> checkStateChanges )
                {
               final java.util.List<DefaultMutableTreeNode> checkedNodes = tree.getCheckedNodes(true);
                   
                        for(final DefaultMutableTreeNode node : checkedNodes)
                        {
                            System.out.println(Arrays.toString(node.getPath()));
                            }
                     System.out.println ( "========================" );
                }
            } );
     setDefaultCloseOperation(EXIT_ON_CLOSE);
     setSize(200, 200);
     getContentPane().add(tree);
   
     setVisible(true);
   }

Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Sun Oct 27, 2013 3:32 pm

Yep, i already found and fixed that.
Should be fine in tomorrow's v1.25 version.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby mgarin » Mon Oct 28, 2013 8:43 pm

You can now find fix for this issue in v1.25 release:
https://github.com/mgarin/weblaf/releases/tag/v1.25
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby ianp » Wed Oct 30, 2013 7:04 pm

I have a fix for the NPE problem on Github, are you interested in pull requests?
ianp
 
Posts: 2
Joined: Fri Oct 25, 2013 7:28 pm

Re: CheckBoxTree support

Postby mgarin » Thu Oct 31, 2013 2:19 pm

ianp, Yes, just noticed it, thanks! :)
I have added a comment there - check it when you will have some free time:
https://github.com/mgarin/weblaf/pull/51
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Previous

Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron