diff options
Diffstat (limited to 'src/com/vaadin')
-rw-r--r-- | src/com/vaadin/ui/AbstractComponent.java | 23 | ||||
-rw-r--r-- | src/com/vaadin/ui/AbstractField.java | 21 | ||||
-rw-r--r-- | src/com/vaadin/ui/Upload.java | 30 |
3 files changed, 31 insertions, 43 deletions
diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index ebccb41d6c..90eef00604 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -117,6 +117,11 @@ public abstract class AbstractComponent implements Component, MethodEventSource private Locale locale; /** + * The component should receive focus (if {@link Focusable}) when attached. + */ + private boolean delayedFocus; + + /** * List of repaint request listeners or null if not listened at all. */ private LinkedList<RepaintRequestListener> repaintRequestListeners = null; @@ -628,6 +633,9 @@ public abstract class AbstractComponent implements Component, MethodEventSource */ public void attach() { requestRepaint(); + if (delayedFocus) { + focus(); + } } /* @@ -637,6 +645,21 @@ public abstract class AbstractComponent implements Component, MethodEventSource public void detach() { } + /** + * Sets the focus for this component if the component is {@link Focusable}. + */ + protected void focus() { + if (this instanceof Focusable) { + final Application app = getApplication(); + if (app != null) { + getWindow().setFocusedComponent((Focusable) this); + delayedFocus = false; + } else { + delayedFocus = true; + } + } + } + /* * Gets the parent application of the component. Don't add a JavaDoc comment * here, we use the default documentation from implemented interface. diff --git a/src/com/vaadin/ui/AbstractField.java b/src/com/vaadin/ui/AbstractField.java index fb436b8ca0..b2b38ffc65 100644 --- a/src/com/vaadin/ui/AbstractField.java +++ b/src/com/vaadin/ui/AbstractField.java @@ -13,7 +13,6 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.Map; -import com.vaadin.Application; import com.vaadin.data.Buffered; import com.vaadin.data.Property; import com.vaadin.data.Validatable; @@ -59,8 +58,6 @@ public abstract class AbstractField extends AbstractComponent implements Field, /* Private members */ - private boolean delayedFocus; - /** * Value of the abstract field. */ @@ -978,19 +975,12 @@ public abstract class AbstractField extends AbstractComponent implements Field, } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Component.Focusable#focus() + /** + * {@inheritDoc} */ + @Override public void focus() { - final Application app = getApplication(); - if (app != null) { - getWindow().setFocusedComponent(this); - delayedFocus = false; - } else { - delayedFocus = true; - } + super.focus(); } /** @@ -1069,9 +1059,6 @@ public abstract class AbstractField extends AbstractComponent implements Field, @Override public void attach() { super.attach(); - if (delayedFocus) { - focus(); - } if (actionManager != null) { actionManager.setViewer(getWindow()); } diff --git a/src/com/vaadin/ui/Upload.java b/src/com/vaadin/ui/Upload.java index fdad5a75cb..49cf159e0a 100644 --- a/src/com/vaadin/ui/Upload.java +++ b/src/com/vaadin/ui/Upload.java @@ -63,8 +63,6 @@ import com.vaadin.terminal.gwt.client.ui.VUpload; @ClientWidget(VUpload.class) public class Upload extends AbstractComponent implements Component.Focusable { - private boolean delayedFocus; - /** * Upload buffer size. */ @@ -859,19 +857,12 @@ public class Upload extends AbstractComponent implements Component.Focusable { this.receiver = receiver; } - /* - * (non-Javadoc) - * - * @see com.vaadin.ui.Component.Focusable#focus() + /** + * {@inheritDoc} */ + @Override public void focus() { - final Application app = getApplication(); - if (app != null) { - getWindow().setFocusedComponent(this); - delayedFocus = false; - } else { - delayedFocus = true; - } + super.focus(); } /** @@ -1024,17 +1015,4 @@ public class Upload extends AbstractComponent implements Component.Focusable { this.buttonCaption = buttonCaption; } - /** - * Notifies the component that it is connected to an application. - * - * @see com.vaadin.ui.Component#attach() - */ - @Override - public void attach() { - super.attach(); - if (delayedFocus) { - focus(); - } - } - } |