From d4c6b5e503c7874f835fd3cc4407f0f86977a06e Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 21 Jul 2011 09:02:32 +0000 Subject: [PATCH] #7220 TreeTable support for Expand/Collapse events svn changeset:19861/svn branch:6.7 --- src/com/vaadin/ui/Tree.java | 4 +- src/com/vaadin/ui/TreeTable.java | 73 +++++++ .../treetable/ExpandAndCollapseListeners.html | 181 ++++++++++++++++++ .../{TreeTables.java => TreeTableTest.java} | 53 +++-- 4 files changed, 282 insertions(+), 29 deletions(-) create mode 100644 tests/src/com/vaadin/tests/components/treetable/ExpandAndCollapseListeners.html rename tests/src/com/vaadin/tests/components/treetable/{TreeTables.java => TreeTableTest.java} (85%) diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index e47d9c7909..3e6d62033e 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -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; diff --git a/src/com/vaadin/ui/TreeTable.java b/src/com/vaadin/ui/TreeTable.java index dfc2703eb7..987e3a9bfd 100644 --- a/src/com/vaadin/ui/TreeTable.java +++ b/src/com/vaadin/ui/TreeTable.java @@ -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 index 0000000000..81a62aaa50 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/treetable/ExpandAndCollapseListeners.html @@ -0,0 +1,181 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.treetable.TreeTableTest?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item023,12
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item323,7
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item775,11
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_Smenu#item04,7
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[0]/VMenuBar[0]#item379,9
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::Root/VOverlay[1]/VMenuBar[0]#item857,11
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]9,5
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[0]/domChild[0]/domChild[0]10,4
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[0]/domChild[0]/domChild[0]25,4
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_22. ExpandEvent: Item 1
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_13. ExpandEvent: Item 3
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_04. ExpandEvent: Item 9
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]30,7
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]30,7
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_15. ExpandEvent: Item 4
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_06. CollapseEvent: Item 4
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[1]/domChild[0]60,9
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[1]/domChild[0]64,15
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[8]/domChild[1]/domChild[0]51,14
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[1]/domChild[0]57,0
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[6]/domChild[1]/domChild[0]66,6
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[8]/domChild[1]/domChild[0]41,1
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[1]/domChild[0]63,0
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]63,9
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]60,11
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[4]/domChild[0]/domChild[0]58,10
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[5]/domChild[0]/domChild[0]66,12
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[0]/domChild[0]/domChild[0]/domChild[0]11,5
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_07. CollapseEvent: Item 1
mouseClickvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_StestComponent/domChild[1]/domChild[0]/domChild[1]/domChild[0]/domChild[2]/domChild[0]/domChild[0]/domChild[0]11,6
assertTextvaadin=runcomvaadintestscomponentstreetableTreeTableTest::PID_SLog_row_08. CollapseEvent: Item 3
+ + diff --git a/tests/src/com/vaadin/tests/components/treetable/TreeTables.java b/tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java similarity index 85% rename from tests/src/com/vaadin/tests/components/treetable/TreeTables.java rename to tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java index 523869e838..7c63f7ba4b 100644 --- a/tests/src/com/vaadin/tests/components/treetable/TreeTables.java +++ b/tests/src/com/vaadin/tests/components/treetable/TreeTableTest.java @@ -13,9 +13,11 @@ import com.vaadin.ui.Table.CellStyleGenerator; 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; -public class TreeTables extends Tables implements CollapseListener { +public class TreeTableTest extends Tables implements + CollapseListener, ExpandListener { @Override protected Class getTestClass() { @@ -91,7 +93,6 @@ public class TreeTables extends Tables implements CollapseListener { createRootItemSelectAction(CATEGORY_DATA_SOURCE); createExpandCollapseActions(CATEGORY_FEATURES); - createSelectionModeSelect(CATEGORY_SELECTION); createChildrenAllowedAction(CATEGORY_DATA_SOURCE); createListeners(CATEGORY_LISTENERS); @@ -109,12 +110,12 @@ public class TreeTables extends Tables implements CollapseListener { } private void createListeners(String category) { - // createBooleanAction("Expand listener", category, false, - // expandListenerCommand); - // createBooleanAction("Collapse listener", category, false, - // collapseListenerCommand); createBooleanAction("Item click listener", category, false, itemClickListenerCommand); + createBooleanAction("Expand listener", category, false, + expandListenerCommand); + createBooleanAction("Collapse listener", category, false, + collapseListenerCommand); } @@ -259,27 +260,25 @@ public class TreeTables extends Tables implements CollapseListener { } }; - // private Command expandListenerCommand = new - // Command() { - // public void execute(TreeTable c, Boolean value, Object data) { - // if (value) { - // c.addListener((ExpandListener) TreeTables.this); - // } else { - // c.removeListener((ExpandListener) TreeTables.this); - // } - // } - // }; - // - // private Command collapseListenerCommand = new - // Command() { - // public void execute(TreeTable c, Boolean value, Object data) { - // if (value) { - // c.addListener((CollapseListener) TreeTables.this); - // } else { - // c.removeListener((CollapseListener) TreeTables.this); - // } - // } - // }; + private Command expandListenerCommand = new Command() { + public void execute(TreeTable c, Boolean value, Object data) { + if (value) { + c.addListener((ExpandListener) TreeTableTest.this); + } else { + c.removeListener((ExpandListener) TreeTableTest.this); + } + } + }; + + private Command collapseListenerCommand = new Command() { + public void execute(TreeTable c, Boolean value, Object data) { + if (value) { + c.addListener((CollapseListener) TreeTableTest.this); + } else { + c.removeListener((CollapseListener) TreeTableTest.this); + } + } + }; public void nodeCollapse(CollapseEvent event) { log(event.getClass().getSimpleName() + ": " + event.getItemId()); -- 2.39.5