diff options
3 files changed, 111 insertions, 5 deletions
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<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 index 0000000000..a234594b8f --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/table/TooManySetColumnCollapsedCalls.html @@ -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 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; + } + +} |