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
}
- /**
- * 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;
}
public void attach() {
super.attach();
if (delayedFocus) {
-
- delayedFocus = false;
focus();
}
}
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;
}
public void attach() {
super.attach();
if (delayedFocus) {
- delayedFocus = false;
focus();
}
}
private boolean centerRequested = false;
+ private Focusable pendingFocus;
+
/* ********************************************************************* */
/**
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;
+ }
+
}
/* ********************************************************************* */
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".