]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge of (#5681) to Vaadin 7. 27/627/1
authorAnna Koskinen <anna@vaadin.com>
Fri, 11 Jan 2013 11:14:56 +0000 (13:14 +0200)
committerAnna Koskinen <anna@vaadin.com>
Fri, 11 Jan 2013 11:14:56 +0000 (13:14 +0200)
Column collapsing optimization.

Change-Id: I3b27024569ee2c5aa464ff6a63e50dcf4a90a8ba

server/src/com/vaadin/ui/Table.java
uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.java [new file with mode: 0644]

index 7b6ccc00dbd6c53b711a71f8d1ff1805f33b8788..57f196d704630b1c87cf9c41ef316e96f3c8b1ff 100644 (file)
@@ -2717,13 +2717,20 @@ public class Table extends AbstractSelect implements Action.Container,
                 try {
                     final Object[] ids = (Object[]) variables
                             .get("collapsedcolumns");
+                    Set<Object> idSet = new HashSet<Object>();
+                    for (Object id : ids) {
+                        idSet.add(columnIdMap.get(id.toString()));
+                    }
                     for (final Iterator<Object> it = visibleColumns.iterator(); it
                             .hasNext();) {
-                        setColumnCollapsed(it.next(), false);
-                    }
-                    for (int i = 0; i < ids.length; i++) {
-                        setColumnCollapsed(columnIdMap.get(ids[i].toString()),
-                                true);
+                        Object propertyId = it.next();
+                        if (isColumnCollapsed(propertyId)) {
+                            if (!idSet.contains(propertyId)) {
+                                setColumnCollapsed(propertyId, false);
+                            }
+                        } else if (idSet.contains(propertyId)) {
+                            setColumnCollapsed(propertyId, true);
+                        }
                     }
                 } catch (final Exception e) {
                     // FIXME: Handle exception
diff --git a/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html b/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html
new file mode 100644 (file)
index 0000000..a234594
--- /dev/null
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>TooManySetColumnCollapsedCalls</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">TooManySetColumnCollapsedCalls</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.table.TooManySetColumnCollapsedCalls?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTooManySetColumnCollapsedCalls::PID_Stable/domChild[0]/domChild[1]</td>
+       <td>5,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstableTooManySetColumnCollapsedCalls::Root/VContextMenu[0]#option1</td>
+       <td>2,7</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>label</td>
+       <td>2</td>
+</tr>
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.java b/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.java
new file mode 100644 (file)
index 0000000..3092139
--- /dev/null
@@ -0,0 +1,63 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+
+public class TooManySetColumnCollapsedCalls extends TestBase {
+
+    private int counter = 0;
+    private Label label;
+    private Table table;
+
+    @Override
+    protected void setup() {
+        label = new Label(String.valueOf(counter));
+        label.setId("label");
+        table = createTable();
+        table.setId("table");
+        addComponent(table);
+        addComponent(label);
+        getLayout().setSpacing(true);
+        table.setColumnCollapsed("p2", true);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Table.setColumnCollapsed is called too many times in Table.changeVariables."
+                + " Collapsing column 'P3' should only increase the counter by one.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 5681;
+    }
+
+    private Table createTable() {
+        Table table = new Table() {
+            @Override
+            public void setColumnCollapsed(Object propertyId, boolean collapsed)
+                    throws IllegalStateException {
+                ++counter;
+                label.setValue(String.valueOf(counter));
+                super.setColumnCollapsed(propertyId, collapsed);
+            }
+        };
+        table.setWidth("400px");
+        table.setHeight("100px");
+        table.setPageLength(100);
+        table.setColumnCollapsingAllowed(true);
+        table.setImmediate(true);
+        table.addContainerProperty("p1", String.class, null);
+        table.addContainerProperty("p2", String.class, null);
+        table.addContainerProperty("p3", String.class, null);
+        table.addContainerProperty("p4", String.class, null);
+
+        for (int i = 0; i < 10; i++) {
+            table.addItem(new Object[] { "a" + i, "b" + i, "c" + i, "X" + i },
+                    "" + i);
+        }
+        return table;
+    }
+
+}