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 mgarin » Thu Sep 05, 2013 1:23 pm

I will also add my own checkbox tree implementation in WebLaF:
https://github.com/mgarin/weblaf/issues/31
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby mgarin » Tue Oct 01, 2013 1:24 pm

I did not find any convinient way to support Jide tristate checkbox yet.
Maybe i will be able to add it after some more checbox UI changes, but i am not sure about that.

Anyway, you can now find a working tristate checkbox and checkbox tree in WebLaF:
https://github.com/mgarin/weblaf/releases/tag/v1.22
Those two components works similar to Jide ones, but have more options and are properly styled :)
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 » Thu Oct 03, 2013 12:28 pm

Thanks Mikle,

Is it possible to have a method that return e.g. getWebCheckBoxTreeSelectionModel (extended from DefaultTreeSelectionModel). this will help in some cases e.g. getSelectionPaths()
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Thu Oct 03, 2013 1:00 pm

Unlike Jide folks i have separated selection and "checking" models and made my own "TreeCheckingModel" interface which has a default implementation - "DefaultTreeCheckingModel". That made tree code structure much easier to edit, improve and understand. That model holds checkbox states and also contains their check/uncheck logic.

You can get that model by simply calling:
Code: Select all
checkBoxTree.getCheckingModel ();


Its not perfect yet and i am going to add some more options to retrieve check states from the tree and to set them back (separately and all at once) in next update, so hold tight :)
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby mgarin » Thu Oct 03, 2013 1:51 pm

By the way, these are methods which will be added in next update:
Code: Select all
    /**
     * Returns list of checked nodes.
     *
     * @return list of checked nodes
     */
    public List<E> getCheckedNodes ();

    /**
     * Returns list of nodes in mixed state.
     *
     * @return list of nodes in mixed state
     */
    public List<E> getMixedNodes ();

    /**
     * Sets specified nodes state to checked.
     *
     * @param nodes nodes to check
     */
    public void setChecked ( Collection<E> nodes );

    /**
     * Sets specified nodes state to unchecked.
     *
     * @param nodes nodes to uncheck
     */
    public void setUnchecked ( Collection<E> nodes );

Similar methods will be added into TreeCheckingModel interface (and their implementations in DefaultTreeCheckingModel as well).

I guess that should be more than enough to work with checkbox tree without any problems.
Though maybe you want to have some other "assistant" methods?
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 » Thu Oct 03, 2013 8:53 pm

One major method is to get the selected paths. I'm not able to get it.
Do i need to getCheckingModel() then test all the nodes status.
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Thu Oct 03, 2013 9:17 pm

You mean the checked paths?

Don't forget that we are talking about a tree - its has its own selection (simply nodes which you have selected). Atop of that checkbox tree has checked nodes (nodes with checkboxes in "checked" state).

And if you were talking about checked paths - starting with next update you will be able to get them all at once - see the method i posted in a code quote above.
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 » Fri Oct 04, 2013 4:41 am

getCheckedNodes() will do that but it will return list of nodes, so to get the path you need to extract the path from each node. it might be useful to have one function that will return all checked TreePath[]
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Fri Oct 04, 2013 9:35 am

I will add that one as well.

Though i don't know what for do you need paths - Web-trees got tons of methods to avoid working with paths so that you can use nodes directly to select/add/remove/edit any tree path.
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 » Fri Oct 04, 2013 10:09 am

Thanks again

you are right in this, it just happens that jide does not have this function to return selected nodes but instead selected paths. maybe i need to change my code a bit to align it with your implementation.
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Fri Oct 04, 2013 12:26 pm

Well, the point is that default Swing JTree forces you to work with paths which is not very convenient and takes a lot of additional coding in some cases. Jide also went that way and didn't add anything special.

For example here is the code to take selected values from Swing/Jide tree:
Code: Select all
List<E> values = new ArrayList<E> ();
for ( TreePath treePath : tree.getSelectionPaths () )
{
    values.add ( ( E ) treePath.getLastPathComponent () );
}
I even skipped the "null" paths check - add it and you will have like 7 lines of code to simply get selected values from your tree. Now imagine that you have to do something more complicated - such kind of coding might become a real pain.

