]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #7143 backported to vaadin 6.6
authorJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Fri, 26 Aug 2011 08:05:27 +0000 (08:05 +0000)
committerJonatan Kronqvist <jonatan.kronqvist@itmill.com>
Fri, 26 Aug 2011 08:05:27 +0000 (08:05 +0000)
svn changeset:20682/svn branch:6.6

src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java
tests/src/com/vaadin/tests/components/table/HiddenColumnsExpandRatios.java [new file with mode: 0644]

index 337e27a875a3f288237099ae0d2ad71f3c322624..272202c455b7c877533065590fcfaacd00d84457 100644 (file)
@@ -2489,6 +2489,10 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
         }
 
         public void setExpandRatio(float floatAttribute) {
+            if (floatAttribute != expandRatio) {
+                lazyAdjustColumnWidths.cancel();
+                lazyAdjustColumnWidths.schedule(LAZY_COLUMN_ADJUST_TIMEOUT);
+            }
             expandRatio = floatAttribute;
         }
 
@@ -2681,6 +2685,11 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,
                 if (!updated.contains(cid)) {
                     removeCell(cid);
                     cit.remove();
+                    // we will need a column width recalculation, since columns
+                    // with expand ratios should expand to fill the void.
+                    initializedAndAttached = false;
+                    initialContentReceived = false;
+                    isNewBody = true;
                 }
             }
         }
diff --git a/tests/src/com/vaadin/tests/components/table/HiddenColumnsExpandRatios.java b/tests/src/com/vaadin/tests/components/table/HiddenColumnsExpandRatios.java
new file mode 100644 (file)
index 0000000..007c935
--- /dev/null
@@ -0,0 +1,75 @@
+package com.vaadin.tests.components.table;
+
+import java.util.Random;
+
+import com.vaadin.data.Item;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.Table;
+
+public class HiddenColumnsExpandRatios extends TestBase {
+
+    @Override
+    protected void setup() {
+        final Table table = new Table();
+        table.setColumnCollapsingAllowed(true);
+        table.setWidth("800px");
+        addComponent(table);
+        table.addContainerProperty("foo", String.class, "");
+        table.addContainerProperty("bar", String.class, "");
+        table.addContainerProperty("baz", String.class, "");
+        table.addContainerProperty("asdf", String.class, "");
+        table.addContainerProperty("sdfg", String.class, "");
+        table.addContainerProperty("dfgh", String.class, "");
+        table.setColumnExpandRatio("bar", 1.0f);
+        for (int i = 0; i < 10; i++) {
+            Item item = table.addItem(i);
+            item.getItemProperty("foo").setValue(genValue());
+            item.getItemProperty("bar").setValue(genValue());
+            item.getItemProperty("baz").setValue(genValue());
+            item.getItemProperty("asdf").setValue(genValue());
+            item.getItemProperty("sdfg").setValue(genValue());
+            item.getItemProperty("dfgh").setValue(genValue());
+        }
+
+        addComponent(new Button("All", new ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                table.setVisibleColumns(table.getContainerPropertyIds()
+                        .toArray());
+            }
+        }));
+        addComponent(new Button("Some", new ClickListener() {
+            public void buttonClick(ClickEvent event) {
+                table.setWidth("100px");
+                table.setWidth("800px");
+                table.setVisibleColumns(new Object[] { "foo", "bar", "baz" });
+            }
+        }));
+    }
+
+    private String genValue() {
+        Random rnd = new Random();
+        StringBuffer str = new StringBuffer("");
+        String[] strings = new String[] { "foo", "bar", "baz" };
+        for (int i = 0; i < 5; i++) {
+            str.append(strings[Math.abs(rnd.nextInt() % strings.length)])
+                    .append(" ");
+        }
+        return str.toString();
+    }
+
+    @Override
+    protected String getDescription() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+}