diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2016-12-15 13:46:05 +0200 |
---|---|---|
committer | Aleksi Hietanen <aleksi@vaadin.com> | 2016-12-15 13:46:05 +0200 |
commit | 04f30c6892c8ddf8794ed8561fa6f00beefeec28 (patch) | |
tree | 335763bd648d44da995b7a8d0495f07a8c610270 /compatibility-server/src/main/java/com | |
parent | 10d4d70b5e2ee7879eec67f1ce91fea01929b5a1 (diff) | |
download | vaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.tar.gz vaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.zip |
Allow defining a focus delegate component for CustomField (#20336)
Diffstat (limited to 'compatibility-server/src/main/java/com')
-rw-r--r-- | compatibility-server/src/main/java/com/vaadin/v7/ui/CustomField.java | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/CustomField.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/CustomField.java index 989bef22ec..c2e6c3f40f 100644 --- a/compatibility-server/src/main/java/com/vaadin/v7/ui/CustomField.java +++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/CustomField.java @@ -130,7 +130,7 @@ public abstract class CustomField<T> extends AbstractField<T> private class ComponentIterator implements Iterator<Component>, Serializable { - boolean first = (root != null); + boolean first = root != null; @Override public boolean hasNext() { @@ -153,4 +153,53 @@ public abstract class CustomField<T> extends AbstractField<T> public Iterator<Component> iterator() { return new ComponentIterator(); } + + /** + * Sets the component to which all methods from the {@link Focusable} + * interface should be delegated. + * <p> + * Set this to a wrapped field to include that field in the tabbing order, + * to make it receive focus when {@link #focus()} is called and to make it + * be correctly focused when used as a Grid editor component. + * <p> + * By default, {@link Focusable} events are handled by the super class and + * ultimately ignored. + * + * @param focusDelegate + * the focusable component to which focus events are redirected + */ + public void setFocusDelegate(Focusable focusDelegate) { + getState().focusDelegate = focusDelegate; + } + + private Focusable getFocusable() { + return (Focusable) getState(false).focusDelegate; + } + + @Override + public void focus() { + if (getFocusable() != null) { + getFocusable().focus(); + } else { + super.focus(); + } + } + + @Override + public int getTabIndex() { + if (getFocusable() != null) { + return getFocusable().getTabIndex(); + } else { + return super.getTabIndex(); + } + } + + @Override + public void setTabIndex(int tabIndex) { + if (getFocusable() != null) { + getFocusable().setTabIndex(tabIndex); + } else { + super.setTabIndex(tabIndex); + } + } } |