summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/event/LayoutEvents.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2012-08-13 18:34:33 +0300
committerArtur Signell <artur@vaadin.com>2012-08-13 19:18:33 +0300
commite85d933b25cc3c5cc85eb7eb4b13b950fd8e1569 (patch)
tree9ab6f13f7188cab44bbd979b1cf620f15328a03f /server/src/com/vaadin/event/LayoutEvents.java
parent14dd4d0b28c76eb994b181a4570f3adec53342e6 (diff)
downloadvaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.tar.gz
vaadin-framework-e85d933b25cc3c5cc85eb7eb4b13b950fd8e1569.zip
Moved server files to a server src folder (#9299)
Diffstat (limited to 'server/src/com/vaadin/event/LayoutEvents.java')
-rw-r--r--server/src/com/vaadin/event/LayoutEvents.java138
1 files changed, 138 insertions, 0 deletions
diff --git a/server/src/com/vaadin/event/LayoutEvents.java b/server/src/com/vaadin/event/LayoutEvents.java
new file mode 100644
index 0000000000..602440ea07
--- /dev/null
+++ b/server/src/com/vaadin/event/LayoutEvents.java
@@ -0,0 +1,138 @@
+/*
+@VaadinApache2LicenseForJavaFiles@
+ */
+package com.vaadin.event;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+
+import com.vaadin.event.MouseEvents.ClickEvent;
+import com.vaadin.shared.Connector;
+import com.vaadin.shared.MouseEventDetails;
+import com.vaadin.tools.ReflectTools;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.ComponentContainer;
+
+public interface LayoutEvents {
+
+ public interface LayoutClickListener extends ComponentEventListener {
+
+ public static final Method clickMethod = ReflectTools.findMethod(
+ LayoutClickListener.class, "layoutClick",
+ LayoutClickEvent.class);
+
+ /**
+ * Layout has been clicked
+ *
+ * @param event
+ * Component click event.
+ */
+ public void layoutClick(LayoutClickEvent event);
+ }
+
+ /**
+ * The interface for adding and removing <code>LayoutClickEvent</code>
+ * listeners. By implementing this interface a class explicitly announces
+ * that it will generate a <code>LayoutClickEvent</code> when a component
+ * inside it is clicked and a <code>LayoutClickListener</code> is
+ * registered.
+ * <p>
+ * Note: The general Java convention is not to explicitly declare that a
+ * class generates events, but to directly define the
+ * <code>addListener</code> and <code>removeListener</code> methods. That
+ * way the caller of these methods has no real way of finding out if the
+ * class really will send the events, or if it just defines the methods to
+ * be able to implement an interface.
+ * </p>
+ *
+ * @since 6.5.2
+ * @see LayoutClickListener
+ * @see LayoutClickEvent
+ */
+ public interface LayoutClickNotifier extends Serializable {
+ /**
+ * Add a click listener to the layout. The listener is called whenever
+ * the user clicks inside the layout. An event is also triggered when
+ * the click targets a component inside a nested layout or Panel,
+ * provided the targeted component does not prevent the click event from
+ * propagating. A caption is not considered part of a component.
+ *
+ * The child component that was clicked is included in the
+ * {@link LayoutClickEvent}.
+ *
+ * Use {@link #removeListener(LayoutClickListener)} to remove the
+ * listener.
+ *
+ * @param listener
+ * The listener to add
+ */
+ public void addListener(LayoutClickListener listener);
+
+ /**
+ * Removes an LayoutClickListener.
+ *
+ * @param listener
+ * LayoutClickListener to be removed
+ */
+ public void removeListener(LayoutClickListener listener);
+ }
+
+ /**
+ * An event fired when the layout has been clicked. The event contains
+ * information about the target layout (component) and the child component
+ * that was clicked. If no child component was found it is set to null.
+ */
+ public static class LayoutClickEvent extends ClickEvent {
+
+ private final Component clickedComponent;
+ private final Component childComponent;
+
+ public LayoutClickEvent(Component source,
+ MouseEventDetails mouseEventDetails,
+ Component clickedComponent, Component childComponent) {
+ super(source, mouseEventDetails);
+ this.clickedComponent = clickedComponent;
+ this.childComponent = childComponent;
+ }
+
+ /**
+ * Returns the component that was clicked, which is somewhere inside the
+ * parent layout on which the listener was registered.
+ *
+ * For the direct child component of the layout, see
+ * {@link #getChildComponent()}.
+ *
+ * @return clicked {@link Component}, null if none found
+ */
+ public Component getClickedComponent() {
+ return clickedComponent;
+ }
+
+ /**
+ * Returns the direct child component of the layout which contains the
+ * clicked component.
+ *
+ * For the clicked component inside that child component of the layout,
+ * see {@link #getClickedComponent()}.
+ *
+ * @return direct child {@link Component} of the layout which contains
+ * the clicked Component, null if none found
+ */
+ public Component getChildComponent() {
+ return childComponent;
+ }
+
+ public static LayoutClickEvent createEvent(ComponentContainer layout,
+ MouseEventDetails mouseDetails, Connector clickedConnector) {
+ Component clickedComponent = (Component) clickedConnector;
+ Component childComponent = clickedComponent;
+ while (childComponent != null
+ && childComponent.getParent() != layout) {
+ childComponent = childComponent.getParent();
+ }
+
+ return new LayoutClickEvent(layout, mouseDetails, clickedComponent,
+ childComponent);
+ }
+ }
+} \ No newline at end of file