From 04f30c6892c8ddf8794ed8561fa6f00beefeec28 Mon Sep 17 00:00:00 2001 From: Pekka Hyvönen Date: Thu, 15 Dec 2016 13:46:05 +0200 Subject: Allow defining a focus delegate component for CustomField (#20336) --- .../main/java/com/vaadin/v7/ui/CustomField.java | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'compatibility-server/src/main/java/com') 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 extends AbstractField private class ComponentIterator implements Iterator, Serializable { - boolean first = (root != null); + boolean first = root != null; @Override public boolean hasNext() { @@ -153,4 +153,53 @@ public abstract class CustomField extends AbstractField public Iterator iterator() { return new ComponentIterator(); } + + /** + * Sets the component to which all methods from the {@link Focusable} + * interface should be delegated. + *

+ * 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. + *

+ * 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); + } + } } -- cgit v1.2.3