aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java25
-rw-r--r--uitest/src/main/java/com/vaadin/tests/components/formlayout/FormLayoutClickListener.java71
-rw-r--r--uitest/src/test/java/com/vaadin/tests/components/formlayout/FormLayoutClickListenerTest.java87
3 files changed, 183 insertions, 0 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java b/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java
index 3f0b4345c4..39992d91a6 100644
--- a/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java
+++ b/client/src/main/java/com/vaadin/client/ui/formlayout/FormLayoutConnector.java
@@ -24,10 +24,12 @@ import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorHierarchyChangeEvent;
import com.vaadin.client.LayoutManager;
import com.vaadin.client.TooltipInfo;
+import com.vaadin.client.Util;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.StateChangeEvent;
import com.vaadin.client.ui.AbstractFieldConnector;
import com.vaadin.client.ui.AbstractLayoutConnector;
+import com.vaadin.client.ui.LayoutClickEventHandler;
import com.vaadin.client.ui.PostLayoutListener;
import com.vaadin.client.ui.VFormLayout;
import com.vaadin.client.ui.VFormLayout.Caption;
@@ -36,7 +38,9 @@ import com.vaadin.client.ui.VFormLayout.VFormLayoutTable;
import com.vaadin.client.ui.layout.ElementResizeEvent;
import com.vaadin.client.ui.layout.ElementResizeListener;
import com.vaadin.shared.ui.Connect;
+import com.vaadin.shared.ui.LayoutClickRpc;
import com.vaadin.shared.ui.MarginInfo;
+import com.vaadin.shared.ui.orderedlayout.AbstractOrderedLayoutServerRpc;
import com.vaadin.shared.ui.orderedlayout.FormLayoutState;
import com.vaadin.ui.FormLayout;
@@ -44,6 +48,26 @@ import com.vaadin.ui.FormLayout;
public class FormLayoutConnector extends AbstractLayoutConnector implements
PostLayoutListener {
+ /*
+ * Handlers & Listeners
+ */
+
+ private LayoutClickEventHandler clickEventHandler = new LayoutClickEventHandler(
+ this) {
+
+ @Override
+ protected ComponentConnector getChildComponent(
+ com.google.gwt.user.client.Element element) {
+ return Util.getConnectorForElement(getConnection(), getWidget(),
+ element);
+ }
+
+ @Override
+ protected LayoutClickRpc getLayoutClickRPC() {
+ return getRpcProxy(AbstractOrderedLayoutServerRpc.class);
+ }
+ };
+
private Map<ComponentConnector, String> oldMaxWidths = null;
private static final ElementResizeListener dummyFirstCellResizeListener = new ElementResizeListener() {
@@ -143,6 +167,7 @@ public class FormLayoutConnector extends AbstractLayoutConnector implements
public void onStateChanged(StateChangeEvent stateChangeEvent) {
super.onStateChanged(stateChangeEvent);
+ clickEventHandler.handleEventHandlerRegistration();
VFormLayoutTable formLayoutTable = getWidget().table;
formLayoutTable.setMargins(new MarginInfo(getState().marginsBitmask));
diff --git a/uitest/src/main/java/com/vaadin/tests/components/formlayout/FormLayoutClickListener.java b/uitest/src/main/java/com/vaadin/tests/components/formlayout/FormLayoutClickListener.java
new file mode 100644
index 0000000000..5d2dc02ccb
--- /dev/null
+++ b/uitest/src/main/java/com/vaadin/tests/components/formlayout/FormLayoutClickListener.java
@@ -0,0 +1,71 @@
+/*
+ * 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.formlayout;
+
+import com.vaadin.event.LayoutEvents.LayoutClickEvent;
+import com.vaadin.event.LayoutEvents.LayoutClickListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.FormLayout;
+import com.vaadin.ui.Label;
+
+/**
+ * Test UI for Form layout click listener.
+ *
+ * @author Vaadin Ltd
+ */
+public class FormLayoutClickListener extends AbstractTestUIWithLog {
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ FormLayout layout = new FormLayout();
+ layout.setMargin(true);
+ layout.setSpacing(true);
+
+ layout.setId("form");
+
+ Label label = new Label("target");
+ label.setId("label");
+ layout.addComponent(label);
+
+ layout.addLayoutClickListener(new LayoutClickListener() {
+
+ @Override
+ public void layoutClick(LayoutClickEvent event) {
+ log("Child component: "
+ + (event.getChildComponent() == null ? null : event
+ .getChildComponent().getId()));
+ log("Clicked component: "
+ + (event.getClickedComponent() == null ? null : event
+ .getClickedComponent().getId()));
+ log("Source component: " + event.getComponent().getId());
+ }
+ });
+
+ addComponent(layout);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "LayoutClickListener should work in FormLayout";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 6346;
+ }
+
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/formlayout/FormLayoutClickListenerTest.java b/uitest/src/test/java/com/vaadin/tests/components/formlayout/FormLayoutClickListenerTest.java
new file mode 100644
index 0000000000..d2e64c3f22
--- /dev/null
+++ b/uitest/src/test/java/com/vaadin/tests/components/formlayout/FormLayoutClickListenerTest.java
@@ -0,0 +1,87 @@
+/*
+ * 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.formlayout;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.elements.FormLayoutElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test for form layout click listener.
+ *
+ * @author Vaadin Ltd
+ */
+public class FormLayoutClickListenerTest extends MultiBrowserTest {
+
+ @Before
+ public void setUp() {
+ openTestURL();
+ waitForElementPresent(By.id("label"));
+ }
+
+ @Test
+ public void layoutClickListener_clickOnLayout_childAndClickedComponentsAreNull() {
+ FormLayoutElement element = $(FormLayoutElement.class).first();
+ Actions actions = new Actions(getDriver());
+ actions.moveByOffset(element.getLocation().getX() + 2,
+ element.getLocation().getY() + 2).click().build().perform();
+ waitForLogRowUpdate();
+
+ Assert.assertEquals("Source component for click event must be form",
+ "3. Source component: form", getLogRow(0));
+ Assert.assertEquals("Clicked component for click event must be null",
+ "2. Clicked component: null", getLogRow(1));
+ Assert.assertEquals("Child component for click event must be null",
+ "1. Child component: null", getLogRow(2));
+ }
+
+ @Test
+ public void layoutClickListener_clickOnLabel_lableIsChildAndClickedComponent() {
+ findElement(By.id("label")).click();
+ waitForLogRowUpdate();
+
+ Assert.assertEquals("Source component for click event must be form",
+ "3. Source component: form", getLogRow(0));
+ Assert.assertEquals("Clicked component for click event must be label",
+ "2. Clicked component: label", getLogRow(1));
+ Assert.assertEquals("Child component for click event must be label",
+ "1. Child component: label", getLogRow(2));
+ }
+
+ private void waitForLogRowUpdate() {
+ waitUntil(new ExpectedCondition<Boolean>() {
+
+ @Override
+ public Boolean apply(WebDriver input) {
+ return !getLogRow(2).trim().isEmpty();
+ }
+
+ @Override
+ public String toString() {
+ // Timed out after 10 seconds waiting for ...
+ return "log rows to be updated";
+ }
+ });
+ }
+
+}