summaryrefslogtreecommitdiffstats
path: root/client/src
diff options
context:
space:
mode:
authorPekka Hyvönen <pekka@vaadin.com>2016-12-15 13:46:05 +0200
committerAleksi Hietanen <aleksi@vaadin.com>2016-12-15 13:46:05 +0200
commit04f30c6892c8ddf8794ed8561fa6f00beefeec28 (patch)
tree335763bd648d44da995b7a8d0495f07a8c610270 /client/src
parent10d4d70b5e2ee7879eec67f1ce91fea01929b5a1 (diff)
downloadvaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.tar.gz
vaadin-framework-04f30c6892c8ddf8794ed8561fa6f00beefeec28.zip
Allow defining a focus delegate component for CustomField (#20336)
Diffstat (limited to 'client/src')
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VCustomField.java59
-rw-r--r--client/src/main/java/com/vaadin/client/ui/customfield/CustomFieldConnector.java45
2 files changed, 96 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VCustomField.java b/client/src/main/java/com/vaadin/client/ui/VCustomField.java
new file mode 100644
index 0000000000..2d5039fcd8
--- /dev/null
+++ b/client/src/main/java/com/vaadin/client/ui/VCustomField.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.client.ui;
+
+import com.vaadin.client.Focusable;
+
+public class VCustomField extends VCustomComponent implements Focusable {
+
+ private Focusable focusDelegate;
+
+ @Override
+ public void focus() {
+ if (focusDelegate != null) {
+ focusDelegate.focus();
+ }
+ }
+
+ /**
+ * Sets the focusable widget to focus instead of this custom field.
+ *
+ * @param focusDelegate
+ * the widget to delegate focus to
+ */
+ public void setFocusDelegate(Focusable focusDelegate) {
+ this.focusDelegate = focusDelegate;
+
+ }
+
+ /**
+ * Sets the focusable widget to focus instead of this custom field.
+ *
+ * @param focusDelegate
+ * the widget to delegate focus to
+ */
+ public void setFocusDelegate(
+ final com.google.gwt.user.client.ui.Focusable focusDelegate) {
+ this.focusDelegate = new Focusable() {
+ @Override
+ public void focus() {
+ focusDelegate.setFocus(true);
+ }
+ };
+
+ }
+
+}
diff --git a/client/src/main/java/com/vaadin/client/ui/customfield/CustomFieldConnector.java b/client/src/main/java/com/vaadin/client/ui/customfield/CustomFieldConnector.java
index c058522c4e..47c9da6732 100644
--- a/client/src/main/java/com/vaadin/client/ui/customfield/CustomFieldConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/customfield/CustomFieldConnector.java
@@ -17,15 +17,18 @@ package com.vaadin.client.ui.customfield;
import java.util.Collections;
import java.util.List;
+import java.util.logging.Logger;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler;
+import com.vaadin.client.Focusable;
import com.vaadin.client.HasComponentsConnector;
+import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
-import com.vaadin.client.ui.VCustomComponent;
+import com.vaadin.client.ui.VCustomField;
import com.vaadin.shared.ui.Connect;
import com.vaadin.shared.ui.customfield.CustomFieldState;
import com.vaadin.ui.CustomField;
@@ -44,8 +47,13 @@ public class CustomFieldConnector extends AbstractFieldConnector
}
@Override
- public VCustomComponent getWidget() {
- return (VCustomComponent) super.getWidget();
+ public CustomFieldState getState() {
+ return (CustomFieldState) super.getState();
+ }
+
+ @Override
+ public VCustomField getWidget() {
+ return (VCustomField) super.getWidget();
}
@Override
@@ -54,6 +62,32 @@ public class CustomFieldConnector extends AbstractFieldConnector
}
@Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+ if (getState().focusDelegate != null) {
+ Widget widget = ((ComponentConnector) getState().focusDelegate)
+ .getWidget();
+ if (widget instanceof Focusable) {
+ getWidget().setFocusDelegate((Focusable) widget);
+ } else if (widget instanceof com.google.gwt.user.client.ui.Focusable) {
+ getWidget().setFocusDelegate(
+ (com.google.gwt.user.client.ui.Focusable) widget);
+ } else {
+ getLogger().warning(
+ "The given focus delegate does not implement Focusable: "
+ + widget.getClass().getName());
+ }
+ } else {
+ getWidget().setFocusDelegate((Focusable) null);
+ }
+
+ }
+
+ private static Logger getLogger() {
+ return Logger.getLogger(CustomFieldConnector.class.getName());
+ }
+
+ @Override
public void onConnectorHierarchyChange(
ConnectorHierarchyChangeEvent event) {
// We always have 1 child, unless the child is hidden
@@ -122,9 +156,4 @@ public class CustomFieldConnector extends AbstractFieldConnector
}
}
- @Override
- public CustomFieldState getState() {
- return (CustomFieldState) super.getState();
- }
-
}