]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix caption updating in CustomLayout (#8415) 8655/head pr8655/r2
authorArtur <artur@vaadin.com>
Thu, 2 Feb 2017 08:53:03 +0000 (10:53 +0200)
committerHenri Sara <henri.sara@gmail.com>
Thu, 2 Feb 2017 08:53:03 +0000 (10:53 +0200)
Fixes #8413

client/src/main/java/com/vaadin/client/ui/VCustomLayout.java
uitest/src/main/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaption.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaptionTest.java [new file with mode: 0644]

index 33ac090aae0124dc0ac38734840d6fbda80d7140..58ae554b0bc04efe474e0072c5c7148c84e9e626 100644 (file)
@@ -301,19 +301,21 @@ public class VCustomLayout extends ComplexPanel {
     }
 
     /** Update caption for given widget */
-    public void updateCaption(ComponentConnector paintable) {
-        Widget widget = paintable.getWidget();
-        if (widget.getParent() != this) {
+    public void updateCaption(ComponentConnector childConnector) {
+        Widget widget = childConnector.getWidget();
+
+        if (!widget.isAttached()) {
             // Widget has not been added because the location was not found
             return;
         }
+
         VCaptionWrapper wrapper = childWidgetToCaptionWrapper.get(widget);
-        if (VCaption.isNeeded(paintable.getState())) {
+        if (VCaption.isNeeded(childConnector.getState())) {
             if (wrapper == null) {
                 // Add a wrapper between the layout and the child widget
                 final String loc = getLocation(widget);
                 super.remove(widget);
-                wrapper = new VCaptionWrapper(paintable, client);
+                wrapper = new VCaptionWrapper(childConnector, client);
                 super.add(wrapper, locationToElement.get(loc));
                 childWidgetToCaptionWrapper.put(widget, wrapper);
             }
diff --git a/uitest/src/main/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaption.java b/uitest/src/main/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaption.java
new file mode 100644 (file)
index 0000000..88e6a87
--- /dev/null
@@ -0,0 +1,40 @@
+package com.vaadin.tests.components.customlayout;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CustomLayout;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.UI;
+import com.vaadin.ui.VerticalLayout;
+
+public class CustomLayoutUpdateCaption extends UI {
+    @Override
+    protected void init(VaadinRequest vaadinRequest) {
+        CustomLayout content = new CustomLayout();
+        content.setTemplateContents("<div>\n"
+                + "        <div location=\"test1\"></div>\n"
+                + "        <div location=\"test2\"></div>\n"
+                + "        <div location=\"okbutton\"></div>\n" + "</div>");
+        content.setSizeUndefined();
+        setContent(content);
+
+        Button loginButton = new Button("Test");
+        final TextField username1 = new TextField();
+        final TextField username2 = new TextField();
+        username1.setCaption("initial");
+        username2.setCaption("initial");
+        content.addComponent(username1, "test1");
+        content.addComponent(new VerticalLayout(username2), "test2");
+        content.addComponent(loginButton, "okbutton");
+
+        loginButton.addClickListener(new ClickListener() {
+            @Override
+            public void buttonClick(ClickEvent e) {
+                username1.setCaption("updated");
+                username2.setCaption("updated");
+            }
+        });
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaptionTest.java b/uitest/src/test/java/com/vaadin/tests/components/customlayout/CustomLayoutUpdateCaptionTest.java
new file mode 100644 (file)
index 0000000..0a77826
--- /dev/null
@@ -0,0 +1,30 @@
+package com.vaadin.tests.components.customlayout;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TextFieldElement;
+import com.vaadin.tests.tb3.SingleBrowserTest;
+
+public class CustomLayoutUpdateCaptionTest extends SingleBrowserTest {
+
+    @Test
+    public void captionUpdated() {
+        openTestURL();
+        List<TextFieldElement> tfs = $(TextFieldElement.class).all();
+        TextFieldElement tf1 = tfs.get(0);
+        TextFieldElement tf2 = tfs.get(1);
+
+        Assert.assertEquals("initial", tf1.getCaption());
+        Assert.assertEquals("initial", tf2.getCaption());
+
+        $(ButtonElement.class).first().click();
+
+        Assert.assertEquals("updated", tf1.getCaption());
+        Assert.assertEquals("updated", tf2.getCaption());
+
+    }
+}