]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7220 TreeTable support for Expand/Collapse events
authorArtur Signell <artur.signell@itmill.com>
Thu, 21 Jul 2011 09:02:32 +0000 (09:02 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 21 Jul 2011 09:02:32 +0000 (09:02 +0000)
svn changeset:19861/svn branch:6.7

src/com/vaadin/ui/Tree.java
src/com/vaadin/ui/TreeTable.java
tests/src/com/vaadin/tests/components/treetable/ExpandAndCollapseListeners.html [new file with mode: 0644]
tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java [new file with mode: 0644]
tests/src/com/vaadin/tests/components/treetable/TreeTables.java [deleted file]

index e47d9c79090844142373f4d69cd603054b6b3c1f..3e6d62033edfce2102dd80e8a971523d8d8a371c 100644 (file)
@@ -826,7 +826,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * @VERSION@
      * @since 3.0
      */
-    public class ExpandEvent extends Component.Event {
+    public static class ExpandEvent extends Component.Event {
 
         private final Object expandedItemId;
 
@@ -915,7 +915,7 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
      * @VERSION@
      * @since 3.0
      */
-    public class CollapseEvent extends Component.Event {
+    public static class CollapseEvent extends Component.Event {
 
         private final Object collapsedItemId;
 
index dfc2703eb7bcb6fd51fc9e1a1352f46393b7efb1..987e3a9bfd13983056603ccbbc7500fbeaa1ac2e 100644 (file)
@@ -22,6 +22,10 @@ import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
 import com.vaadin.terminal.Resource;
 import com.vaadin.terminal.gwt.client.ui.VTreeTable;
+import com.vaadin.ui.Tree.CollapseEvent;
+import com.vaadin.ui.Tree.CollapseListener;
+import com.vaadin.ui.Tree.ExpandEvent;
+import com.vaadin.ui.Tree.ExpandListener;
 import com.vaadin.ui.treetable.Collapsible;
 import com.vaadin.ui.treetable.HierarchicalContainerOrderedWrapper;
 
@@ -479,6 +483,12 @@ public class TreeTable extends Table implements Hierarchical {
         setCurrentPageFirstItemIndex(getCurrentPageFirstItemIndex());
         toggledItemId = itemId;
         requestRepaint();
+
+        if (isCollapsed(itemId)) {
+            fireCollapseEvent(itemId);
+        } else {
+            fireExpandEvent(itemId);
+        }
     }
 
     @Override
@@ -631,4 +641,67 @@ public class TreeTable extends Table implements Hierarchical {
         return hierarchyColumnId;
     }
 
+    /**
+     * Adds an expand listener.
+     * 
+     * @param listener
+     *            the Listener to be added.
+     */
+    public void addListener(ExpandListener listener) {
+        addListener(ExpandEvent.class, listener, ExpandListener.EXPAND_METHOD);
+    }
+
+    /**
+     * Removes an expand listener.
+     * 
+     * @param listener
+     *            the Listener to be removed.
+     */
+    public void removeListener(ExpandListener listener) {
+        removeListener(ExpandEvent.class, listener,
+                ExpandListener.EXPAND_METHOD);
+    }
+
+    /**
+     * Emits an expand event.
+     * 
+     * @param itemId
+     *            the item id.
+     */
+    protected void fireExpandEvent(Object itemId) {
+        fireEvent(new ExpandEvent(this, itemId));
+    }
+
+    /**
+     * Adds a collapse listener.
+     * 
+     * @param listener
+     *            the Listener to be added.
+     */
+    public void addListener(CollapseListener listener) {
+        addListener(CollapseEvent.class, listener,
+                CollapseListener.COLLAPSE_METHOD);
+    }
+
+    /**
+     * Removes a collapse listener.
+     * 
+     * @param listener
+     *            the Listener to be removed.
+     */
+    public void removeListener(CollapseListener listener) {
+        removeListener(CollapseEvent.class, listener,
+                CollapseListener.COLLAPSE_METHOD);
+    }
+
+    /**
+     * Emits a collapse event.
+     * 
+     * @param itemId
+     *            the item id.
+     */
+    protected void fireCollapseEvent(Object itemId) {
+        fireEvent(new CollapseEvent(this, itemId));
+    }
+
 }
diff --git a/tests/src/com/vaadin/tests/components/treetable/ExpandAndCollapseListeners.html b/tests/src/com/vaadin/tests/components/treetable/ExpandAndCollapseListeners.html
new file mode 100644 (file)
index 0000000..81a62aa
--- /dev/null
@@ -0,0 +1,181 @@
+<?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>New Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">New Test</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.treetable.TreeTableTest?restartApplication</td>
+       <td></td>
+</tr>
+<!--expand and collapse listeners-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item0</td>
+       <td>23,12</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+       <td>23,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item7</td>
+       <td>75,11</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item0</td>
+       <td>4,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item3</td>
+       <td>79,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item8</td>
+       <td>57,11</td>
+</tr>
+<!--expand and assert events-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>9,5</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>10,4</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>25,4</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_2</td>
+       <td>2. ExpandEvent: Item 1</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_1</td>
+       <td>3. ExpandEvent: Item 3</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_0</td>
+       <td>4. ExpandEvent: Item 9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>30,7</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>30,7</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_1</td>
+       <td>5. ExpandEvent: Item 4</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_0</td>
+       <td>6. CollapseEvent: Item 4</td>
+</tr>
+<!--click around to see that we do not get extra expand/collapse events-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[1]/domChild[0]</td>
+       <td>60,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[0]</td>
+       <td>64,15</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[8]/domChild[1]/domChild[0]</td>
+       <td>51,14</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[1]/domChild[0]</td>
+       <td>57,0</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[1]/domChild[0]</td>
+       <td>66,6</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[8]/domChild[1]/domChild[0]</td>
+       <td>41,1</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[1]/domChild[0]</td>
+       <td>63,0</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]</td>
+       <td>63,9</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]</td>
+       <td>60,11</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[0]/domChild[0]</td>
+       <td>58,10</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[5]/domChild[0]/domChild[0]</td>
+       <td>66,12</td>
+</tr>
+<!--some collapse testing-->
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>11,5</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_0</td>
+       <td>7. CollapseEvent: Item 1</td>
+</tr>
+<tr>
+       <td>mouseClick</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]/domChild[0]</td>
+       <td>11,6</td>
+</tr>
+<tr>
+       <td>assertText</td>
+       <td>vaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_0</td>
+       <td>8. CollapseEvent: Item 3</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java b/tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java
new file mode 100644 (file)
index 0000000..7c63f7b
--- /dev/null
@@ -0,0 +1,290 @@
+package com.vaadin.tests.components.treetable;\r
+\r
+import java.util.ArrayList;\r
+import java.util.Iterator;\r
+import java.util.LinkedHashMap;\r
+import java.util.List;\r
+\r
+import com.vaadin.data.Container;\r
+import com.vaadin.data.Container.Hierarchical;\r
+import com.vaadin.data.util.HierarchicalContainer;\r
+import com.vaadin.tests.components.table.Tables;\r
+import com.vaadin.ui.Table.CellStyleGenerator;\r
+import com.vaadin.ui.Tree.CollapseEvent;\r
+import com.vaadin.ui.Tree.CollapseListener;\r
+import com.vaadin.ui.Tree.ExpandEvent;\r
+import com.vaadin.ui.Tree.ExpandListener;\r
+import com.vaadin.ui.TreeTable;\r
+\r
+public class TreeTableTest extends Tables<TreeTable> implements\r
+        CollapseListener, ExpandListener {\r
+\r
+    @Override\r
+    protected Class<TreeTable> getTestClass() {\r
+        return TreeTable.class;\r
+    }\r
+\r
+    private int rootItemIds = 3;\r
+    private CellStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Table.CellStyleGenerator() {\r
+\r
+        public String getStyle(Object itemId, Object propertyId) {\r
+            if (propertyId != null) {\r
+                return null;\r
+            }\r
+\r
+            Hierarchical c = getComponent().getContainerDataSource();\r
+            if (c.isRoot(itemId)) {\r
+                return "green";\r
+            }\r
+\r
+            Object parent = c.getParent(itemId);\r
+            if (!c.isRoot(parent)) {\r
+                return "red";\r
+            }\r
+\r
+            return null;\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return "Root green, second level red";\r
+        }\r
+\r
+    };\r
+\r
+    private CellStyleGenerator evenItemsBold = new CellStyleGenerator() {\r
+\r
+        public String getStyle(Object itemId, Object propertyId) {\r
+            if (propertyId != null) {\r
+                return null;\r
+            }\r
+\r
+            Hierarchical c = getComponent().getContainerDataSource();\r
+            int idx = 0;\r
+\r
+            for (Iterator<?> i = c.getItemIds().iterator(); i.hasNext();) {\r
+                Object id = i.next();\r
+                if (id == itemId) {\r
+                    if (idx % 2 == 1) {\r
+                        return "bold";\r
+                    } else {\r
+                        return null;\r
+                    }\r
+                }\r
+\r
+                idx++;\r
+            }\r
+\r
+            return null;\r
+        }\r
+\r
+        @Override\r
+        public String toString() {\r
+            return "Even items bold";\r
+        };\r
+\r
+    };\r
+\r
+    @Override\r
+    protected void createActions() {\r
+        super.createActions();\r
+\r
+        // Causes container changes so doing this first..\r
+        createRootItemSelectAction(CATEGORY_DATA_SOURCE);\r
+\r
+        createExpandCollapseActions(CATEGORY_FEATURES);\r
+        createChildrenAllowedAction(CATEGORY_DATA_SOURCE);\r
+\r
+        createListeners(CATEGORY_LISTENERS);\r
+        // createItemStyleGenerator(CATEGORY_FEATURES);\r
+\r
+        // TODO: DropHandler\r
+        // TODO: DragMode\r
+        // TODO: ActionHandler\r
+\r
+    }\r
+\r
+    @Override\r
+    protected Container createContainer(int properties, int items) {\r
+        return createHierarchicalContainer(properties, items, rootItemIds);\r
+    }\r
+\r
+    private void createListeners(String category) {\r
+        createBooleanAction("Item click listener", category, false,\r
+                itemClickListenerCommand);\r
+        createBooleanAction("Expand listener", category, false,\r
+                expandListenerCommand);\r
+        createBooleanAction("Collapse listener", category, false,\r
+                collapseListenerCommand);\r
+\r
+    }\r
+\r
+    private Container.Hierarchical createHierarchicalContainer(int properties,\r
+            int items, int roots) {\r
+        Container.Hierarchical c = new HierarchicalContainer();\r
+\r
+        populateContainer(c, properties, items);\r
+\r
+        if (items <= roots) {\r
+            return c;\r
+        }\r
+\r
+        // "roots" roots, each with\r
+        // "firstLevel" children, two with no children (one with childAllowed,\r
+        // one without)\r
+        // ("firstLevel"-2)*"secondLevel" children ("secondLevel"/2 with\r
+        // childAllowed, "secondLevel"/2 without)\r
+\r
+        // N*M+N*(M-2)*C = items\r
+        // items=N(M+MC-2C)\r
+\r
+        // Using secondLevel=firstLevel/2 =>\r
+        // items = roots*(firstLevel+firstLevel*firstLevel/2-2*firstLevel/2)\r
+        // =roots*(firstLevel+firstLevel^2/2-firstLevel)\r
+        // = roots*firstLevel^2/2\r
+        // => firstLevel = sqrt(items/roots*2)\r
+\r
+        int firstLevel = (int) Math.ceil(Math.sqrt(items / roots * 2.0));\r
+        int secondLevel = firstLevel / 2;\r
+\r
+        while (roots * (1 + 2 + (firstLevel - 2) * secondLevel) < items) {\r
+            // Increase something so we get enough items\r
+            secondLevel++;\r
+        }\r
+\r
+        List<Object> itemIds = new ArrayList<Object>(c.getItemIds());\r
+\r
+        int nextItemId = roots;\r
+        for (int rootIndex = 0; rootIndex < roots; rootIndex++) {\r
+            // roots use items 0..roots-1\r
+            Object rootItemId = itemIds.get(rootIndex);\r
+\r
+            // force roots to be roots even though they automatically should be\r
+            c.setParent(rootItemId, null);\r
+\r
+            for (int firstLevelIndex = 0; firstLevelIndex < firstLevel; firstLevelIndex++) {\r
+                if (nextItemId >= items) {\r
+                    break;\r
+                }\r
+                Object firstLevelItemId = itemIds.get(nextItemId++);\r
+                c.setParent(firstLevelItemId, rootItemId);\r
+\r
+                if (firstLevelIndex < 2) {\r
+                    continue;\r
+                }\r
+\r
+                // firstLevelChildren 2.. have child nodes\r
+                for (int secondLevelIndex = 0; secondLevelIndex < secondLevel; secondLevelIndex++) {\r
+                    if (nextItemId >= items) {\r
+                        break;\r
+                    }\r
+\r
+                    Object secondLevelItemId = itemIds.get(nextItemId++);\r
+                    c.setParent(secondLevelItemId, firstLevelItemId);\r
+                }\r
+            }\r
+        }\r
+\r
+        return c;\r
+    }\r
+\r
+    private void createRootItemSelectAction(String category) {\r
+        LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();\r
+        for (int i = 1; i <= 10; i++) {\r
+            options.put(String.valueOf(i), i);\r
+        }\r
+        options.put("20", 20);\r
+        options.put("50", 50);\r
+        options.put("100", 100);\r
+\r
+        createSelectAction("Number of root items", category, options, "3",\r
+                rootItemIdsCommand);\r
+    }\r
+\r
+    private void createExpandCollapseActions(String category) {\r
+        LinkedHashMap<String, Object> options = new LinkedHashMap<String, Object>();\r
+\r
+        for (Object id : getComponent().getItemIds()) {\r
+            options.put(id.toString(), id);\r
+        }\r
+        createMultiClickAction("Expand", category, options, expandItemCommand,\r
+                null);\r
+        // createMultiClickAction("Expand recursively", category, options,\r
+        // expandItemRecursivelyCommand, null);\r
+        createMultiClickAction("Collapse", category, options,\r
+                collapseItemCommand, null);\r
+\r
+    }\r
+\r
+    private void createChildrenAllowedAction(String category) {\r
+        LinkedHashMap<String, Object> options = new LinkedHashMap<String, Object>();\r
+\r
+        for (Object id : getComponent().getItemIds()) {\r
+            options.put(id.toString(), id);\r
+        }\r
+        createMultiToggleAction("Children allowed", category, options,\r
+                setChildrenAllowedCommand, true);\r
+\r
+    }\r
+\r
+    /*\r
+     * COMMANDS\r
+     */\r
+    private Command<TreeTable, Integer> rootItemIdsCommand = new Command<TreeTable, Integer>() {\r
+\r
+        public void execute(TreeTable c, Integer value, Object data) {\r
+            rootItemIds = value;\r
+            updateContainer();\r
+        }\r
+    };\r
+\r
+    private Command<TreeTable, Object> expandItemCommand = new Command<TreeTable, Object>() {\r
+\r
+        public void execute(TreeTable c, Object itemId, Object data) {\r
+            c.setCollapsed(itemId, false);\r
+        }\r
+    };\r
+\r
+    private Command<TreeTable, Object> collapseItemCommand = new Command<TreeTable, Object>() {\r
+\r
+        public void execute(TreeTable c, Object itemId, Object data) {\r
+            c.setCollapsed(itemId, true);\r
+        }\r
+    };\r
+\r
+    private Command<TreeTable, Boolean> setChildrenAllowedCommand = new Command<TreeTable, Boolean>() {\r
+\r
+        public void execute(TreeTable c, Boolean areChildrenAllowed,\r
+                Object itemId) {\r
+            c.setChildrenAllowed(itemId, areChildrenAllowed);\r
+        }\r
+    };\r
+\r
+    private Command<TreeTable, Boolean> expandListenerCommand = new Command<TreeTable, Boolean>() {\r
+        public void execute(TreeTable c, Boolean value, Object data) {\r
+            if (value) {\r
+                c.addListener((ExpandListener) TreeTableTest.this);\r
+            } else {\r
+                c.removeListener((ExpandListener) TreeTableTest.this);\r
+            }\r
+        }\r
+    };\r
+\r
+    private Command<TreeTable, Boolean> collapseListenerCommand = new Command<TreeTable, Boolean>() {\r
+        public void execute(TreeTable c, Boolean value, Object data) {\r
+            if (value) {\r
+                c.addListener((CollapseListener) TreeTableTest.this);\r
+            } else {\r
+                c.removeListener((CollapseListener) TreeTableTest.this);\r
+            }\r
+        }\r
+    };\r
+\r
+    public void nodeCollapse(CollapseEvent event) {\r
+        log(event.getClass().getSimpleName() + ": " + event.getItemId());\r
+    }\r
+\r
+    public void nodeExpand(ExpandEvent event) {\r
+        log(event.getClass().getSimpleName() + ": " + event.getItemId());\r
+    }\r
+}\r
diff --git a/tests/src/com/vaadin/tests/components/treetable/TreeTables.java b/tests/src/com/vaadin/tests/components/treetable/TreeTables.java
deleted file mode 100644 (file)
index 523869e..0000000
+++ /dev/null
@@ -1,291 +0,0 @@
-package com.vaadin.tests.components.treetable;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.LinkedHashMap;\r
-import java.util.List;\r
-\r
-import com.vaadin.data.Container;\r
-import com.vaadin.data.Container.Hierarchical;\r
-import com.vaadin.data.util.HierarchicalContainer;\r
-import com.vaadin.tests.components.table.Tables;\r
-import com.vaadin.ui.Table.CellStyleGenerator;\r
-import com.vaadin.ui.Tree.CollapseEvent;\r
-import com.vaadin.ui.Tree.CollapseListener;\r
-import com.vaadin.ui.Tree.ExpandEvent;\r
-import com.vaadin.ui.TreeTable;\r
-\r
-public class TreeTables extends Tables<TreeTable> implements CollapseListener {\r
-\r
-    @Override\r
-    protected Class<TreeTable> getTestClass() {\r
-        return TreeTable.class;\r
-    }\r
-\r
-    private int rootItemIds = 3;\r
-    private CellStyleGenerator rootGreenSecondLevelRed = new com.vaadin.ui.Table.CellStyleGenerator() {\r
-\r
-        public String getStyle(Object itemId, Object propertyId) {\r
-            if (propertyId != null) {\r
-                return null;\r
-            }\r
-\r
-            Hierarchical c = getComponent().getContainerDataSource();\r
-            if (c.isRoot(itemId)) {\r
-                return "green";\r
-            }\r
-\r
-            Object parent = c.getParent(itemId);\r
-            if (!c.isRoot(parent)) {\r
-                return "red";\r
-            }\r
-\r
-            return null;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            return "Root green, second level red";\r
-        }\r
-\r
-    };\r
-\r
-    private CellStyleGenerator evenItemsBold = new CellStyleGenerator() {\r
-\r
-        public String getStyle(Object itemId, Object propertyId) {\r
-            if (propertyId != null) {\r
-                return null;\r
-            }\r
-\r
-            Hierarchical c = getComponent().getContainerDataSource();\r
-            int idx = 0;\r
-\r
-            for (Iterator<?> i = c.getItemIds().iterator(); i.hasNext();) {\r
-                Object id = i.next();\r
-                if (id == itemId) {\r
-                    if (idx % 2 == 1) {\r
-                        return "bold";\r
-                    } else {\r
-                        return null;\r
-                    }\r
-                }\r
-\r
-                idx++;\r
-            }\r
-\r
-            return null;\r
-        }\r
-\r
-        @Override\r
-        public String toString() {\r
-            return "Even items bold";\r
-        };\r
-\r
-    };\r
-\r
-    @Override\r
-    protected void createActions() {\r
-        super.createActions();\r
-\r
-        // Causes container changes so doing this first..\r
-        createRootItemSelectAction(CATEGORY_DATA_SOURCE);\r
-\r
-        createExpandCollapseActions(CATEGORY_FEATURES);\r
-        createSelectionModeSelect(CATEGORY_SELECTION);\r
-        createChildrenAllowedAction(CATEGORY_DATA_SOURCE);\r
-\r
-        createListeners(CATEGORY_LISTENERS);\r
-        // createItemStyleGenerator(CATEGORY_FEATURES);\r
-\r
-        // TODO: DropHandler\r
-        // TODO: DragMode\r
-        // TODO: ActionHandler\r
-\r
-    }\r
-\r
-    @Override\r
-    protected Container createContainer(int properties, int items) {\r
-        return createHierarchicalContainer(properties, items, rootItemIds);\r
-    }\r
-\r
-    private void createListeners(String category) {\r
-        // createBooleanAction("Expand listener", category, false,\r
-        // expandListenerCommand);\r
-        // createBooleanAction("Collapse listener", category, false,\r
-        // collapseListenerCommand);\r
-        createBooleanAction("Item click listener", category, false,\r
-                itemClickListenerCommand);\r
-\r
-    }\r
-\r
-    private Container.Hierarchical createHierarchicalContainer(int properties,\r
-            int items, int roots) {\r
-        Container.Hierarchical c = new HierarchicalContainer();\r
-\r
-        populateContainer(c, properties, items);\r
-\r
-        if (items <= roots) {\r
-            return c;\r
-        }\r
-\r
-        // "roots" roots, each with\r
-        // "firstLevel" children, two with no children (one with childAllowed,\r
-        // one without)\r
-        // ("firstLevel"-2)*"secondLevel" children ("secondLevel"/2 with\r
-        // childAllowed, "secondLevel"/2 without)\r
-\r
-        // N*M+N*(M-2)*C = items\r
-        // items=N(M+MC-2C)\r
-\r
-        // Using secondLevel=firstLevel/2 =>\r
-        // items = roots*(firstLevel+firstLevel*firstLevel/2-2*firstLevel/2)\r
-        // =roots*(firstLevel+firstLevel^2/2-firstLevel)\r
-        // = roots*firstLevel^2/2\r
-        // => firstLevel = sqrt(items/roots*2)\r
-\r
-        int firstLevel = (int) Math.ceil(Math.sqrt(items / roots * 2.0));\r
-        int secondLevel = firstLevel / 2;\r
-\r
-        while (roots * (1 + 2 + (firstLevel - 2) * secondLevel) < items) {\r
-            // Increase something so we get enough items\r
-            secondLevel++;\r
-        }\r
-\r
-        List<Object> itemIds = new ArrayList<Object>(c.getItemIds());\r
-\r
-        int nextItemId = roots;\r
-        for (int rootIndex = 0; rootIndex < roots; rootIndex++) {\r
-            // roots use items 0..roots-1\r
-            Object rootItemId = itemIds.get(rootIndex);\r
-\r
-            // force roots to be roots even though they automatically should be\r
-            c.setParent(rootItemId, null);\r
-\r
-            for (int firstLevelIndex = 0; firstLevelIndex < firstLevel; firstLevelIndex++) {\r
-                if (nextItemId >= items) {\r
-                    break;\r
-                }\r
-                Object firstLevelItemId = itemIds.get(nextItemId++);\r
-                c.setParent(firstLevelItemId, rootItemId);\r
-\r
-                if (firstLevelIndex < 2) {\r
-                    continue;\r
-                }\r
-\r
-                // firstLevelChildren 2.. have child nodes\r
-                for (int secondLevelIndex = 0; secondLevelIndex < secondLevel; secondLevelIndex++) {\r
-                    if (nextItemId >= items) {\r
-                        break;\r
-                    }\r
-\r
-                    Object secondLevelItemId = itemIds.get(nextItemId++);\r
-                    c.setParent(secondLevelItemId, firstLevelItemId);\r
-                }\r
-            }\r
-        }\r
-\r
-        return c;\r
-    }\r
-\r
-    private void createRootItemSelectAction(String category) {\r
-        LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();\r
-        for (int i = 1; i <= 10; i++) {\r
-            options.put(String.valueOf(i), i);\r
-        }\r
-        options.put("20", 20);\r
-        options.put("50", 50);\r
-        options.put("100", 100);\r
-\r
-        createSelectAction("Number of root items", category, options, "3",\r
-                rootItemIdsCommand);\r
-    }\r
-\r
-    private void createExpandCollapseActions(String category) {\r
-        LinkedHashMap<String, Object> options = new LinkedHashMap<String, Object>();\r
-\r
-        for (Object id : getComponent().getItemIds()) {\r
-            options.put(id.toString(), id);\r
-        }\r
-        createMultiClickAction("Expand", category, options, expandItemCommand,\r
-                null);\r
-        // createMultiClickAction("Expand recursively", category, options,\r
-        // expandItemRecursivelyCommand, null);\r
-        createMultiClickAction("Collapse", category, options,\r
-                collapseItemCommand, null);\r
-\r
-    }\r
-\r
-    private void createChildrenAllowedAction(String category) {\r
-        LinkedHashMap<String, Object> options = new LinkedHashMap<String, Object>();\r
-\r
-        for (Object id : getComponent().getItemIds()) {\r
-            options.put(id.toString(), id);\r
-        }\r
-        createMultiToggleAction("Children allowed", category, options,\r
-                setChildrenAllowedCommand, true);\r
-\r
-    }\r
-\r
-    /*\r
-     * COMMANDS\r
-     */\r
-    private Command<TreeTable, Integer> rootItemIdsCommand = new Command<TreeTable, Integer>() {\r
-\r
-        public void execute(TreeTable c, Integer value, Object data) {\r
-            rootItemIds = value;\r
-            updateContainer();\r
-        }\r
-    };\r
-\r
-    private Command<TreeTable, Object> expandItemCommand = new Command<TreeTable, Object>() {\r
-\r
-        public void execute(TreeTable c, Object itemId, Object data) {\r
-            c.setCollapsed(itemId, false);\r
-        }\r
-    };\r
-\r
-    private Command<TreeTable, Object> collapseItemCommand = new Command<TreeTable, Object>() {\r
-\r
-        public void execute(TreeTable c, Object itemId, Object data) {\r
-            c.setCollapsed(itemId, true);\r
-        }\r
-    };\r
-\r
-    private Command<TreeTable, Boolean> setChildrenAllowedCommand = new Command<TreeTable, Boolean>() {\r
-\r
-        public void execute(TreeTable c, Boolean areChildrenAllowed,\r
-                Object itemId) {\r
-            c.setChildrenAllowed(itemId, areChildrenAllowed);\r
-        }\r
-    };\r
-\r
-    // private Command<TreeTable, Boolean> expandListenerCommand = new\r
-    // Command<TreeTable, Boolean>() {\r
-    // public void execute(TreeTable c, Boolean value, Object data) {\r
-    // if (value) {\r
-    // c.addListener((ExpandListener) TreeTables.this);\r
-    // } else {\r
-    // c.removeListener((ExpandListener) TreeTables.this);\r
-    // }\r
-    // }\r
-    // };\r
-    //\r
-    // private Command<TreeTable, Boolean> collapseListenerCommand = new\r
-    // Command<TreeTable, Boolean>() {\r
-    // public void execute(TreeTable c, Boolean value, Object data) {\r
-    // if (value) {\r
-    // c.addListener((CollapseListener) TreeTables.this);\r
-    // } else {\r
-    // c.removeListener((CollapseListener) TreeTables.this);\r
-    // }\r
-    // }\r
-    // };\r
-\r
-    public void nodeCollapse(CollapseEvent event) {\r
-        log(event.getClass().getSimpleName() + ": " + event.getItemId());\r
-    }\r
-\r
-    public void nodeExpand(ExpandEvent event) {\r
-        log(event.getClass().getSimpleName() + ": " + event.getItemId());\r
-    }\r
-}\r