From cdefd5c3e5cbde20ac555099016fb7f249c3e1d9 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 28 Jun 2017 13:41:46 +0300 Subject: [PATCH] Add mouse event details to Tree.ItemClick (#9599) This provides a way to get the mouse button clicked as requested in #9335. --- server/src/main/java/com/vaadin/ui/Tree.java | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java index cd53d1bc08..6ae86efe37 100644 --- a/server/src/main/java/com/vaadin/ui/Tree.java +++ b/server/src/main/java/com/vaadin/ui/Tree.java @@ -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 extends Composite public static class ItemClick extends ConnectorEvent { private final T item; + private final MouseEventDetails mouseEventDetails; /** * Constructs a new item click. @@ -109,10 +111,15 @@ public class Tree 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 source, T item) { + protected ItemClick(Tree source, T item, + MouseEventDetails mouseEventDetails) { super(source); this.item = item; + this.mouseEventDetails = mouseEventDetails; } /** @@ -129,6 +136,15 @@ public class Tree extends Composite public Tree getSource() { return (Tree) super.getSource(); } + + /** + * Returns the mouse event details. + * + * @return the mouse event details + */ + public MouseEventDetails getMouseEventDetails() { + return mouseEventDetails; + } } /** @@ -244,8 +260,8 @@ public class Tree 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()))); } /** -- 2.39.5