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>();
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);
}
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);
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;
}
}
--- /dev/null
+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);
+ }
+
+}