]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7963 Moved ActionManager from AbstractField to AbstractComponent to
authorArtur Signell <artur@vaadin.com>
Tue, 22 Nov 2011 10:26:53 +0000 (12:26 +0200)
committerArtur Signell <artur@vaadin.com>
Tue, 22 Nov 2011 11:18:40 +0000 (13:18 +0200)
enable Button to extend AbstractComponent

src/com/vaadin/ui/AbstractComponent.java
src/com/vaadin/ui/AbstractField.java

index eda2fd64ad9aaff9ba720afd758edc90656b8d2d..b9fffac35f8061f36ec2cf25620c70d50f4ec4fb 100644 (file)
@@ -19,8 +19,10 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import com.vaadin.Application;
+import com.vaadin.event.ActionManager;
 import com.vaadin.event.EventRouter;
 import com.vaadin.event.MethodEventSource;
+import com.vaadin.event.ShortcutListener;
 import com.vaadin.terminal.ErrorMessage;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
@@ -145,6 +147,12 @@ public abstract class AbstractComponent implements Component, MethodEventSource
 
     private ComponentErrorHandler errorHandler = null;
 
+    /**
+     * Keeps track of the Actions added to this component; the actual
+     * handling/notifying is delegated, usually to the containing window.
+     */
+    private ActionManager actionManager;
+
     /* Constructor */
 
     /**
@@ -635,6 +643,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource
         if (delayedFocus) {
             focus();
         }
+        if (actionManager != null) {
+            actionManager.setViewer(getWindow());
+        }
     }
 
     /*
@@ -642,6 +653,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      * we use the default documentation from implemented interface.
      */
     public void detach() {
+        if (actionManager != null) {
+            actionManager.setViewer((Window) null);
+        }
     }
 
     /**
@@ -1517,4 +1531,34 @@ public abstract class AbstractComponent implements Component, MethodEventSource
 
     }
 
+    /*
+     * Actions
+     */
+
+    /**
+     * Gets the {@link ActionManager} used to manage the
+     * {@link ShortcutListener}s added to this {@link Field}.
+     * 
+     * @return the ActionManager in use
+     */
+    protected ActionManager getActionManager() {
+        if (actionManager == null) {
+            actionManager = new ActionManager();
+            if (getWindow() != null) {
+                actionManager.setViewer(getWindow());
+            }
+        }
+        return actionManager;
+    }
+
+    public void addShortcutListener(ShortcutListener shortcut) {
+        getActionManager().addAction(shortcut);
+    }
+
+    public void removeShortcutListener(ShortcutListener shortcut) {
+        if (actionManager != null) {
+            actionManager.removeAction(shortcut);
+        }
+    }
+
 }
\ No newline at end of file
index 7899569ea8fc627557bda4fe70db53db0e1fabaf..fe61d2a86c3e618395d2b754f3707695c3ccf1a3 100644 (file)
@@ -18,7 +18,6 @@ import com.vaadin.data.Validatable;
 import com.vaadin.data.Validator;
 import com.vaadin.data.Validator.InvalidValueException;
 import com.vaadin.event.Action;
-import com.vaadin.event.ActionManager;
 import com.vaadin.event.ShortcutAction;
 import com.vaadin.event.ShortcutListener;
 import com.vaadin.terminal.CompositeErrorMessage;
@@ -131,12 +130,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,
      */
     private boolean validationVisible = true;
 
-    /**
-     * Keeps track of the Actions added to this component; the actual
-     * handling/notifying is delegated, usually to the containing window.
-     */
-    private ActionManager actionManager;
-
     private boolean valueWasModifiedByDataSourceDuringCommit;
 
     /* Component basics */
@@ -1110,27 +1103,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         }
     }
 
-    /**
-     * Notifies the component that it is connected to an application.
-     * 
-     * @see com.vaadin.ui.Component#attach()
-     */
-    @Override
-    public void attach() {
-        super.attach();
-        if (actionManager != null) {
-            actionManager.setViewer(getWindow());
-        }
-    }
-
-    @Override
-    public void detach() {
-        super.detach();
-        if (actionManager != null) {
-            actionManager.setViewer((Window) null);
-        }
-    }
-
     /**
      * Is this field required. Required fields must filled by the user.
      * 
@@ -1244,36 +1216,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,
         requestRepaint();
     }
 
-    /*
-     * Actions
-     */
-
-    /**
-     * Gets the {@link ActionManager} used to manage the
-     * {@link ShortcutListener}s added to this {@link Field}.
-     * 
-     * @return the ActionManager in use
-     */
-    protected ActionManager getActionManager() {
-        if (actionManager == null) {
-            actionManager = new ActionManager();
-            if (getWindow() != null) {
-                actionManager.setViewer(getWindow());
-            }
-        }
-        return actionManager;
-    }
-
-    public void addShortcutListener(ShortcutListener shortcut) {
-        getActionManager().addAction(shortcut);
-    }
-
-    public void removeShortcutListener(ShortcutListener shortcut) {
-        if (actionManager != null) {
-            actionManager.removeAction(shortcut);
-        }
-    }
-
     /**
      * A ready-made {@link ShortcutListener} that focuses the given
      * {@link Focusable} (usually a {@link Field}) when the keyboard shortcut is