]> source.dussan.org Git - vaadin-framework.git/commitdiff
Some API changes for #875 as discussed at length.
authorMarc Englund <marc.englund@itmill.com>
Tue, 23 Mar 2010 15:40:24 +0000 (15:40 +0000)
committerMarc Englund <marc.englund@itmill.com>
Tue, 23 Mar 2010 15:40:24 +0000 (15:40 +0000)
svn changeset:12048/svn branch:6.3

src/com/vaadin/event/Action.java
src/com/vaadin/ui/AbstractField.java
src/com/vaadin/ui/Button.java
src/com/vaadin/ui/Form.java
src/com/vaadin/ui/Panel.java

index b2e3f6a9300f943500cca57e0aefaab6737d582d..fcb8f165b4d244296fce40bfc4b92f25ddc43862 100644 (file)
@@ -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 <code>addAction()</code>
+     * -method, which in many cases is easier than implementing the
+     * Action.Handler interface.<br/>
+     * 
+     */
     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 <T extends Action & Action.Listener> void addAction(T action);
 
         public <T extends Action & Action.Listener> void removeAction(T action);
     }
 
-    public interface NotifierProxy {
-        public <T extends Action & Action.Listener> void addAction(T action);
+    public interface ShortcutNotifier {
+        public void addShortcutListener(ShortcutListener shortcut);
 
-        public <T extends Action & Action.Listener> void removeAction(T action);
+        public void removeShortcutListener(ShortcutListener shortcut);
     }
 
     /**
index 35f186dd098d4c2102cc088ee7f74d6ad4b0006b..fb436b8ca0b6b2d8a290f2b1894058d4ad69d5bc 100644 (file)
@@ -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 <T extends Action & Action.Listener> void addAction(T action) {
-        getActionManager().addAction(action);
+    public void addShortcutListener(ShortcutListener shortcut) {
+        getActionManager().addAction(shortcut);
     }
 
-    public <T extends Action & Action.Listener> void removeAction(T action) {
+    public void removeShortcutListener(ShortcutListener shortcut) {
         if (actionManager == null) {
-            actionManager.removeAction(action);
+            actionManager.removeAction(shortcut);
         }
     }
 
index 08fab9772a460eb83f588a5ac5a9e87bee51e8f9..004bf43a8f3d1b575a116f196bca7416c6c97c70 100644 (file)
@@ -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;
         }
     }
index 59d1b51481e4f61074ba40b08d35e1c475e69612..1858355205026b7c6150c5b50d9d00a7e9c41d43 100644 (file)
@@ -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 <T extends Action & com.vaadin.event.Action.Listener> void addAction(
+            T action) {
+        getOwnActionManager().addAction(action);
+    }
+
+    public <T extends Action & com.vaadin.event.Action.Listener> void removeAction(
+            T action) {
+        if (ownActionManager == null) {
+            ownActionManager.removeAction(action);
         }
     }
 
index e23e38d56f928daa1aa9003bcdc35e7457608aba..d4fb66deb640ed4e6deb0c805523b87d15a3be52 100644 (file)
@@ -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;