From 6c663d40425234642afecd7f1d36c7e62ac308ab Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Tue, 23 Mar 2010 15:40:24 +0000 Subject: [PATCH] Some API changes for #875 as discussed at length. svn changeset:12048/svn branch:6.3 --- src/com/vaadin/event/Action.java | 19 +++++++++-- src/com/vaadin/ui/AbstractField.java | 20 +++++------- src/com/vaadin/ui/Button.java | 6 ++-- src/com/vaadin/ui/Form.java | 47 ++++++++++++++++++---------- src/com/vaadin/ui/Panel.java | 3 +- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/com/vaadin/event/Action.java b/src/com/vaadin/event/Action.java index b2e3f6a930..fcb8f165b4 100644 --- a/src/com/vaadin/event/Action.java +++ b/src/com/vaadin/event/Action.java @@ -72,20 +72,33 @@ public class Action implements Serializable { return icon; } + /** + * An Action that implements this interface can be added to an + * Action.Notifier (or NotifierProxy) via the addAction() + * -method, which in many cases is easier than implementing the + * Action.Handler interface.
+ * + */ public interface Listener { public void handleAction(Object sender, Object target); } + /** + * Action.Containers implementing this support an easier way of adding + * single Actions than the more involved Action.Handler. The added actions + * must be Action.Listeners, thus handling the action themselves. + * + */ public interface Notifier extends Container { public void addAction(T action); public void removeAction(T action); } - public interface NotifierProxy { - public void addAction(T action); + public interface ShortcutNotifier { + public void addShortcutListener(ShortcutListener shortcut); - public void removeAction(T action); + public void removeShortcutListener(ShortcutListener shortcut); } /** diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 35f186dd09..fb436b8ca0 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -55,7 +55,7 @@ import com.vaadin.terminal.PaintTarget; */ @SuppressWarnings("serial") public abstract class AbstractField extends AbstractComponent implements Field, - Property.ReadOnlyStatusChangeNotifier, Action.NotifierProxy { + Property.ReadOnlyStatusChangeNotifier, Action.ShortcutNotifier { /* Private members */ @@ -138,7 +138,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, * Keeps track of the Actions added to this component; the actual * handling/notifying is delegated, usually to the containing window. */ - protected ActionManager actionManager; + private ActionManager actionManager; /* Component basics */ @@ -1072,9 +1072,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, if (delayedFocus) { focus(); } - if (actionManager != null && !(this instanceof Action.Container)) { - // Only for non Action.Containers because those want to paint - // actions themselves - e.g Form + if (actionManager != null) { actionManager.setViewer(getWindow()); } } @@ -1082,9 +1080,7 @@ public abstract class AbstractField extends AbstractComponent implements Field, @Override public void detach() { super.detach(); - if (actionManager != null && !(this instanceof Action.Container)) { - // Only for non Action.Containers because those want to paint - // actions themselves - e.g Form + if (actionManager != null) { actionManager.setViewer((Window) null); } } @@ -1216,13 +1212,13 @@ public abstract class AbstractField extends AbstractComponent implements Field, return actionManager; } - public void addAction(T action) { - getActionManager().addAction(action); + public void addShortcutListener(ShortcutListener shortcut) { + getActionManager().addAction(shortcut); } - public void removeAction(T action) { + public void removeShortcutListener(ShortcutListener shortcut) { if (actionManager == null) { - actionManager.removeAction(action); + actionManager.removeAction(shortcut); } } diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 08fab9772a..004bf43a8f 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -357,16 +357,16 @@ public class Button extends AbstractField { public ClickShortcut setClickShortcut(int keyCode, int... modifiers) { ClickShortcut old = clickShortcut; if (old != null) { - removeAction(old); + removeShortcutListener(old); } clickShortcut = new ClickShortcut(this, keyCode, modifiers); - addAction(clickShortcut); + addShortcutListener(clickShortcut); return old; } public void removeClickShortcut() { if (clickShortcut != null) { - removeAction(clickShortcut); + removeShortcutListener(clickShortcut); clickShortcut = null; } } diff --git a/src/com/vaadin/ui/Form.java b/src/com/vaadin/ui/Form.java index 59d1b51481..1858355205 100644 --- a/src/com/vaadin/ui/Form.java +++ b/src/com/vaadin/ui/Form.java @@ -21,6 +21,7 @@ import com.vaadin.data.util.BeanItem; import com.vaadin.event.Action; import com.vaadin.event.ActionManager; import com.vaadin.event.Action.Handler; +import com.vaadin.event.Action.ShortcutNotifier; import com.vaadin.terminal.CompositeErrorMessage; import com.vaadin.terminal.ErrorMessage; import com.vaadin.terminal.PaintException; @@ -61,7 +62,7 @@ import com.vaadin.terminal.gwt.client.ui.VForm; @SuppressWarnings("serial") @ClientWidget(VForm.class) public class Form extends AbstractField implements Item.Editor, Buffered, Item, - Validatable, Action.Container { + Validatable, Action.Notifier { private Object propertyValue; @@ -138,9 +139,11 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, /** * Keeps track of the Actions added to this component, and manages the - * painting and handling as well. + * painting and handling as well. Note that the extended AbstractField is a + * {@link ShortcutNotifier} and has a actionManager that delegates actions + * to the containing window. This one does not delegate. */ - ActionManager actionManager = new ActionManager(this); + ActionManager ownActionManager = new ActionManager(this); /** * Contructs a new form with default layout. @@ -195,8 +198,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, formFooter.paint(target); } - if (actionManager != null) { - actionManager.paintActions(null, target); + if (ownActionManager != null) { + ownActionManager.paintActions(null, target); } } @@ -205,8 +208,8 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, super.changeVariables(source, variables); // Actions - if (actionManager != null) { - actionManager.handleActions(variables, this); + if (ownActionManager != null) { + ownActionManager.handleActions(variables, this); } } @@ -1283,20 +1286,20 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, * ACTIONS */ - protected ActionManager getActionManager() { - if (actionManager == null) { - actionManager = new ActionManager(this); + protected ActionManager getOwnActionManager() { + if (ownActionManager == null) { + ownActionManager = new ActionManager(this); } - return actionManager; + return ownActionManager; } public void addActionHandler(Handler actionHandler) { - getActionManager().addActionHandler(actionHandler); + getOwnActionManager().addActionHandler(actionHandler); } public void removeActionHandler(Handler actionHandler) { - if (actionManager != null) { - actionManager.removeActionHandler(actionHandler); + if (ownActionManager != null) { + ownActionManager.removeActionHandler(actionHandler); } } @@ -1304,8 +1307,20 @@ public class Form extends AbstractField implements Item.Editor, Buffered, Item, * Removes all action handlers */ public void removeAllActionHandlers() { - if (actionManager != null) { - actionManager.removeAllActionHandlers(); + if (ownActionManager != null) { + ownActionManager.removeAllActionHandlers(); + } + } + + public void addAction( + T action) { + getOwnActionManager().addAction(action); + } + + public void removeAction( + T action) { + if (ownActionManager == null) { + ownActionManager.removeAction(action); } } diff --git a/src/com/vaadin/ui/Panel.java b/src/com/vaadin/ui/Panel.java index e23e38d56f..d4fb66deb6 100644 --- a/src/com/vaadin/ui/Panel.java +++ b/src/com/vaadin/ui/Panel.java @@ -32,8 +32,7 @@ import com.vaadin.ui.themes.Runo; @ClientWidget(VPanel.class) public class Panel extends AbstractComponentContainer implements Scrollable, ComponentContainer.ComponentAttachListener, - ComponentContainer.ComponentDetachListener, Action.Container, - Action.Notifier { + ComponentContainer.ComponentDetachListener, Action.Notifier { private static final String CLICK_EVENT = VPanel.CLICK_EVENT_IDENTIFIER; -- 2.39.5