]> source.dussan.org Git - vaadin-framework.git/commitdiff
#1394 enable implementing Focusable components outside the com.vaadin.ui package
authorHenri Sara <henri.sara@itmill.com>
Thu, 1 Apr 2010 11:35:32 +0000 (11:35 +0000)
committerHenri Sara <henri.sara@itmill.com>
Thu, 1 Apr 2010 11:35:32 +0000 (11:35 +0000)
svn changeset:12274/svn branch:6.3

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

index ebccb41d6cc9dea8c0741ffed0eb35445a62b1eb..90eef006042c7898e7480d9f4d75e340f2e9287e 100644 (file)
@@ -116,6 +116,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.
      */
@@ -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.
index fb436b8ca0b6b2d8a290f2b1894058d4ad69d5bc..b2b38ffc651bfbf20b7d3d22aec42fb78207da0a 100644 (file)
@@ -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());
         }
index fdad5a75cbe5a760450f2b7f1740ddfa65553546..49cf159e0ae2f37eb936aa6a45bb8f84c39e4227 100644 (file)
@@ -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();
-        }
-    }
-
 }