diff options
author | Artur <artur@vaadin.com> | 2017-05-26 11:39:18 +0300 |
---|---|---|
committer | Henri Sara <henri.sara@gmail.com> | 2017-05-26 11:39:18 +0300 |
commit | 3d6a25c2f17311126e96c8f68c6741412ca318a9 (patch) | |
tree | bbe1a79cd1bf2802e9db32a0d367628856f15af6 | |
parent | 791658f3534bcdbc754f82f1e21091e85a87c52a (diff) | |
download | vaadin-framework-3d6a25c2f17311126e96c8f68c6741412ca318a9.tar.gz vaadin-framework-3d6a25c2f17311126e96c8f68c6741412ca318a9.zip |
Find active connector anywhere in the DOM (#9429)
Fixes #9419
3 files changed, 103 insertions, 3 deletions
diff --git a/client/src/main/java/com/vaadin/client/ApplicationConnection.java b/client/src/main/java/com/vaadin/client/ApplicationConnection.java index 6f2a78a2d5..5a67d41a54 100644 --- a/client/src/main/java/com/vaadin/client/ApplicationConnection.java +++ b/client/src/main/java/com/vaadin/client/ApplicationConnection.java @@ -39,6 +39,7 @@ import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.ui.HasWidgets; +import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.client.ApplicationConfiguration.ErrorMessage; import com.vaadin.client.ApplicationConnection.ApplicationStoppedEvent; @@ -1478,16 +1479,17 @@ public class ApplicationConnection implements HasHandlers { } /** - * Gets the active connector for focused element in browser. + * Gets the active connector for the focused element in the browser. * - * @return Connector for focused element or null. + * @return the connector for the focused element or <code>null</code> if + * none found or no element is focused. */ private ComponentConnector getActiveConnector() { Element focusedElement = WidgetUtil.getFocusedElement(); if (focusedElement == null) { return null; } - return Util.getConnectorForElement(this, getUIConnector().getWidget(), + return Util.getConnectorForElement(this, RootPanel.get(), focusedElement); } diff --git a/uitest/src/main/java/com/vaadin/tests/components/window/ShortcutInWindow.java b/uitest/src/main/java/com/vaadin/tests/components/window/ShortcutInWindow.java new file mode 100644 index 0000000000..983a30a8d2 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/window/ShortcutInWindow.java @@ -0,0 +1,64 @@ +/* + * 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.tests.components.window; + +import com.vaadin.annotations.Widgetset; +import com.vaadin.event.ShortcutAction.KeyCode; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.ValueChangeMode; +import com.vaadin.tests.components.AbstractTestUIWithLog; +import com.vaadin.ui.Button; +import com.vaadin.ui.HorizontalLayout; +import com.vaadin.ui.TextField; +import com.vaadin.ui.VerticalLayout; +import com.vaadin.ui.Window; + +@Widgetset("com.vaadin.DefaultWidgetSet") +public class ShortcutInWindow extends AbstractTestUIWithLog { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout content = new VerticalLayout(); + HorizontalLayout buttons = new HorizontalLayout(); + final TextField name = new TextField("Name"); + name.setValueChangeMode(ValueChangeMode.BLUR); + name.setValueChangeTimeout(1000); + name.addValueChangeListener( + (e) -> log("Value Changed: " + e.getValue())); + final Button toggle = new Button(name.getValueChangeMode().toString()); + toggle.addClickListener((e) -> { + int o = name.getValueChangeMode().ordinal(); + int i = ValueChangeMode.values().length <= o + 1 ? 0 : o + 1; + ValueChangeMode m = ValueChangeMode.values()[i]; + toggle.setCaption(m.toString()); + name.setValueChangeMode(m); + log("New ValueChangeMode: " + m.toString()); + }); + final Button submit = new Button("Submit", + (e) -> log("Submitted value: " + name.getValue())); + submit.setClickShortcut(KeyCode.ENTER); + buttons.addComponent(toggle); + buttons.addComponent(submit); + content.addComponent(name); + content.addComponent(buttons); + Window popup = new Window(); + popup.center(); + popup.setContent(content); + getUI().addWindow(popup); + + } + +} diff --git a/uitest/src/test/java/com/vaadin/tests/components/window/ShortcutInWindowTest.java b/uitest/src/test/java/com/vaadin/tests/components/window/ShortcutInWindowTest.java new file mode 100644 index 0000000000..26041d8531 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/window/ShortcutInWindowTest.java @@ -0,0 +1,34 @@ +/* + * 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.tests.components.window; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.Keys; + +import com.vaadin.testbench.elements.TextFieldElement; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ShortcutInWindowTest extends SingleBrowserTest { + + @Test + public void shortcutFlushesActiveField() { + openTestURL(); + TextFieldElement tf = $(TextFieldElement.class).first(); + tf.sendKeys("foo" + Keys.ENTER); + Assert.assertEquals("2. Submitted value: foo", getLogRow(0)); + } +} |