]> source.dussan.org Git - vaadin-framework.git/commitdiff
Use HierarchicalContainer as default container for Tree (#3950)
authorHenri Sara <hesara@vaadin.com>
Mon, 3 Sep 2012 12:23:15 +0000 (15:23 +0300)
committerHenri Sara <hesara@vaadin.com>
Mon, 3 Sep 2012 12:23:47 +0000 (15:23 +0300)
server/src/com/vaadin/ui/Tree.java
server/tests/src/com/vaadin/tests/server/component/tree/TestHasChildren.java [deleted file]
server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java [new file with mode: 0644]

index 9cf1aa3511cde63548ea6693ce87529636986edb..03895a12bb9b2dc8570b16668e742ce8f51b2614 100644 (file)
@@ -33,7 +33,7 @@ import java.util.StringTokenizer;
 import com.vaadin.data.Container;
 import com.vaadin.data.Item;
 import com.vaadin.data.util.ContainerHierarchicalWrapper;
-import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.data.util.HierarchicalContainer;
 import com.vaadin.event.Action;
 import com.vaadin.event.Action.Handler;
 import com.vaadin.event.DataBoundTransferable;
@@ -140,6 +140,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * Creates a new empty tree.
      */
     public Tree() {
+        this(null);
     }
 
     /**
@@ -148,7 +149,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * @param caption
      */
     public Tree(String caption) {
-        setCaption(caption);
+        this(caption, new HierarchicalContainer());
     }
 
     /**
@@ -158,8 +159,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * @param dataSource
      */
     public Tree(String caption, Container dataSource) {
-        setCaption(caption);
-        setContainerDataSource(dataSource);
+        super(caption, dataSource);
     }
 
     /* Expanding and collapsing */
@@ -827,10 +827,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
     @Override
     public void setContainerDataSource(Container newDataSource) {
         if (newDataSource == null) {
-            // Note: using wrapped IndexedContainer to match constructor (super
-            // creates an IndexedContainer, which is then wrapped).
-            newDataSource = new ContainerHierarchicalWrapper(
-                    new IndexedContainer());
+            newDataSource = new HierarchicalContainer();
         }
 
         // Assure that the data source is ordered by making unordered
diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TestHasChildren.java b/server/tests/src/com/vaadin/tests/server/component/tree/TestHasChildren.java
deleted file mode 100644 (file)
index 66535d3..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.vaadin.tests.server.component.tree;
-
-import junit.framework.TestCase;
-
-import com.vaadin.ui.Tree;
-
-public class TestHasChildren extends TestCase {
-
-    private Tree tree;
-
-    @Override
-    protected void setUp() {
-        tree = new Tree();
-        tree.addItem("parent");
-        tree.addItem("child");
-        tree.setChildrenAllowed("parent", true);
-        tree.setParent("child", "parent");
-    }
-
-    public void testRemoveChildren() {
-        assertTrue(tree.hasChildren("parent"));
-        tree.removeItem("child");
-        assertFalse(tree.hasChildren("parent"));
-    }
-}
diff --git a/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java b/server/tests/src/com/vaadin/tests/server/component/tree/TreeTest.java
new file mode 100644 (file)
index 0000000..16a7091
--- /dev/null
@@ -0,0 +1,74 @@
+package com.vaadin.tests.server.component.tree;
+
+import junit.framework.TestCase;
+
+import com.vaadin.data.Container;
+import com.vaadin.data.util.HierarchicalContainer;
+import com.vaadin.data.util.IndexedContainer;
+import com.vaadin.ui.Tree;
+
+public class TreeTest extends TestCase {
+
+    private Tree tree;
+    private Tree tree2;
+    private Tree tree3;
+    private Tree tree4;
+
+    @Override
+    protected void setUp() {
+        tree = new Tree();
+        tree.addItem("parent");
+        tree.addItem("child");
+        tree.setChildrenAllowed("parent", true);
+        tree.setParent("child", "parent");
+
+        tree2 = new Tree("Caption");
+        tree2.addItem("parent");
+        tree2.addItem("child");
+        tree2.setChildrenAllowed("parent", true);
+        tree2.setParent("child", "parent");
+
+        tree3 = new Tree("Caption", null);
+        tree3.addItem("parent");
+        tree3.addItem("child");
+        tree3.setChildrenAllowed("parent", true);
+        tree3.setParent("child", "parent");
+
+        tree4 = new Tree("Caption", new IndexedContainer());
+        tree4.addItem("parent");
+        tree4.addItem("child");
+        tree4.setChildrenAllowed("parent", true);
+        tree4.setParent("child", "parent");
+    }
+
+    public void testRemoveChildren() {
+        assertTrue(tree.hasChildren("parent"));
+        tree.removeItem("child");
+        assertFalse(tree.hasChildren("parent"));
+
+        assertTrue(tree2.hasChildren("parent"));
+        tree2.removeItem("child");
+        assertFalse(tree2.hasChildren("parent"));
+
+        assertTrue(tree3.hasChildren("parent"));
+        tree3.removeItem("child");
+        assertFalse(tree3.hasChildren("parent"));
+
+        assertTrue(tree4.hasChildren("parent"));
+        tree4.removeItem("child");
+        assertFalse(tree4.hasChildren("parent"));
+    }
+
+    public void testContainerTypeIsHierarchical() {
+        assertTrue(HierarchicalContainer.class.isAssignableFrom(tree
+                .getContainerDataSource().getClass()));
+        assertTrue(HierarchicalContainer.class.isAssignableFrom(tree2
+                .getContainerDataSource().getClass()));
+        assertTrue(HierarchicalContainer.class.isAssignableFrom(tree3
+                .getContainerDataSource().getClass()));
+        assertFalse(HierarchicalContainer.class.isAssignableFrom(tree4
+                .getContainerDataSource().getClass()));
+        assertTrue(Container.Hierarchical.class.isAssignableFrom(tree4
+                .getContainerDataSource().getClass()));
+    }
+}