From 96845bea4d6d1f01dc0d22d2a3f19058a883eb4a Mon Sep 17 00:00:00 2001 From: Anna Koskinen Date: Fri, 11 Jan 2013 13:14:56 +0200 Subject: [PATCH] Merge of (#5681) to Vaadin 7. Column collapsing optimization. Change-Id: I3b27024569ee2c5aa464ff6a63e50dcf4a90a8ba --- server/src/com/vaadin/ui/Table.java | 17 +++-- .../table/TooManySetColumnCollapsedCalls.html | 36 +++++++++++ .../table/TooManySetColumnCollapsedCalls.java | 63 +++++++++++++++++++ 3 files changed, 111 insertions(+), 5 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.java diff --git a/server/src/com/vaadin/ui/Table.java b/server/src/com/vaadin/ui/Table.java index 7b6ccc00db..57f196d704 100644 --- a/server/src/com/vaadin/ui/Table.java +++ b/server/src/com/vaadin/ui/Table.java @@ -2717,13 +2717,20 @@ public class Table extends AbstractSelect implements Action.Container, try { final Object[] ids = (Object[]) variables .get("collapsedcolumns"); + Set idSet = new HashSet(); + for (Object id : ids) { + idSet.add(columnIdMap.get(id.toString())); + } for (final Iterator 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 index 0000000000..a234594b8f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html @@ -0,0 +1,36 @@ + + + + + + +TooManySetColumnCollapsedCalls + + + + + + + + + + + + + + + + + + + + + + + + + + +
TooManySetColumnCollapsedCalls
open/run/com.vaadin.tests.components.table.TooManySetColumnCollapsedCalls?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstableTooManySetColumnCollapsedCalls::PID_Stable/domChild[0]/domChild[1]5,9
mouseClickvaadin=runcomvaadintestscomponentstableTooManySetColumnCollapsedCalls::Root/VContextMenu[0]#option12,7
assertTextlabel2
+ + 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 index 0000000000..30921392e8 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.java @@ -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; + } + +} -- 2.39.5