Hi to all,

I'm working with a GUI based on treeView and I found a problem:

If two TreeNode have the same text AND a comparator is defined for the TreeBranch they belong, then is impossible to select (by mouse o by arrow key) one of them.

Try this code:

------------------------------------------------------------------------

package test;

import java.util.Comparator;
import org.apache.pivot.collections.ArrayList;
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.Map;
import org.apache.pivot.wtk.Application;
import org.apache.pivot.wtk.DesktopApplicationContext;
import org.apache.pivot.wtk.Display;
import org.apache.pivot.wtk.TreeView;
import org.apache.pivot.wtk.Window;
import org.apache.pivot.wtk.content.TreeBranch;
import org.apache.pivot.wtk.content.TreeNode;

public class Main implements Application {

    private Window window         = new Window();
    private TreeView treeView     = new TreeView();
    private TreeBranch treeBranch = new TreeBranch();
    private TreeNode treeNodeA    = new TreeNode();
    private TreeNode treeNodeB    = new TreeNode();
    private TreeNode treeNodeC    = new TreeNode();

    Comparator<TreeNode> cmpTreeNode = new Comparator<TreeNode>(){

        @Override
        public int compare(TreeNode a, TreeNode b) {

            return (a.getText().compareToIgnoreCase(b.getText()));
        }
    };

    @Override
public void startup(Display display, Map<String, String> properties) throws Exception {

        treeNodeA.setText("Description A"); // SAME DESCRIPTION
        treeNodeA.setUserData("1");

        treeNodeB.setText("Description B");
        treeNodeB.setUserData("2");

        treeNodeC.setText("Description A");     // SAME DESCRIPTION
        treeNodeC.setUserData("3");

        treeBranch.add(treeNodeA);
        treeBranch.add(treeNodeB);
        treeBranch.add(treeNodeC);

        treeBranch.setText("TB1");
        treeBranch.setComparator(cmpTreeNode);

        List<TreeBranch> tb = new ArrayList();

        tb.add(treeBranch);

        treeView.setTreeData(tb);

        window.setContent(treeView);

        window.open(display);
    }

////////////////////////////////////////////////////////////////////////////////

    @Override
    public boolean shutdown(boolean optional) {

        if (window != null) window.close();

        return false;
    }

////////////////////////////////////////////////////////////////////////////////

    @Override
    public void suspend() {}

////////////////////////////////////////////////////////////////////////////////

    @Override
    public void resume() {}

////////////////////////////////////////////////////////////////////////////////

    public static void main(String[] args) {

args = new String[]{"--width=200", "--height=200", "--center=true"};

        DesktopApplicationContext.main(Main.class, args);
    }
}

------------------------------------------------------------------------

If you remove:

treeBranch.setComparator(cmpTreeNode);

everything is fine.



Stefano


--
Dr. Stefano Sancese

WatchGuard Certified System Professional - http://www.watchguard.com
Socio Clusit - Associazione Italiana per la Sicurezza Informatica

************************************************************************

In God we trust, all others we monitor (National Security Agency)

************************************************************************

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to