]> source.dussan.org Git - vaadin-framework.git/commitdiff
svn changeset:5558/svn branch:trunk
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 30 Sep 2008 11:13:49 +0000 (11:13 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 30 Sep 2008 11:13:49 +0000 (11:13 +0000)
src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java
src/com/itmill/toolkit/ui/AbstractField.java
src/com/itmill/toolkit/ui/Component.java
src/com/itmill/toolkit/ui/Upload.java
src/com/itmill/toolkit/ui/Window.java

index abcc93b1dae6e65c2c848d5979fe373fa6bfcfe7..e2f11b29a0cc5e4dfab73378b58ff74627954de5 100644 (file)
@@ -479,15 +479,6 @@ public class CommunicationManager implements Paintable.RepaintRequestListener {
                 timeoutInterval = newTimeoutInterval;
             }
 
-            // add meta instruction for client to set focus if it is set
-            final Paintable f = (Paintable) application.consumeFocus();
-            if (f != null) {
-                if (metaOpen) {
-                    outWriter.write(",");
-                }
-                outWriter.write("\"focus\":\"" + getPaintableId(f) + "\"");
-            }
-
             outWriter.print("}, \"resources\" : {");
 
             // Precache custom layouts
index 285d1a3dfed2768f904007e26a9d59abb24aea5a..fa1faecd0bceb5c9f1fddf0d00910d3a96bbd833 100644 (file)
@@ -925,13 +925,16 @@ public abstract class AbstractField extends AbstractComponent implements Field,
 
     }
 
-    /**
-     * Asks the terminal to place the cursor to this field.
+    /*
+     * (non-Javadoc)
+     * 
+     * @see com.itmill.toolkit.ui.Component.Focusable#focus()
      */
     public void focus() {
         final Application app = getApplication();
         if (app != null) {
-            app.setFocusedComponent(this);
+            getWindow().setFocusedComponent(this);
+            delayedFocus = false;
         } else {
             delayedFocus = true;
         }
@@ -1013,8 +1016,6 @@ public abstract class AbstractField extends AbstractComponent implements Field,
     public void attach() {
         super.attach();
         if (delayedFocus) {
-
-            delayedFocus = false;
             focus();
         }
     }
index dec180cdbacb74ad5b38d9500372d15a160155cf..7c90a25a085313fea00fdd3b57bf5390d86b3958 100644 (file)
@@ -401,7 +401,7 @@ public interface Component extends Paintable, VariableOwner, Sizeable {
     /**
      * Interface implemented by components which can obtain input focus.
      */
-    public interface Focusable {
+    public interface Focusable extends Component {
 
         /**
          * Sets the focus to this component.
index 8f45bf04df29ed0035590389ff669fd601b9b739..43b9274ec5a85a6ded0595cf147045af3561e138 100644 (file)
@@ -845,15 +845,16 @@ public class Upload extends AbstractComponent implements Component.Focusable {
         this.receiver = receiver;
     }
 
-    /**
-     * Sets the focus to this component.
+    /*
+     * (non-Javadoc)
      * 
      * @see com.itmill.toolkit.ui.Component.Focusable#focus()
      */
     public void focus() {
         final Application app = getApplication();
         if (app != null) {
-            app.setFocusedComponent(this);
+            getWindow().setFocusedComponent(this);
+            delayedFocus = false;
         } else {
             delayedFocus = true;
         }
@@ -998,7 +999,6 @@ public class Upload extends AbstractComponent implements Component.Focusable {
     public void attach() {
         super.attach();
         if (delayedFocus) {
-            delayedFocus = false;
             focus();
         }
     }
index c3d4e234d29cf2d18426a1747374802126f2d1dc..b4e204b322b95181d05ed41d0b88da0e1b0e2f55 100644 (file)
@@ -112,6 +112,8 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
 
     private boolean centerRequested = false;
 
+    private Focusable pendingFocus;
+
     /* ********************************************************************* */
 
     /**
@@ -540,6 +542,16 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
             notifications = null;
         }
 
+        if (pendingFocus != null) {
+            // ensure focused component is still attached to this main window
+            if (pendingFocus.getWindow() == this
+                    || (pendingFocus.getWindow() != null && pendingFocus
+                            .getWindow().getParent() == this)) {
+                target.paintReference(pendingFocus, "focused");
+            }
+            pendingFocus = null;
+        }
+
     }
 
     /* ********************************************************************* */
@@ -1193,6 +1205,29 @@ public class Window extends Panel implements URIHandler, ParameterHandler {
         requestRepaint();
     }
 
+    /**
+     * This method is used by Component.Focusable objects to request focus to
+     * themselves. Focus renders must be handled at window level (instead of
+     * Component.Focusable) due we want the last focused component to be focused
+     * in client too. Not the one that is rendered last (the case we'd get if
+     * implemented in Focusable only).
+     * 
+     * To focus component from Toolkit application, use Focusable.focus(). See
+     * {@link Focusable}.
+     * 
+     * @param focusable
+     *            to be focused on next paint
+     */
+    void setFocusedComponent(Focusable focusable) {
+        if (getParent() != null) {
+            // focus is handled by main windows
+            ((Window) getParent()).setFocusedComponent(focusable);
+        } else {
+            pendingFocus = focusable;
+            requestRepaint();
+        }
+    }
+
     /**
      * A notification message, used to display temporary messages to the user -
      * for example "Document saved", or "Save failed".