I tried to add as much additional (helper) methods in WebTree/WebAsyncTree/WebCheckBoxTree as i could imagine. Here is the same example for WebTree:
Code: Select all
List<E> values = webTree.getSelectedNodes ();

Basically what you usually have in Swing/Jide tree:
[ your code ] -> [ tree (working with paths/rows) ] -> [ tree model (working with nodes) ]
And what i have added in that scheme is:
[ your code ] -> [ tree (working with paths/rows/nodes) ] -> [ tree model (working with nodes) ]

So you are free to choose what you want to work with - if paths are more convenient for you - use them, if you like nodes more - use them instead.
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 » Thu Oct 10, 2013 9:15 pm

is there a function similar to setDigIn(boolean);
If the CheckBoxTree is in dig-in mode, checking the parent node will check all the children. Correspondingly, getSelectionPaths() will only return the parent tree path. If not in dig-in mode, each tree node can be checked or unchecked independently

in this case we will have normal checkbox and not tristate one
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Fri Oct 11, 2013 2:18 pm

It was implemented, but i forgot to make a "bridge" method, my bad.
There was only "isRecursiveCheckingEnabled ()" method in the tree.

There will be an option in WebCheckBoxTree with next update:
Code: Select all
setRecursiveChecking ( boolean enabled )

It will have the same effect on the tree as "setDigIn (...)" method.

Though i'm not sure whether i should or should not return sub-nodes of checked node (when setRecursiveChecking is set to true) like Jide checkbox tree does. For now i return all checked nodes - doesn't matter if their parent is also checked or not. Basically - i do not exclude checked nodes placed inside other checked node.
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 » Fri Oct 11, 2013 3:45 pm

in jide, if all the child are checked, only the parent path (one node) is returned. when setDigIn (false), it will return everything since each node (parent or child) is considered as its own.
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Fri Oct 11, 2013 4:16 pm

I know, but i am not sure whether its the best behavior or not :)
You might still want to get all checked nodes, not just their parent checked nodes.
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 » Fri Oct 11, 2013 5:51 pm

how about an option to optimize the checked nodes e.g. if getCheckedNodes(boolean optimize) set to true, the result will be only the parent node (all of its child are checked). in case of false it will return the same results as when using setRecursiveChecking(false).
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Fri Oct 11, 2013 6:44 pm

That is good idea! :)
I will add that method in the update as well.

By the way, there will be two more features added - you will now be able to hide/disable checkboxes on some specific nodes by providing StateProvider into WebCheckBoxTree for each state. StateProvider is a new interface that returns boolean value for value of custom type.
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 13, 2013 6:11 pm

How can i hide the checkbox for the root node. i tried the following but it is not working:

Code: Select all
final WebCheckBoxTree tree= new WebCheckBoxTree(new DefaultTreeModel(rootNode))
{
   public boolean isCheckBoxVisible(DefaultMutableTreeNode node)
   {
                return(!node.isRoot());
   }
};
Abu Abdullah
 
Posts: 41
Joined: Tue Apr 17, 2012 12:11 pm

Re: CheckBoxTree support

Postby mgarin » Mon Oct 14, 2013 10:45 am

It wasn't implemented in a few places so yes, in old version that method is kinda bugged.

Here is how you will be able to do it in next version:
Code: Select all
final WebCheckBoxTree checkBoxTree = new WebCheckBoxTree ();
checkBoxTree.setCheckBoxVisibleStateProvider ( new StateProvider<DefaultMutableTreeNode> ()
{
    @Override
    public boolean provide ( DefaultMutableTreeNode node )
    {
        return !node.isRoot ();
    }
} );

Similar provider for enabling/disabling separate checkboxes:
Code: Select all
checkBoxTree.setCheckBoxEnabledStateProvider ( new StateProvider<DefaultMutableTreeNode> ()
{
    @Override
    public boolean provide ( DefaultMutableTreeNode node )
    {
        return !node.isRoot ();
    }
} );
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: CheckBoxTree support

Postby mgarin » Tue Oct 15, 2013 4:20 pm

All features i mentioned above are now available in v1.24 release:
https://github.com/mgarin/weblaf/releases/tag/v1.24
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

PreviousNext

Return to Suggestions

Who is online

Users browsing this forum: No registered users and 1 guest

cron