import java.util.Iterator;
import java.util.Set;
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ApplicationConnection;
import com.vaadin.client.ComponentConnector;
+import com.vaadin.client.DeferredWorker;
import com.vaadin.client.Util;
import com.vaadin.client.VCaptionWrapper;
import com.vaadin.client.VConsole;
import com.vaadin.client.ui.popupview.VisibilityChangeEvent;
import com.vaadin.client.ui.popupview.VisibilityChangeHandler;
-public class VPopupView extends HTML implements Iterable<Widget> {
+public class VPopupView extends HTML implements Iterable<Widget>,
+ DeferredWorker {
public static final String CLASSNAME = "v-popupview";
public final CustomPopup popup;
private final Label loading = new Label();
+ private boolean popupShowInProgress;
+
/**
* loading constructor
*/
@Override
public void show() {
+ popupShowInProgress = true;
// Find the shortcut action handler that should handle keyboard
// events from the popup. The events do not propagate automatically
// because the popup is directly attached to the RootPanel.
- Widget widget = VPopupView.this;
- while (shortcutActionHandler == null && widget != null) {
- if (widget instanceof ShortcutActionHandlerOwner) {
- shortcutActionHandler = ((ShortcutActionHandlerOwner) widget)
- .getShortcutActionHandler();
- }
- widget = widget.getParent();
- }
super.show();
+
+ /*
+ * Shortcut actions could be set (and currently in 7.2 they ARE SET
+ * via old style "updateFromUIDL" method, see f.e. UIConnector)
+ * AFTER method show() has been invoked (which is called as a
+ * reaction on change in component hierarchy). As a result there
+ * could be no shortcutActionHandler set yet. So let's postpone
+ * search of shortcutActionHandler.
+ */
+ Scheduler.get().scheduleDeferred(new ScheduledCommand() {
+ @Override
+ public void execute() {
+ try {
+ if (shortcutActionHandler == null) {
+ shortcutActionHandler = findShortcutActionHandler();
+ }
+ } finally {
+ popupShowInProgress = false;
+ }
+ }
+ });
}
/**
positionOrSizeUpdated();
}
+ private ShortcutActionHandler findShortcutActionHandler() {
+ Widget widget = VPopupView.this;
+ ShortcutActionHandler handler = null;
+ while (handler == null && widget != null) {
+ if (widget instanceof ShortcutActionHandlerOwner) {
+ handler = ((ShortcutActionHandlerOwner) widget)
+ .getShortcutActionHandler();
+ }
+ widget = widget.getParent();
+ }
+ return handler;
+ }
}// class CustomPopup
public HandlerRegistration addVisibilityChangeHandler(
return Collections.singleton((Widget) popup).iterator();
}
+ @Override
+ public boolean isWorkPending() {
+ return popupShowInProgress;
+ }
+
}// class VPopupView
--- /dev/null
+/*
+ * Copyright 2000-2014 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.popupview;
+
+import com.vaadin.event.ShortcutAction;
+import com.vaadin.event.ShortcutListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Component;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.PopupView;
+import com.vaadin.ui.TextField;
+
+/**
+ * Test UI to check availability of shortcut action listener in the popup view
+ * oeverlay component.
+ *
+ * @author Vaadin Ltd
+ */
+public class PopupViewShortcutActionHandler extends AbstractTestUI {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ addComponent(new PopupView(new DemoPoupView()));
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Shortcut listener search should be executed in the end "
+ + "of request (after legacy UIDL request handling).";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14275;
+ }
+
+ private class DemoPoupView implements PopupView.Content {
+
+ @Override
+ public String getMinimizedValueAsHTML() {
+ return "Click Me";
+ }
+
+ @Override
+ public Component getPopupComponent() {
+ TextField field = new TextField("Enter text");
+ field.setImmediate(true);
+ field.addShortcutListener(new ShortcutListener("SearchAction",
+ ShortcutAction.KeyCode.ENTER, null) {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void handleAction(Object sender, Object target) {
+ Label label = new Label(
+ "shortcut addedEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE");
+ label.addStyleName("shortcut-result");
+ addComponent(label);
+ }
+ });
+ return field;
+ }
+
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.popupview;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.phantomjs.PhantomJSDriver;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.TestBench;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Check availability of shortcut action listener in the popup view.
+ *
+ * @author Vaadin Ltd
+ */
+public class PopupViewShortcutActionHandlerTest extends MultiBrowserTest {
+
+ @Test
+ public void testShortcutHandling() {
+ openTestURL();
+
+ getDriver().findElement(By.className("v-popupview")).click();
+ WebElement textField = getDriver().findElement(
+ By.className("v-textfield"));
+ textField.sendKeys("a", Keys.ENTER);
+
+ Assert.assertTrue(
+ "Unable to find label component which is the result of"
+ + " shortcut action handling.",
+ isElementPresent(By.className("shortcut-result")));
+ }
+
+ @Override
+ protected void setupDriver() throws Exception {
+ System.setProperty("phantomjs.binary.path",
+ "C:\\tmp\\phantom\\phantomjs.exe");
+ WebDriver dr = TestBench.createDriver(new PhantomJSDriver());
+ setDriver(dr);
+ }
+
+ @Override
+ protected String getScreenshotDirectory() {
+ return "C:\\tmp\\a";
+ }
+
+ @Override
+ protected void openTestURL() {
+ driver.get("http://localhost:8080/vaadin/run/PopupViewShortcutActionHandler");
+ }
+
+ @Override
+ public List<DesiredCapabilities> getBrowsersToTest() {
+ return Collections.singletonList(Browser.FIREFOX
+ .getDesiredCapabilities());
+ }
+
+}