]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merged fix for #2706
authorArtur Signell <artur.signell@itmill.com>
Mon, 2 Mar 2009 14:21:55 +0000 (14:21 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 2 Mar 2009 14:21:55 +0000 (14:21 +0000)
svn changeset:7002/svn branch:6.0

src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java
src/com/itmill/toolkit/tests/layouts/FormLayoutWithInvisibleComponent.java [new file with mode: 0644]

index c74f48f6ad5cbbff2523fcc15f369b5034c0f67a..6c5b13f8e23b6460dbc88888564a4e71ec8e8c71 100644 (file)
@@ -48,6 +48,10 @@ public class IFormLayout extends SimplePanel implements Container {
 
     public class IFormLayoutTable extends FlexTable {
 
+        private static final int COLUMN_CAPTION = 0;
+        private static final int COLUMN_ERRORFLAG = 1;
+        private static final int COLUMN_WIDGET = 2;
+
         private HashMap<Paintable, Caption> componentToCaption = new HashMap<Paintable, Caption>();
         private HashMap<Paintable, ErrorFlag> componentToError = new HashMap<Paintable, ErrorFlag>();
 
@@ -89,24 +93,26 @@ public class IFormLayout extends SimplePanel implements Container {
                     error = new ErrorFlag();
                     componentToError.put(p, error);
                 }
-                prepareCell(i, 2);
-                final Paintable oldComponent = (Paintable) getWidget(i, 2);
+                prepareCell(i, COLUMN_WIDGET);
+                final Paintable oldComponent = (Paintable) getWidget(i,
+                        COLUMN_WIDGET);
                 if (oldComponent == null) {
-                    setWidget(i, 2, (Widget) p);
+                    setWidget(i, COLUMN_WIDGET, (Widget) p);
                 } else if (oldComponent != p) {
                     client.unregisterPaintable(oldComponent);
-                    setWidget(i, 2, (Widget) p);
+                    setWidget(i, COLUMN_WIDGET, (Widget) p);
                 }
-                getCellFormatter().setStyleName(i, 2,
+                getCellFormatter().setStyleName(i, COLUMN_WIDGET,
                         CLASSNAME + "-contentcell");
-                getCellFormatter().setStyleName(i, 0,
+                getCellFormatter().setStyleName(i, COLUMN_CAPTION,
                         CLASSNAME + "-captioncell");
-                setWidget(i, 0, caption);
+                setWidget(i, COLUMN_CAPTION, caption);
 
                 setContentWidth(i);
 
-                getCellFormatter().setStyleName(i, 1, CLASSNAME + "-errorcell");
-                setWidget(i, 1, error);
+                getCellFormatter().setStyleName(i, COLUMN_ERRORFLAG,
+                        CLASSNAME + "-errorcell");
+                setWidget(i, COLUMN_ERRORFLAG, error);
 
                 p.updateFromUIDL(childUidl, client);
 
@@ -123,7 +129,7 @@ public class IFormLayout extends SimplePanel implements Container {
             }
 
             while (getRowCount() > i) {
-                final Paintable p = (Paintable) getWidget(i, 2);
+                final Paintable p = (Paintable) getWidget(i, COLUMN_WIDGET);
                 client.unregisterPaintable(p);
                 componentToCaption.remove(p);
                 removeRow(i);
@@ -149,18 +155,27 @@ public class IFormLayout extends SimplePanel implements Container {
             if (!isDynamicWidth()) {
                 width = "100%";
             }
-            getCellFormatter().setWidth(row, 2, width);
+            getCellFormatter().setWidth(row, COLUMN_WIDGET, width);
         }
 
         public void replaceChildComponent(Widget oldComponent,
                 Widget newComponent) {
             int i;
             for (i = 0; i < getRowCount(); i++) {
-                if (oldComponent == getWidget(i, 1)) {
+                Widget candidate = getWidget(i, COLUMN_WIDGET);
+                if (oldComponent == candidate) {
                     final Caption newCap = new Caption(
                             (Paintable) newComponent, client);
-                    setWidget(i, 0, newCap);
-                    setWidget(i, 1, newComponent);
+                    componentToCaption.put((Paintable) newComponent, newCap);
+                    ErrorFlag error = componentToError.get(newComponent);
+                    if (error == null) {
+                        error = new ErrorFlag();
+                        componentToError.put((Paintable) newComponent, error);
+                    }
+
+                    setWidget(i, COLUMN_CAPTION, newCap);
+                    setWidget(i, COLUMN_ERRORFLAG, error);
+                    setWidget(i, COLUMN_WIDGET, newComponent);
                     break;
                 }
             }
diff --git a/src/com/itmill/toolkit/tests/layouts/FormLayoutWithInvisibleComponent.java b/src/com/itmill/toolkit/tests/layouts/FormLayoutWithInvisibleComponent.java
new file mode 100644 (file)
index 0000000..540fa6d
--- /dev/null
@@ -0,0 +1,49 @@
+package com.itmill.toolkit.tests.layouts;
+
+import com.itmill.toolkit.tests.components.TestBase;
+import com.itmill.toolkit.ui.Button;
+import com.itmill.toolkit.ui.CheckBox;
+import com.itmill.toolkit.ui.FormLayout;
+import com.itmill.toolkit.ui.TextField;
+import com.itmill.toolkit.ui.Button.ClickEvent;
+
+public class FormLayoutWithInvisibleComponent extends TestBase {
+
+    private TextField messages;
+
+    @Override
+    protected String getDescription() {
+        return "There is an initial invisible text field below the checkbox. Checking the checkbox should show the field as a textarea (40x10) and also show its caption(\"Messages visible\") and a required error (*).";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 2706;
+    }
+
+    @Override
+    protected void setup() {
+        FormLayout formLayout = new FormLayout();
+        CheckBox control = new CheckBox("Messages On/Off",
+                new Button.ClickListener() {
+                    public void buttonClick(ClickEvent event) {
+                        messages.setVisible(event.getButton().booleanValue());
+                        messages.setRequired(true);
+                        messages.setCaption("Messages visible");
+                    }
+
+                });
+        control.setImmediate(true);
+        formLayout.addComponent(control);
+
+        messages = new TextField("Messages hidden");
+        messages.setRows(10);
+        messages.setColumns(40);
+        messages.setVisible(false);
+        messages.setEnabled(false);
+        formLayout.addComponent(messages);
+
+        addComponent(formLayout);
+    }
+
+}