summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenri Sara <henri.sara@itmill.com>2011-11-24 11:05:07 +0000
committerHenri Sara <henri.sara@itmill.com>2011-11-24 11:05:07 +0000
commit08e8d3b94008b037102f0ed7e6c257eff9d6cb4c (patch)
tree834a12fd55907fd36ea269bdd745e172ee6a7cdf
parent1c6a751a5a1315b74b3e5adac337058e803e9d1f (diff)
downloadvaadin-framework-08e8d3b94008b037102f0ed7e6c257eff9d6cb4c.tar.gz
vaadin-framework-08e8d3b94008b037102f0ed7e6c257eff9d6cb4c.zip
#7988 TreeTable.setCollapsed(...) should refresh UI
svn changeset:22119/svn branch:6.7
-rw-r--r--src/com/vaadin/ui/Table.java2
-rw-r--r--src/com/vaadin/ui/TreeTable.java25
-rw-r--r--tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html52
-rw-r--r--tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java44
4 files changed, 115 insertions, 8 deletions
diff --git a/src/com/vaadin/ui/Table.java b/src/com/vaadin/ui/Table.java
index b95d738157..f8fe76a522 100644
--- a/src/com/vaadin/ui/Table.java
+++ b/src/com/vaadin/ui/Table.java
@@ -2712,7 +2712,7 @@ public class Table extends AbstractSelect implements Action.Container,
rowCacheInvalidated = invalidated;
}
- private boolean isRowCacheInvalidated() {
+ protected boolean isRowCacheInvalidated() {
return rowCacheInvalidated;
}
diff --git a/src/com/vaadin/ui/TreeTable.java b/src/com/vaadin/ui/TreeTable.java
index fb12ffe323..c3731ebaef 100644
--- a/src/com/vaadin/ui/TreeTable.java
+++ b/src/com/vaadin/ui/TreeTable.java
@@ -385,7 +385,7 @@ public class TreeTable extends Table implements Hierarchical {
String object = (String) variables.get("toggleCollapsed");
Object itemId = itemIdMapper.get(object);
toggledItemId = itemId;
- toggleChildVisibility(itemId);
+ toggleChildVisibility(itemId, false);
if (variables.containsKey("selectCollapsed")) {
// ensure collapsed is selected unless opened with selection
// head
@@ -470,7 +470,8 @@ public class TreeTable extends Table implements Hierarchical {
@Override
protected boolean isPartialRowUpdate() {
- return toggledItemId != null && containerSupportsPartialUpdates;
+ return toggledItemId != null && containerSupportsPartialUpdates
+ && !isRowCacheInvalidated();
}
@Override
@@ -516,7 +517,7 @@ public class TreeTable extends Table implements Hierarchical {
return !getContainerStrategy().isNodeOpen(toggledItemId);
}
- private void toggleChildVisibility(Object itemId) {
+ private void toggleChildVisibility(Object itemId, boolean forceFullRefresh) {
getContainerStrategy().toggleChildVisibility(itemId);
// ensure that page still has first item in page, DON'T clear the
// caches.
@@ -528,7 +529,7 @@ public class TreeTable extends Table implements Hierarchical {
fireExpandEvent(itemId);
}
- if (containerSupportsPartialUpdates) {
+ if (containerSupportsPartialUpdates && !forceFullRefresh) {
requestRepaint();
} else {
// For containers that do not send item set change events, always do
@@ -646,8 +647,8 @@ public class TreeTable extends Table implements Hierarchical {
}
/**
- * Sets the Item specified by given identifier collapsed or expanded. If the
- * Item is collapsed, its children is not displayed in for the user.
+ * Sets the Item specified by given identifier as collapsed or expanded. If
+ * the Item is collapsed, its children are not displayed to the user.
*
* @param itemId
* the identifier of the Item
@@ -656,7 +657,17 @@ public class TreeTable extends Table implements Hierarchical {
*/
public void setCollapsed(Object itemId, boolean collapsed) {
if (isCollapsed(itemId) != collapsed) {
- toggleChildVisibility(itemId);
+ if (null == toggledItemId && !isRowCacheInvalidated()) {
+ // optimization: partial refresh if only one item is
+ // collapsed/expanded
+ toggledItemId = itemId;
+ toggleChildVisibility(itemId, false);
+ } else {
+ // make sure a full refresh takes place - otherwise neither
+ // partial nor full repaint of table content is performed
+ toggledItemId = null;
+ toggleChildVisibility(itemId, true);
+ }
}
}
diff --git a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html
new file mode 100644
index 0000000000..a9eb80e4d8
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html
@@ -0,0 +1,52 @@
+<?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>ProgrammaticCollapse</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ProgrammaticCollapse</td></tr>
+</thead><tbody>
+<tr>
+ <td>open</td>
+ <td>/run/com.vaadin.tests.components.treetable.ProgrammaticCollapse?restartApplication</td>
+ <td></td>
+</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></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>expanded</td>
+</tr>
+<tr>
+ <td>closeNotification</td>
+ <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]/VHorizontalLayout[0]/ChildComponentContainer[1]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>screenCapture</td>
+ <td></td>
+ <td>collapsed</td>
+</tr>
+<tr>
+ <td>closeNotification</td>
+ <td>//body/div[2]</td>
+ <td>0,0</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java
new file mode 100644
index 0000000000..f37e5c5888
--- /dev/null
+++ b/tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java
@@ -0,0 +1,44 @@
+package com.vaadin.tests.components.treetable;
+
+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;
+
+public class ProgrammaticCollapse extends TestBase {
+
+ @Override
+ protected void setup() {
+ HorizontalLayout layout = new HorizontalLayout();
+ final TreeTable table = new TreeTable();
+ 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);
+ layout.addComponent(table);
+ layout.addComponent(new Button("Expand / Collapse",
+ new ClickListener() {
+ public void buttonClick(ClickEvent event) {
+ boolean collapsed = !table.isCollapsed(1);
+ table.getWindow().showNotification(
+ "set collapsed: " + collapsed);
+ table.setCollapsed(1, collapsed);
+ }
+ }));
+ addComponent(layout);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Using setCollapsed(...) after the treetable has been rendered should update the UI";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 7988;
+ }
+
+}