From a28763d2b933ab9f07e1b6faa4705b16b8d197ba Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Tue, 22 Nov 2011 12:26:53 +0200 Subject: [PATCH] #7963 Moved ActionManager from AbstractField to AbstractComponent to enable Button to extend AbstractComponent --- src/com/vaadin/ui/AbstractComponent.java | 44 ++++++++++++++++++ src/com/vaadin/ui/AbstractField.java | 58 ------------------------ 2 files changed, 44 insertions(+), 58 deletions(-) diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index eda2fd64ad..b9fffac35f 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -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 diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index 7899569ea8..fe61d2a86c 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -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 -- 2.39.5