From 662b4725dfce0fad89645c3a0896315841f1988a Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 30 Sep 2008 11:13:49 +0000 Subject: [PATCH] svn changeset:5558/svn branch:trunk --- .../gwt/server/CommunicationManager.java | 9 ----- src/com/itmill/toolkit/ui/AbstractField.java | 11 +++--- src/com/itmill/toolkit/ui/Component.java | 2 +- src/com/itmill/toolkit/ui/Upload.java | 8 ++--- src/com/itmill/toolkit/ui/Window.java | 35 +++++++++++++++++++ 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java index abcc93b1da..e2f11b29a0 100644 --- a/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java +++ b/src/com/itmill/toolkit/terminal/gwt/server/CommunicationManager.java @@ -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 diff --git a/src/com/itmill/toolkit/ui/AbstractField.java b/src/com/itmill/toolkit/ui/AbstractField.java index 285d1a3dfe..fa1faecd0b 100644 --- a/src/com/itmill/toolkit/ui/AbstractField.java +++ b/src/com/itmill/toolkit/ui/AbstractField.java @@ -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(); } } diff --git a/src/com/itmill/toolkit/ui/Component.java b/src/com/itmill/toolkit/ui/Component.java index dec180cdba..7c90a25a08 100644 --- a/src/com/itmill/toolkit/ui/Component.java +++ b/src/com/itmill/toolkit/ui/Component.java @@ -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. diff --git a/src/com/itmill/toolkit/ui/Upload.java b/src/com/itmill/toolkit/ui/Upload.java index 8f45bf04df..43b9274ec5 100644 --- a/src/com/itmill/toolkit/ui/Upload.java +++ b/src/com/itmill/toolkit/ui/Upload.java @@ -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(); } } diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index c3d4e234d2..b4e204b322 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -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". -- 2.39.5