diff options
3 files changed, 99 insertions, 8 deletions
diff --git a/src/com/vaadin/ui/TreeTable.java b/src/com/vaadin/ui/TreeTable.java index c3731ebaef..fa80476fc8 100644 --- a/src/com/vaadin/ui/TreeTable.java +++ b/src/com/vaadin/ui/TreeTable.java @@ -657,7 +657,8 @@ public class TreeTable extends Table implements Hierarchical { */ public void setCollapsed(Object itemId, boolean collapsed) { if (isCollapsed(itemId) != collapsed) { - if (null == toggledItemId && !isRowCacheInvalidated()) { + if (null == toggledItemId && getVisibleItemIds().contains(itemId) + && !isRowCacheInvalidated()) { // optimization: partial refresh if only one item is // collapsed/expanded toggledItemId = itemId; diff --git a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html index a9eb80e4d8..44dd858378 100644 --- a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html +++ b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html @@ -18,7 +18,7 @@ </tr> <tr> <td>click</td> - <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> <td></td> </tr> <tr> @@ -33,7 +33,7 @@ </tr> <tr> <td>click</td> - <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td> <td></td> </tr> <tr> @@ -46,6 +46,66 @@ <td>//body/div[2]</td> <td>0,0</td> </tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>closeNotification</td> + <td>//body/div[2]</td> + <td>0,0</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>lastexpanded</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>closeNotification</td> + <td>//body/div[2]</td> + <td>0,0</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>lastcollapsed</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>closeNotification</td> + <td>//body/div[2]</td> + <td>0,0</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>manyexpanded</td> +</tr> +<tr> + <td>click</td> + <td>vaadin=runcomvaadintestscomponentstreetableProgrammaticCollapse::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td> + <td></td> +</tr> +<tr> + <td>closeNotification</td> + <td>//body/div[2]</td> + <td>0,0</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>manycollapsed</td> +</tr> </tbody></table> </body> diff --git a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java index f37e5c5888..6f2e507ce3 100644 --- a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java +++ b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java @@ -4,20 +4,28 @@ 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.HorizontalLayout; import com.vaadin.ui.TreeTable; +import com.vaadin.ui.VerticalLayout; public class ProgrammaticCollapse extends TestBase { @Override protected void setup() { - HorizontalLayout layout = new HorizontalLayout(); + VerticalLayout layout = new VerticalLayout(); final TreeTable table = new TreeTable(); + table.setPageLength(10); table.addContainerProperty("A", String.class, null); table.addContainerProperty("B", String.class, null); - table.addItem(new Object[] { "A1", "B1" }, 1); - table.addItem(new Object[] { "A2", "B2" }, 2); - table.setParent(2, 1); + for (int i = 1; i <= 100; ++i) { + int parentid = i; + table.addItem(new Object[] { "A" + i, "B" + i }, parentid); + for (int j = 1; j < 5; ++j) { + int id = 1000 * i + j; + table.addItem(new Object[] { "A" + i + "." + j, + "B" + i + "." + j }, id); + table.setParent(id, parentid); + } + } layout.addComponent(table); layout.addComponent(new Button("Expand / Collapse", new ClickListener() { @@ -28,6 +36,28 @@ public class ProgrammaticCollapse extends TestBase { table.setCollapsed(1, collapsed); } })); + layout.addComponent(new Button("Expand / Collapse last", + new ClickListener() { + public void buttonClick(ClickEvent event) { + boolean collapsed = !table.isCollapsed(100); + table.getWindow().showNotification( + "set collapsed: " + collapsed); + table.setCollapsed(100, collapsed); + } + })); + layout.addComponent(new Button("Expand / Collapse multiple", + new ClickListener() { + private boolean collapsed = true; + + public void buttonClick(ClickEvent event) { + collapsed = !collapsed; + table.getWindow().showNotification( + "set collapsed: " + collapsed); + for (int i = 0; i < 50; ++i) { + table.setCollapsed(i * 2, collapsed); + } + } + })); addComponent(layout); } |