summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2015-09-28 11:40:57 +0300
committerVaadin Code Review <review@vaadin.com>2015-10-01 09:43:16 +0000
commit00dc7ab85e8fd533854ccc50b788012cf1450342 (patch)
treefb8204bbf18476be0af486dbd11faeff6651c518 /server
parentcc4f755a6c9cf996442f9c5356f6f0fbdcf41a8f (diff)
downloadvaadin-framework-00dc7ab85e8fd533854ccc50b788012cf1450342.tar.gz
vaadin-framework-00dc7ab85e8fd533854ccc50b788012cf1450342.zip
Add support for ContextClickEvent in AbstractComponent (#19015)
Change-Id: I93d5d20925b8ac9b4b108ccc6deec2090e68aa0d
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/event/ContextClickEvent.java82
-rw-r--r--server/src/com/vaadin/ui/AbstractComponent.java32
2 files changed, 113 insertions, 1 deletions
diff --git a/server/src/com/vaadin/event/ContextClickEvent.java b/server/src/com/vaadin/event/ContextClickEvent.java
new file mode 100644
index 0000000000..88b46d938b
--- /dev/null
+++ b/server/src/com/vaadin/event/ContextClickEvent.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.event;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import com.vaadin.event.MouseEvents.ClickEvent;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.ui.Component;
+import com.vaadin.util.ReflectTools;
+
+/**
+ * Context click event fired by a {@link Component}. ContextClickEvent happens
+ * when context click happens on the client-side inside the Component.
+ *
+ * @since
+ * @author Vaadin Ltd
+ */
+public class ContextClickEvent extends ClickEvent {
+
+ public static final Method CONTEXT_CLICK_METHOD = ReflectTools
+ .findMethod(ContextClickListener.class, "contextClick",
+ ContextClickEvent.class);
+
+ public ContextClickEvent(Component source,
+ MouseEventDetails mouseEventDetails) {
+ super(source, mouseEventDetails);
+ }
+
+ /**
+ * Listener for {@link ContextClickEvent ContextClickEvents}.
+ */
+ public interface ContextClickListener extends Serializable {
+
+ /**
+ * Called when the context click happens.
+ *
+ * @param event
+ * the context click event
+ */
+ public void contextClick(ContextClickEvent event);
+ }
+
+ /**
+ * The interface for adding and removing listeners for
+ * {@link ContextClickEvent ContextClickEvents}.
+ */
+ public interface ContextClickNotifier extends Serializable {
+ /**
+ * Adds a context click listener that gets notified when a context click
+ * happens.
+ *
+ * @param listener
+ * the context click listener to add
+ */
+ public void addContextClickListener(ContextClickListener listener);
+
+ /**
+ * Removes a context click listener that was previously added with
+ * {@link #addContextClickListener(ContextClickListener)}.
+ *
+ * @param listener
+ * the context click listener to remove
+ */
+ public void removeContextClickListener(ContextClickListener listener);
+ }
+
+}
diff --git a/server/src/com/vaadin/ui/AbstractComponent.java b/server/src/com/vaadin/ui/AbstractComponent.java
index f499cb1fec..42b36b0f21 100644
--- a/server/src/com/vaadin/ui/AbstractComponent.java
+++ b/server/src/com/vaadin/ui/AbstractComponent.java
@@ -34,6 +34,9 @@ import org.jsoup.nodes.Element;
import com.vaadin.event.ActionManager;
import com.vaadin.event.ConnectorActionManager;
+import com.vaadin.event.ContextClickEvent;
+import com.vaadin.event.ContextClickEvent.ContextClickListener;
+import com.vaadin.event.ContextClickEvent.ContextClickNotifier;
import com.vaadin.event.ShortcutListener;
import com.vaadin.server.AbstractClientConnector;
import com.vaadin.server.AbstractErrorMessage.ContentMode;
@@ -49,6 +52,9 @@ import com.vaadin.server.UserError;
import com.vaadin.server.VaadinSession;
import com.vaadin.shared.AbstractComponentState;
import com.vaadin.shared.ComponentConstants;
+import com.vaadin.shared.ContextClickRpc;
+import com.vaadin.shared.EventId;
+import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.ComponentStateUtil;
import com.vaadin.shared.util.SharedUtil;
import com.vaadin.ui.Field.ValueChangeEvent;
@@ -67,7 +73,7 @@ import com.vaadin.util.ReflectTools;
*/
@SuppressWarnings("serial")
public abstract class AbstractComponent extends AbstractClientConnector
- implements Component {
+ implements Component, ContextClickNotifier {
/* Private members */
@@ -1391,6 +1397,30 @@ public abstract class AbstractComponent extends AbstractClientConnector
return false;
}
+ @Override
+ public void addContextClickListener(ContextClickListener listener) {
+ // Register default Context Click RPC if needed. This RPC won't be
+ // called if there are no listeners on the server-side. A client-side
+ // connector can override this and use a different RPC channel.
+ if (getRpcManager(ContextClickRpc.class.getName()) == null) {
+ registerRpc(new ContextClickRpc() {
+ @Override
+ public void contextClick(MouseEventDetails details) {
+ fireEvent(new ContextClickEvent(AbstractComponent.this,
+ details));
+ }
+ });
+ }
+
+ addListener(EventId.CONTEXT_CLICK, ContextClickEvent.class, listener,
+ ContextClickEvent.CONTEXT_CLICK_METHOD);
+ }
+
+ @Override
+ public void removeContextClickListener(ContextClickListener listener) {
+ removeListener(EventId.CONTEXT_CLICK, ContextClickEvent.class, listener);
+ }
+
private static final Logger getLogger() {
return Logger.getLogger(AbstractComponent.class.getName());
}