@@ -412,6 +412,17 @@ public class Tree<T> extends Composite | |||
treeGrid.collapse(items); | |||
} | |||
/** | |||
* Returns whether a given item is expanded or collapsed. | |||
* | |||
* @param item | |||
* the item to check | |||
* @return true if the item is expanded, false if collapsed | |||
*/ | |||
public boolean isExpanded(T item) { | |||
return treeGrid.isExpanded(item); | |||
} | |||
/** | |||
* This method is a shorthand that delegates to the currently set selection | |||
* model. | |||
@@ -767,7 +778,7 @@ public class Tree<T> extends Composite | |||
/** | |||
* Sets the height of a row. If -1 (default), the row height is calculated | |||
* based on the theme for an empty row before the Tree is displayed. | |||
* | |||
* | |||
* @param rowHeight | |||
* The height of a row in pixels or -1 for automatic calculation | |||
*/ | |||
@@ -777,7 +788,7 @@ public class Tree<T> extends Composite | |||
/** | |||
* Sets the content mode of the item caption. | |||
* | |||
* | |||
* @param contentMode | |||
* the content mode | |||
*/ |
@@ -52,8 +52,6 @@ import com.vaadin.shared.ui.treegrid.TreeGridState; | |||
import com.vaadin.ui.declarative.DesignAttributeHandler; | |||
import com.vaadin.ui.declarative.DesignContext; | |||
import com.vaadin.ui.declarative.DesignFormatter; | |||
import com.vaadin.ui.renderers.AbstractRenderer; | |||
import com.vaadin.ui.renderers.Renderer; | |||
/** | |||
* A grid component for displaying hierarchical tabular data. | |||
@@ -383,6 +381,17 @@ public class TreeGrid<T> extends Grid<T> | |||
}); | |||
} | |||
/** | |||
* Returns whether a given item is expanded or collapsed. | |||
* | |||
* @param item | |||
* the item to check | |||
* @return true if the item is expanded, false if collapsed | |||
*/ | |||
public boolean isExpanded(T item) { | |||
return getDataCommunicator().isExpanded(item); | |||
} | |||
@Override | |||
protected TreeGridState getState() { | |||
return (TreeGridState) super.getState(); |
@@ -56,8 +56,7 @@ public class TreeTest { | |||
treeData.addItem(null, "Foo"); | |||
treeData.addItem("Foo", "Bar"); | |||
treeData.addItem("Foo", "Baz"); | |||
tree.setDataProvider( | |||
new TreeDataProvider<>(treeData)); | |||
tree.setDataProvider(new TreeDataProvider<>(treeData)); | |||
TreeCollapseExpandListener listener = new TreeCollapseExpandListener( | |||
tree); | |||
@@ -66,9 +65,11 @@ public class TreeTest { | |||
Assert.assertFalse(listener.isExpanded()); | |||
tree.expand("Foo"); | |||
Assert.assertTrue("Item not expanded", tree.isExpanded("Foo")); | |||
Assert.assertTrue("Expand event not fired", listener.isExpanded()); | |||
Assert.assertFalse(listener.isCollapsed()); | |||
tree.collapse("Foo"); | |||
Assert.assertFalse("Item not collapsed", tree.isExpanded("Foo")); | |||
Assert.assertTrue("Collapse event not fired", listener.isCollapsed()); | |||
} | |||
@@ -35,11 +35,13 @@ public class TreeGridTest { | |||
// Test expand event | |||
Assert.assertFalse(expandEventFired); | |||
treeGrid.expand("Foo"); | |||
Assert.assertTrue("Item not expanded", treeGrid.isExpanded("Foo")); | |||
Assert.assertTrue("Expand event not fired", expandEventFired); | |||
// Test collapse event | |||
Assert.assertFalse(collapseEventFired); | |||
treeGrid.collapse("Foo"); | |||
Assert.assertFalse("Item not collapsed", treeGrid.isExpanded("Foo")); | |||
Assert.assertTrue("Collapse event not fired", collapseEventFired); | |||
} | |||
} |