summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2016-09-30 23:30:42 +0300
committerArtur Signell <artur@vaadin.com>2016-10-26 22:11:19 +0300
commit44603b49f80b4191eca8f82a8cc17243820aa2c4 (patch)
tree8bbf711428687c8903fb1528598797d88f872310 /server
parentece3ac4f2fc3db486796df8c70e9381349a8c091 (diff)
downloadvaadin-framework-44603b49f80b4191eca8f82a8cc17243820aa2c4.tar.gz
vaadin-framework-44603b49f80b4191eca8f82a8cc17243820aa2c4.zip
Allow defining a focus delegate component for CustomField (#20336)
Change-Id: I1160e7a384b1816204eb7f4b0f52f83ed9e230c0
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/CustomField.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/server/src/main/java/com/vaadin/ui/CustomField.java b/server/src/main/java/com/vaadin/ui/CustomField.java
index df8f9180c4..04c00aaf47 100644
--- a/server/src/main/java/com/vaadin/ui/CustomField.java
+++ b/server/src/main/java/com/vaadin/ui/CustomField.java
@@ -20,6 +20,7 @@ import java.io.Serializable;
import java.util.Iterator;
import com.vaadin.data.Property;
+import com.vaadin.shared.ui.customfield.CustomFieldState;
/**
* A {@link Field} whose UI content can be constructed by the user, enabling the
@@ -150,4 +151,64 @@ public abstract class CustomField<T> extends AbstractField<T>
public Iterator<Component> iterator() {
return new ComponentIterator();
}
+
+ @Override
+ protected CustomFieldState getState() {
+ return (CustomFieldState) super.getState();
+ }
+
+ @Override
+ protected CustomFieldState getState(boolean markAsDirty) {
+ return (CustomFieldState) super.getState(markAsDirty);
+ }
+
+ /**
+ * 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);
+ }
+ }
+
}