From c7c069294377b9ee13829391b788949f38a4e523 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Mon, 2 Mar 2009 14:21:55 +0000 Subject: [PATCH] Merged fix for #2706 svn changeset:7002/svn branch:6.0 --- .../terminal/gwt/client/ui/IFormLayout.java | 43 ++++++++++------ .../FormLayoutWithInvisibleComponent.java | 49 +++++++++++++++++++ 2 files changed, 78 insertions(+), 14 deletions(-) create mode 100644 src/com/itmill/toolkit/tests/layouts/FormLayoutWithInvisibleComponent.java diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java index c74f48f6ad..6c5b13f8e2 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IFormLayout.java @@ -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 componentToCaption = new HashMap(); private HashMap componentToError = new HashMap(); @@ -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 index 0000000000..540fa6d261 --- /dev/null +++ b/src/com/itmill/toolkit/tests/layouts/FormLayoutWithInvisibleComponent.java @@ -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); + } + +} -- 2.39.5