]> source.dussan.org Git - vaadin-framework.git/commitdiff
Deprecated Application.setFocusedComponent and Application.consumeFocus(), this desig...
authorJani Laakso <jani.laakso@itmill.com>
Fri, 8 Feb 2008 15:09:51 +0000 (15:09 +0000)
committerJani Laakso <jani.laakso@itmill.com>
Fri, 8 Feb 2008 15:09:51 +0000 (15:09 +0000)
Upload setFocus() now works even if it is not yet attached.

svn changeset:3755/svn branch:trunk

src/com/itmill/toolkit/Application.java
src/com/itmill/toolkit/ui/AbstractField.java
src/com/itmill/toolkit/ui/Upload.java
src/com/itmill/toolkit/ui/Window.java

index ec9c8f8b795945c6f779ee90ac93f4b5d5794e89..e5b44542d0b4972a549f35b13fb1288de41aa54f 100644 (file)
@@ -1068,6 +1068,11 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener
         return context;
     }
 
+    /**
+     * @deprecated Call component's focus method instead.
+     * 
+     * @param focusable
+     */
     public void setFocusedComponent(Focusable focusable) {
         pendingFocus = focusable;
     }
@@ -1075,6 +1080,8 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener
     /**
      * Gets and nulls focused component in this window
      * 
+     * @deprecated This method will be replaced with focus listener in the
+     *             future releases.
      * @return Focused component or null if none is focused.
      */
     public Component.Focusable consumeFocus() {
index 9d926f0e7f5bba06d4550882cdd3d34eee9a2de9..0b309ab56281f83acd7a3150559b5668801831e5 100644 (file)
@@ -11,6 +11,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 
+import com.itmill.toolkit.Application;
 import com.itmill.toolkit.data.Buffered;
 import com.itmill.toolkit.data.Property;
 import com.itmill.toolkit.data.Validatable;
@@ -848,9 +849,9 @@ public abstract class AbstractField extends AbstractComponent implements Field,
      * Asks the terminal to place the cursor to this field.
      */
     public void focus() {
-        final Window w = getWindow();
-        if (w != null) {
-            w.setFocusedComponent(this);
+        final Application app = getApplication();
+        if (app != null) {
+            app.setFocusedComponent(this);
         } else {
             delayedFocus = true;
         }
index 10123d3d5e2050424598b5df98d0b4ed269dcb6d..af5344c3cd21e0bc48b2cb5e7190138005fc19bc 100644 (file)
@@ -10,6 +10,7 @@ import java.io.OutputStream;
 import java.lang.reflect.Method;
 import java.util.Map;
 
+import com.itmill.toolkit.Application;
 import com.itmill.toolkit.terminal.PaintException;
 import com.itmill.toolkit.terminal.PaintTarget;
 import com.itmill.toolkit.terminal.UploadStream;
@@ -42,6 +43,8 @@ import com.itmill.toolkit.terminal.UploadStream;
  */
 public class Upload extends AbstractComponent implements Component.Focusable {
 
+    private boolean delayedFocus;
+
     /**
      * Upload buffer size.
      */
@@ -687,9 +690,11 @@ public class Upload extends AbstractComponent implements Component.Focusable {
      * @see com.itmill.toolkit.ui.Component.Focusable#focus()
      */
     public void focus() {
-        final Window w = getWindow();
-        if (w != null) {
-            w.setFocusedComponent(this);
+        final Application app = getApplication();
+        if (app != null) {
+            app.setFocusedComponent(this);
+        } else {
+            delayedFocus = true;
         }
     }
 
@@ -822,4 +827,18 @@ public class Upload extends AbstractComponent implements Component.Focusable {
     public void setButtonCaption(String buttonCaption) {
         this.buttonCaption = buttonCaption;
     }
+
+    /**
+     * Notifies the component that it is connected to an application.
+     * 
+     * @see com.itmill.toolkit.ui.Component#attach()
+     */
+    public void attach() {
+        super.attach();
+        if (delayedFocus) {
+            delayedFocus = false;
+            focus();
+        }
+    }
+
 }
index a042a30776ccb33b80b9ee364817798b6c400ccc..416270f19432f4085bd8d2b2cb0620a73db536f4 100644 (file)
@@ -93,11 +93,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
      */
     private int border = BORDER_DEFAULT;
 
-    /**
-     * Focused component.
-     */
-    private Focusable focusedComponent;
-
     /**
      * Distance of Window top border in pixels from top border of the containing
      * (main window) or -1 if unspecified.
@@ -871,29 +866,6 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
         }
     }
 
-    /**
-     * Gets the currently focused component in this window.
-     * 
-     * @return the Focused component or null if none is focused.
-     */
-    public Component.Focusable getFocusedComponent() {
-        return focusedComponent;
-    }
-
-    /**
-     * Sets the currently focused component in this window.
-     * 
-     * @param focusable
-     *                the Focused component or null if none is focused.
-     */
-    public void setFocusedComponent(Component.Focusable focusable) {
-        final Application app = getApplication();
-        if (app != null) {
-            app.setFocusedComponent(focusable);
-            focusedComponent = focusable;
-        }
-    }
-
     /**
      * Gets the distance of Window left border in pixels from left border of the
      * containing (main window).