]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add mouse event details to Tree.ItemClick (#9599)
authorHenri Sara <henri.sara@gmail.com>
Wed, 28 Jun 2017 10:41:46 +0000 (13:41 +0300)
committerGitHub <noreply@github.com>
Wed, 28 Jun 2017 10:41:46 +0000 (13:41 +0300)
This provides a way to get the mouse button clicked as
requested in #9335.

server/src/main/java/com/vaadin/ui/Tree.java

index cd53d1bc08c567b9733db22a66c0ceca2b3ad877..6ae86efe3711ebd3883933526301f7c920112942 100644 (file)
@@ -40,6 +40,7 @@ import com.vaadin.event.SerializableEventListener;
 import com.vaadin.event.selection.SelectionListener;
 import com.vaadin.server.ErrorMessage;
 import com.vaadin.server.Resource;
+import com.vaadin.shared.MouseEventDetails;
 import com.vaadin.shared.Registration;
 import com.vaadin.shared.ui.ContentMode;
 import com.vaadin.shared.ui.grid.HeightMode;
@@ -101,6 +102,7 @@ public class Tree<T> extends Composite
     public static class ItemClick<T> extends ConnectorEvent {
 
         private final T item;
+        private final MouseEventDetails mouseEventDetails;
 
         /**
          * Constructs a new item click.
@@ -109,10 +111,15 @@ public class Tree<T> extends Composite
          *            the tree component
          * @param item
          *            the clicked item
+         * @param mouseEventDetails
+         *            information about the original mouse event (mouse button
+         *            clicked, coordinates if available etc.)
          */
-        protected ItemClick(Tree<T> source, T item) {
+        protected ItemClick(Tree<T> source, T item,
+                MouseEventDetails mouseEventDetails) {
             super(source);
             this.item = item;
+            this.mouseEventDetails = mouseEventDetails;
         }
 
         /**
@@ -129,6 +136,15 @@ public class Tree<T> extends Composite
         public Tree<T> getSource() {
             return (Tree<T>) super.getSource();
         }
+
+        /**
+         * Returns the mouse event details.
+         *
+         * @return the mouse event details
+         */
+        public MouseEventDetails getMouseEventDetails() {
+            return mouseEventDetails;
+        }
     }
 
     /**
@@ -244,8 +260,8 @@ public class Tree<T> extends Composite
                 e.isUserOriginated()));
         treeGrid.addCollapseListener(e -> fireCollapseEvent(
                 e.getCollapsedItem(), e.isUserOriginated()));
-        treeGrid.addItemClickListener(
-                e -> fireEvent(new ItemClick<>(this, e.getItem())));
+        treeGrid.addItemClickListener(e -> fireEvent(
+                new ItemClick<>(this, e.getItem(), e.getMouseEventDetails())));
     }
 
     /**