pivot-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Edvin Syse <ed...@sysedata.no>
Subject Re: Avoid "double click signal" when expanding and collapsing a branch in a TreeViewer
Date Wed, 15 Jun 2011 16:52:00 GMT
Den 15.06.2011 18:35, skrev Greg Brown:
> Why might you need to know what type of skin is installed on a component? Maybe there
is another alternative that might address your use case?

My use case is to avoid the problem described in the subject. I don't 
want to edit when I double click the branch controls (double clicking 
happens when you collapse and expand in rapid succession). I wrote a 
utility class that I install on the TreeView like this:

getComponentMouseButtonListeners().add(new DoubleClickTreeAdapter(this) {
     public void doubleClicked(TreeNode node) {

The doubleClicked() callback is invoked when an actual double click 
occured. editNode() opens my editor for the current node, this is _not_ 
an inline editor, it opens a BoxPane with a Form and some other stuff 
inside a TabPane to the right of the TreeView.

The DoubleClickTreeAdapter.java looks like this:

public abstract class DoubleClickTreeAdapter implements 
ComponentMouseButtonListener {
     private TreeView treeView;

     public DoubleClickTreeAdapter(TreeView treeView) {
         this.treeView = treeView;

     public boolean mouseClick(Component component, Mouse.Button button, 
int x, int y, int count) {
         if (count == 2 && button == Mouse.Button.LEFT) {
             Sequence.Tree.Path path = treeView.getNodeAt(y);
             if (path != null) {
                 TreeNode node = (TreeNode) 
Sequence.Tree.get(treeView.getTreeData(), path);
                 if (node instanceof TreeBranch) {

                         Integer indent = (Integer) 
                         Integer spacing = (Integer) 
                         int baseNodeX = path.getLength() * (indent + 
                         if (x > baseNodeX)
                     } else {
                         // Add support for other skins here, default to 
allow double click anywhere for unknown skins
                 } else {
         } else if (count == 1 && treeView.getNodeAt(y) == null)
         return true;

     public abstract void doubleClicked(TreeNode node);

As you can see, I check that the TreeViewSkin is infact 
TerraTreeViewSkin, so that I know I can relay on the indent and spacing 
to determine if I clicked on or to the left of a branch control, or on 
the actual node icon/text.

I will default to call doubleClicked() if there is a non-standard skin 
installed, but I can easily add more checks for different skins.

(I removed the empty mouseDown/mouseUp calls from the code above).

-- Edvin

View raw message