diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-02-24 06:54:28 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-02-24 06:54:28 +0000 |
commit | f4b3242373c10f6912eb2477149869fe35ccebfe (patch) | |
tree | 0e5cf4a269ea99ff1a19eb4c7affec1b9911f6c4 /src/com/vaadin | |
parent | 6e9e7b34507be862d9eca9b730adc195ccced913 (diff) | |
download | vaadin-framework-f4b3242373c10f6912eb2477149869fe35ccebfe.tar.gz vaadin-framework-f4b3242373c10f6912eb2477149869fe35ccebfe.zip |
#6434 LayoutClickNotifier interface
svn changeset:17403/svn branch:6.5
Diffstat (limited to 'src/com/vaadin')
-rw-r--r-- | src/com/vaadin/event/LayoutEvents.java | 48 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbsoluteLayout.java | 25 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractLayout.java | 11 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractOrderedLayout.java | 24 | ||||
-rw-r--r-- | src/com/vaadin/ui/CssLayout.java | 25 | ||||
-rw-r--r-- | src/com/vaadin/ui/GridLayout.java | 24 |
6 files changed, 64 insertions, 93 deletions
diff --git a/src/com/vaadin/event/LayoutEvents.java b/src/com/vaadin/event/LayoutEvents.java index 0e77bb82ed..5c7fc0db28 100644 --- a/src/com/vaadin/event/LayoutEvents.java +++ b/src/com/vaadin/event/LayoutEvents.java @@ -3,6 +3,7 @@ */ package com.vaadin.event; +import java.io.Serializable; import java.lang.reflect.Method; import com.vaadin.event.MouseEvents.ClickEvent; @@ -28,6 +29,53 @@ public interface LayoutEvents { } /** + * 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. diff --git a/src/com/vaadin/ui/AbsoluteLayout.java b/src/com/vaadin/ui/AbsoluteLayout.java index d96059fdb3..3b0239af7b 100644 --- a/src/com/vaadin/ui/AbsoluteLayout.java +++ b/src/com/vaadin/ui/AbsoluteLayout.java @@ -12,6 +12,7 @@ import java.util.Map; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; +import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; @@ -25,7 +26,8 @@ import com.vaadin.terminal.gwt.client.ui.VAbsoluteLayout; */ @SuppressWarnings("serial") @ClientWidget(VAbsoluteLayout.class) -public class AbsoluteLayout extends AbstractLayout { +public class AbsoluteLayout extends AbstractLayout implements + LayoutClickNotifier { private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; @@ -560,32 +562,11 @@ public class AbsoluteLayout extends AbstractLayout { } } - /** - * Add a click listener to the layout. The listener is called whenever the - * user clicks inside the layout. Also when the click targets a component - * inside the Panel, provided the targeted component does not prevent the - * click event from propagating. - * - * 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) { addListener(CLICK_EVENT, LayoutClickEvent.class, listener, LayoutClickListener.clickMethod); } - /** - * Remove a click listener from the layout. The listener should earlier have - * been added using {@link #addListener(LayoutClickListener)}. - * - * @param listener - * The listener to remove - */ public void removeListener(LayoutClickListener listener) { removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); } diff --git a/src/com/vaadin/ui/AbstractLayout.java b/src/com/vaadin/ui/AbstractLayout.java index eff53cf1e0..d0cc549138 100644 --- a/src/com/vaadin/ui/AbstractLayout.java +++ b/src/com/vaadin/ui/AbstractLayout.java @@ -7,6 +7,7 @@ package com.vaadin.ui; import java.util.Map; import com.vaadin.event.LayoutEvents.LayoutClickEvent; +import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.EventId; @@ -95,7 +96,8 @@ public abstract class AbstractLayout extends AbstractComponentContainer public void changeVariables(Object source, Map<String, Object> variables) { super.changeVariables(source, variables); // not all subclasses use these events - if (variables.containsKey(CLICK_EVENT)) { + if (this instanceof LayoutClickNotifier + && variables.containsKey(CLICK_EVENT)) { fireClick((Map<String, Object>) variables.get(CLICK_EVENT)); } @@ -104,11 +106,12 @@ public abstract class AbstractLayout extends AbstractComponentContainer /** * Fire a layout click event. * - * Note that this is only used by the subclasses that support layout click - * listeners, and can be overridden for custom click event firing. + * Note that this method is only used by the subclasses that implement + * {@link LayoutClickNotifier}, and can be overridden for custom click event + * firing. * * @param parameters - * The parameters recieved from the client side implementation + * The parameters received from the client side implementation */ protected void fireClick(Map<String, Object> parameters) { MouseEventDetails mouseDetails = MouseEventDetails diff --git a/src/com/vaadin/ui/AbstractOrderedLayout.java b/src/com/vaadin/ui/AbstractOrderedLayout.java index 6e55343c2e..8dfbe07b18 100644 --- a/src/com/vaadin/ui/AbstractOrderedLayout.java +++ b/src/com/vaadin/ui/AbstractOrderedLayout.java @@ -11,6 +11,7 @@ import java.util.Map; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; +import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Sizeable; @@ -18,7 +19,7 @@ import com.vaadin.terminal.gwt.client.EventId; @SuppressWarnings("serial") public abstract class AbstractOrderedLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; @@ -349,32 +350,11 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements AlignmentUtils.setComponentAlignment(this, component, alignment); } - /** - * Add a click listener to the layout. The listener is called whenever the - * user clicks inside the layout. Also when the click targets a component - * inside the Panel, provided the targeted component does not prevent the - * click event from propagating. - * - * 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) { addListener(CLICK_EVENT, LayoutClickEvent.class, listener, LayoutClickListener.clickMethod); } - /** - * Remove a click listener from the layout. The listener should earlier have - * been added using {@link #addListener(LayoutClickListener)}. - * - * @param listener - * The listener to remove - */ public void removeListener(LayoutClickListener listener) { removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); } diff --git a/src/com/vaadin/ui/CssLayout.java b/src/com/vaadin/ui/CssLayout.java index 5e0cfed263..5789a65ed3 100644 --- a/src/com/vaadin/ui/CssLayout.java +++ b/src/com/vaadin/ui/CssLayout.java @@ -9,6 +9,7 @@ import java.util.LinkedList; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; +import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.Paintable; @@ -57,7 +58,7 @@ import com.vaadin.terminal.gwt.client.ui.VCssLayout; * */ @ClientWidget(VCssLayout.class) -public class CssLayout extends AbstractLayout { +public class CssLayout extends AbstractLayout implements LayoutClickNotifier { private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; @@ -249,33 +250,11 @@ public class CssLayout extends AbstractLayout { } } - /** - * Add a click listener to the layout. The listener is called whenever the - * user clicks inside the layout. Also when the click targets a component - * inside the 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) { addListener(CLICK_EVENT, LayoutClickEvent.class, listener, LayoutClickListener.clickMethod); } - /** - * Remove a click listener from the layout. The listener should earlier have - * been added using {@link #addListener(LayoutClickListener)}. - * - * @param listener - * The listener to remove - */ public void removeListener(LayoutClickListener listener) { removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); } diff --git a/src/com/vaadin/ui/GridLayout.java b/src/com/vaadin/ui/GridLayout.java index ed6136a852..40b0ca9a6c 100644 --- a/src/com/vaadin/ui/GridLayout.java +++ b/src/com/vaadin/ui/GridLayout.java @@ -14,6 +14,7 @@ import java.util.Map.Entry; import com.vaadin.event.LayoutEvents.LayoutClickEvent; import com.vaadin.event.LayoutEvents.LayoutClickListener; +import com.vaadin.event.LayoutEvents.LayoutClickNotifier; import com.vaadin.terminal.PaintException; import com.vaadin.terminal.PaintTarget; import com.vaadin.terminal.gwt.client.EventId; @@ -42,7 +43,7 @@ import com.vaadin.terminal.gwt.client.ui.VGridLayout; @SuppressWarnings("serial") @ClientWidget(VGridLayout.class) public class GridLayout extends AbstractLayout implements - Layout.AlignmentHandler, Layout.SpacingHandler { + Layout.AlignmentHandler, Layout.SpacingHandler, LayoutClickNotifier { private static final String CLICK_EVENT = EventId.LAYOUT_CLICK; @@ -1378,32 +1379,11 @@ public class GridLayout extends AbstractLayout implements AlignmentUtils.setComponentAlignment(this, component, alignment); } - /** - * Add a click listener to the layout. The listener is called whenever the - * user clicks inside the layout. Also when the click targets a component - * inside the Panel, provided the targeted component does not prevent the - * click event from propagating. - * - * 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) { addListener(CLICK_EVENT, LayoutClickEvent.class, listener, LayoutClickListener.clickMethod); } - /** - * Remove a click listener from the layout. The listener should earlier have - * been added using {@link #addListener(LayoutClickListener)}. - * - * @param listener - * The listener to remove - */ public void removeListener(LayoutClickListener listener) { removeListener(CLICK_EVENT, LayoutClickEvent.class, listener); } |