From 5097095625403405d030575fcc1102f02aa3e327 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Mon, 5 Oct 2015 11:23:46 +0300 Subject: Add support for TreeContextClickEvents (#19062) Tree connector now overrides the send context click event providing the row key to the server-side via RPC call. This is then passed on to a TreeContextClickEvent and fired to listeners. This patch modifies the test base for context click testing by making it tolerate 1 piksel differences. This was to fix any subpixel related issues in coordinate comparison. Change-Id: Iacced274a6b518b5f89378cbc32b8381362e1e4f --- server/src/com/vaadin/ui/Tree.java | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'server') diff --git a/server/src/com/vaadin/ui/Tree.java b/server/src/com/vaadin/ui/Tree.java index b41139275b..2c537e3a98 100644 --- a/server/src/com/vaadin/ui/Tree.java +++ b/server/src/com/vaadin/ui/Tree.java @@ -38,6 +38,7 @@ import com.vaadin.data.util.ContainerHierarchicalWrapper; import com.vaadin.data.util.HierarchicalContainer; import com.vaadin.event.Action; import com.vaadin.event.Action.Handler; +import com.vaadin.event.ContextClickEvent; import com.vaadin.event.DataBoundTransferable; import com.vaadin.event.ItemClickEvent; import com.vaadin.event.ItemClickEvent.ItemClickListener; @@ -59,6 +60,7 @@ import com.vaadin.shared.MouseEventDetails; import com.vaadin.shared.ui.MultiSelectMode; import com.vaadin.shared.ui.dd.VerticalDropLocation; import com.vaadin.shared.ui.tree.TreeConstants; +import com.vaadin.shared.ui.tree.TreeServerRpc; import com.vaadin.ui.declarative.DesignAttributeHandler; import com.vaadin.ui.declarative.DesignContext; import com.vaadin.ui.declarative.DesignException; @@ -75,6 +77,32 @@ import com.vaadin.util.ReflectTools; public class Tree extends AbstractSelect implements Container.Hierarchical, Action.Container, ItemClickNotifier, DragSource, DropTarget { + public static class TreeContextClickEvent extends ContextClickEvent { + + private final Object itemId; + + public TreeContextClickEvent(Tree source, Object itemId, + MouseEventDetails mouseEventDetails) { + super(source, mouseEventDetails); + this.itemId = itemId; + } + + @Override + public Tree getComponent() { + return (Tree) super.getComponent(); + } + + /** + * Returns the item id of context clicked row. + * + * @return item id of clicked row; null if no row is + * present at the location + */ + public Object getItemId() { + return itemId; + } + } + /* Private members */ private static final String NULL_ALT_EXCEPTION_MESSAGE = "Parameter 'altText' needs to be non null"; @@ -154,6 +182,14 @@ public class Tree extends AbstractSelect implements Container.Hierarchical, */ public Tree() { this(null); + + registerRpc(new TreeServerRpc() { + @Override + public void contextClick(String rowKey, MouseEventDetails details) { + fireEvent(new TreeContextClickEvent(Tree.this, + itemIdMapper.get(rowKey), details)); + } + }); } /** -- cgit v1.2.3