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-client | |
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-client')
-rw-r--r-- | compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCustomField.java | 60 | ||||
-rw-r--r-- | compatibility-client/src/main/java/com/vaadin/v7/client/ui/customfield/CustomFieldConnector.java | 35 |
2 files changed, 92 insertions, 3 deletions
diff --git a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCustomField.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCustomField.java new file mode 100644 index 0000000000..f826e5d620 --- /dev/null +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/VCustomField.java @@ -0,0 +1,60 @@ +/* + * 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.v7.client.ui; + +import com.vaadin.client.Focusable; + +@Deprecated +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/compatibility-client/src/main/java/com/vaadin/v7/client/ui/customfield/CustomFieldConnector.java b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/customfield/CustomFieldConnector.java index 2d26c7c040..f72672b43d 100644 --- a/compatibility-client/src/main/java/com/vaadin/v7/client/ui/customfield/CustomFieldConnector.java +++ b/compatibility-client/src/main/java/com/vaadin/v7/client/ui/customfield/CustomFieldConnector.java @@ -17,16 +17,19 @@ package com.vaadin.v7.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.shared.ui.Connect; import com.vaadin.v7.client.ui.AbstractFieldConnector; -import com.vaadin.v7.client.ui.VCustomComponent; +import com.vaadin.v7.client.ui.VCustomField; import com.vaadin.v7.ui.CustomField; @Connect(value = CustomField.class) @@ -43,8 +46,8 @@ public class CustomFieldConnector extends AbstractFieldConnector } @Override - public VCustomComponent getWidget() { - return (VCustomComponent) super.getWidget(); + public VCustomField getWidget() { + return (VCustomField) super.getWidget(); } @Override @@ -53,6 +56,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 |