]> source.dussan.org Git - vaadin-framework.git/commitdiff
Merge changes from 6.7 to 6.8
authorHenri Sara <henri.sara@itmill.com>
Tue, 29 Nov 2011 12:57:06 +0000 (12:57 +0000)
committerHenri Sara <henri.sara@itmill.com>
Tue, 29 Nov 2011 12:57:06 +0000 (12:57 +0000)
svn changeset:22173/svn branch:6.8

build/build.xml
src/com/vaadin/ui/Table.java
src/com/vaadin/ui/TreeTable.java
tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.html [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/treetable/ProgrammaticCollapse.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/components/treetable/TreeTableModifyAndSetCollapsed.java [new file with mode: 0644]

index a94fa143ac7d024a133dc3ec613af9ad0859e76b..e7f25afde3d62b7155daaa09bcefe979fa414cf2 100644 (file)
@@ -6,7 +6,7 @@
          basedir="../" default="package-all">
 
     <!--Call one of package-* targets unless you understand what you are doing. -->
-    <target name="package-all" depends="clean-all, init, build, javadoc, internal-package-war, internal-package-liferay, differences, internal-package-liferay" description="Build public packages.">
+    <target name="package-all" depends="clean-all, init, build, javadoc, internal-package-war, internal-package-liferay, differences" description="Build public packages.">
     </target>
 
     <target name="package-jar" depends="clean-result, init, vaadin.jar" description="Create vaadin-x.y.z.jar file.">
index b95d7381572cb07fcd011e4642ab8c23ff83181e..cd07465d076fbd948653f3bd5549ce9c7a825566 100644 (file)
@@ -2712,7 +2712,7 @@ public class Table extends AbstractSelect implements Action.Container,
         rowCacheInvalidated = invalidated;
     }
 
-    private boolean isRowCacheInvalidated() {
+    protected boolean isRowCacheInvalidated() {
         return rowCacheInvalidated;
     }
 
@@ -3816,8 +3816,12 @@ public class Table extends AbstractSelect implements Action.Container,
         final LinkedList<Object> visible = new LinkedList<Object>();
 
         final Object[][] cells = getVisibleCells();
-        for (int i = 0; i < cells[CELL_ITEMID].length; i++) {
-            visible.add(cells[CELL_ITEMID][i]);
+        // may be null if the table has not been rendered yet (e.g. not attached
+        // to a layout)
+        if (null != cells) {
+            for (int i = 0; i < cells[CELL_ITEMID].length; i++) {
+                visible.add(cells[CELL_ITEMID][i]);
+            }
         }
 
         return visible;
index fb12ffe323630937f0557881a3fc473714e7038e..171ee616e1be6bfbe6e3f21fbf330c43b86d7c87 100644 (file)
@@ -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,18 @@ public class TreeTable extends Table implements Hierarchical {
      */
     public void setCollapsed(Object itemId, boolean collapsed) {
         if (isCollapsed(itemId) != collapsed) {
-            toggleChildVisibility(itemId);
+            if (null == toggledItemId && !isRowCacheInvalidated()
+                    && getVisibleItemIds().contains(itemId)) {
+                // 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 (file)
index 0000000..44dd858
--- /dev/null
@@ -0,0 +1,112 @@
+<?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]/VVerticalLayout[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]/VVerticalLayout[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>
+<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>
+</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 (file)
index 0000000..6f2e507
--- /dev/null
@@ -0,0 +1,74 @@
+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.TreeTable;
+import com.vaadin.ui.VerticalLayout;
+
+public class ProgrammaticCollapse extends TestBase {
+
+    @Override
+    protected void setup() {
+        VerticalLayout layout = new VerticalLayout();
+        final TreeTable table = new TreeTable();
+        table.setPageLength(10);
+        table.addContainerProperty("A", String.class, null);
+        table.addContainerProperty("B", String.class, null);
+        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() {
+                    public void buttonClick(ClickEvent event) {
+                        boolean collapsed = !table.isCollapsed(1);
+                        table.getWindow().showNotification(
+                                "set collapsed: " + collapsed);
+                        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);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Using setCollapsed(...) after the treetable has been rendered should update the UI";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 7988;
+    }
+
+}
diff --git a/tests/testbench/com/vaadin/tests/components/treetable/TreeTableModifyAndSetCollapsed.java b/tests/testbench/com/vaadin/tests/components/treetable/TreeTableModifyAndSetCollapsed.java
new file mode 100644 (file)
index 0000000..336ffb5
--- /dev/null
@@ -0,0 +1,57 @@
+package com.vaadin.tests.components.treetable;
+
+import com.vaadin.data.Item;
+import com.vaadin.data.util.HierarchicalContainer;
+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.TreeTable;
+
+public class TreeTableModifyAndSetCollapsed extends TestBase {
+
+    int counter = 1;
+
+    @Override
+    protected void setup() {
+        final HierarchicalContainer container = new HierarchicalContainer();
+        container.addContainerProperty("value", String.class, "");
+
+        final TreeTable tt = new TreeTable(null, container);
+        tt.setSizeFull();
+        int parentId = counter++;
+        Item parent = container.addItem(parentId);
+        tt.setCollapsed(parentId, false);
+        parent.getItemProperty("value").setValue("parent " + (counter++) + "");
+        addComponent(tt);
+        Button repopulate = new Button("Repopulate", new ClickListener() {
+
+            public void buttonClick(ClickEvent event) {
+                // repopulate the container and expand root item
+                container.removeAllItems();
+                int parentId = counter++;
+                Item parent = container.addItem(parentId);
+                tt.setCollapsed(parentId, false);
+                parent.getItemProperty("value").setValue(
+                        "parent " + (counter++) + "");
+                for (int i = 0; i < 4; i++) {
+                    int childId = counter++;
+                    Item child = container.addItem(childId);
+                    child.getItemProperty("value").setValue(childId + "");
+                    container.setParent(childId, parentId);
+                }
+            }
+        });
+        addComponent(repopulate);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Modifying a container and using setCollapsed on the same server round-trip should not cause any problems";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return Integer.valueOf(7785);
+    }
+}