Upload setFocus() now works even if it is not yet attached.
svn changeset:3755/svn branch:trunk
return context;
}
+ /**
+ * @deprecated Call component's focus method instead.
+ *
+ * @param focusable
+ */
public void setFocusedComponent(Focusable focusable) {
pendingFocus = focusable;
}
/**
* 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() {
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;
* 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;
}
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;
*/
public class Upload extends AbstractComponent implements Component.Focusable {
+ private boolean delayedFocus;
+
/**
* Upload buffer size.
*/
* @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;
}
}
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();
+ }
+ }
+
}
*/
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.
}
}
- /**
- * 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).