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

src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/tests/components/table/TableRowHeight.java [new file with mode: 0644]

index 2cd5ce5d6214e29856dfdce0087b7f40bb597f41..1f7bdcea2edcc85f78d347d7346bcf9fe1d9c449 100644 (file)
@@ -562,7 +562,12 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
 
         // fix "natural" height if height not set
         if (height == null || "".equals(height)) {
-            bodyContainer.setHeight((tBody.getRowHeight() * pageLength) + "px");
+            /*
+             * We must force an update of the row height as this point as it
+             * might have been (incorrectly) calculated earlier
+             */
+            bodyContainer.setHeight((tBody.getRowHeight(true) * pageLength)
+                    + "px");
         }
 
         // fix "natural" width if width not set
@@ -1910,7 +1915,11 @@ public class IScrollTable extends FlowPanel implements Table, ScrollListener {
         }
 
         public int getRowHeight() {
-            if (initDone) {
+            return getRowHeight(false);
+        }
+
+        public int getRowHeight(boolean forceUpdate) {
+            if (initDone && !forceUpdate) {
                 return rowHeight;
             } else {
                 if (DOM.getChildCount(tBody) > 0) {
diff --git a/src/com/itmill/toolkit/tests/components/table/TableRowHeight.java b/src/com/itmill/toolkit/tests/components/table/TableRowHeight.java
new file mode 100644 (file)
index 0000000..11b4ea8
--- /dev/null
@@ -0,0 +1,112 @@
+package com.itmill.toolkit.tests.components.table;
+
+import com.itmill.toolkit.data.Item;
+import com.itmill.toolkit.data.util.IndexedContainer;
+import com.itmill.toolkit.tests.components.TestBase;
+import com.itmill.toolkit.ui.Component;
+import com.itmill.toolkit.ui.GridLayout;
+import com.itmill.toolkit.ui.Label;
+import com.itmill.toolkit.ui.Table;
+import com.itmill.toolkit.ui.Table.ColumnGenerator;
+
+public class TableRowHeight extends TestBase {
+
+    @Override
+    protected String getDescription() {
+        return "This test case contains 4 tables in various configurations. All tables have a pageLength of "
+                + PAGELENGTH
+                + " and thus should show as many rows without any scrollbars (height is undefined for all tables).";
+
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 2691;
+    }
+
+    private static final int PAGELENGTH = 2;
+
+    public void setup() {
+        Table table1 = initTable(PAGELENGTH, false, false);
+        addComponent(new Label("Plain table"));
+        addComponent(table1);
+
+        Table table2 = initTable(PAGELENGTH, true, false);
+        addComponent(new Label("Table with label component in generated column"));
+        addComponent(table2);
+
+        Table table3 = initTable(PAGELENGTH, false, true);
+        addComponent(new Label(
+                "Table with layout component in generated column"));
+        addComponent(table3);
+
+        Table table4 = initTable(PAGELENGTH, true, true);
+        addComponent(new Label(
+                "Table with both label and layout component in generated column"));
+        addComponent(table4);
+
+    }
+
+    private Table initTable(int pageLength, boolean addLabelColGen,
+            boolean addLayoutColGen) {
+        Table table = new Table();
+        table.setWidth("100%");
+        table.setPageLength(pageLength);
+
+        IndexedContainer idx = new IndexedContainer();
+        idx.addContainerProperty("firstname", String.class, null);
+        idx.addContainerProperty("lastname", String.class, null);
+        Item i = idx.addItem(1);
+        i.getItemProperty("firstname").setValue("John");
+        i.getItemProperty("lastname").setValue("Johnson");
+        i = idx.addItem(2);
+        i.getItemProperty("firstname").setValue("Jane");
+        i.getItemProperty("lastname").setValue("Janeine");
+
+        table.setContainerDataSource(idx);
+
+        table.setColumnHeader("firstname", "FirstName");
+        table.setColumnHeader("lastname", "LastName");
+        if (addLabelColGen) {
+            table.addGeneratedColumn("name1", new LabelColumnGenerator());
+        }
+        if (addLayoutColGen) {
+            table.addGeneratedColumn("name2", new LayoutColumnGenerator());
+        }
+
+        return table;
+    }
+
+    public class LabelColumnGenerator implements ColumnGenerator {
+
+        public Component generateCell(Table source, Object itemId,
+                Object columnId) {
+            Item item = source.getItem(itemId);
+            String firstname = (String) item.getItemProperty("firstname")
+                    .getValue();
+            String lastname = (String) item.getItemProperty("lastname")
+                    .getValue();
+            Label label = new Label(firstname + " " + lastname);
+            return label;
+        }
+
+    }
+
+    public class LayoutColumnGenerator implements ColumnGenerator {
+
+        public Component generateCell(Table source, Object itemId,
+                Object columnId) {
+            Item item = source.getItem(itemId);
+            GridLayout layout = new GridLayout(1, 2);
+            String firstname = (String) item.getItemProperty("firstname")
+                    .getValue();
+            String lastname = (String) item.getItemProperty("lastname")
+                    .getValue();
+            layout.addComponent(new Label(firstname), 0, 0);
+            layout.addComponent(new Label(lastname), 0, 1);
+            return layout;
+        }
+
+    }
+
+}