treeGrid.collapse(items); | 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 | * This method is a shorthand that delegates to the currently set selection | ||||
* model. | * model. | ||||
/** | /** | ||||
* Sets the height of a row. If -1 (default), the row height is calculated | * 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. | * based on the theme for an empty row before the Tree is displayed. | ||||
* | |||||
* | |||||
* @param rowHeight | * @param rowHeight | ||||
* The height of a row in pixels or -1 for automatic calculation | * The height of a row in pixels or -1 for automatic calculation | ||||
*/ | */ | ||||
/** | /** | ||||
* Sets the content mode of the item caption. | * Sets the content mode of the item caption. | ||||
* | |||||
* | |||||
* @param contentMode | * @param contentMode | ||||
* the content mode | * the content mode | ||||
*/ | */ |
import com.vaadin.ui.declarative.DesignAttributeHandler; | import com.vaadin.ui.declarative.DesignAttributeHandler; | ||||
import com.vaadin.ui.declarative.DesignContext; | import com.vaadin.ui.declarative.DesignContext; | ||||
import com.vaadin.ui.declarative.DesignFormatter; | 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. | * A grid component for displaying hierarchical tabular data. | ||||
}); | }); | ||||
} | } | ||||
/** | |||||
* 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 | @Override | ||||
protected TreeGridState getState() { | protected TreeGridState getState() { | ||||
return (TreeGridState) super.getState(); | return (TreeGridState) super.getState(); |
treeData.addItem(null, "Foo"); | treeData.addItem(null, "Foo"); | ||||
treeData.addItem("Foo", "Bar"); | treeData.addItem("Foo", "Bar"); | ||||
treeData.addItem("Foo", "Baz"); | treeData.addItem("Foo", "Baz"); | ||||
tree.setDataProvider( | |||||
new TreeDataProvider<>(treeData)); | |||||
tree.setDataProvider(new TreeDataProvider<>(treeData)); | |||||
TreeCollapseExpandListener listener = new TreeCollapseExpandListener( | TreeCollapseExpandListener listener = new TreeCollapseExpandListener( | ||||
tree); | tree); | ||||
Assert.assertFalse(listener.isExpanded()); | Assert.assertFalse(listener.isExpanded()); | ||||
tree.expand("Foo"); | tree.expand("Foo"); | ||||
Assert.assertTrue("Item not expanded", tree.isExpanded("Foo")); | |||||
Assert.assertTrue("Expand event not fired", listener.isExpanded()); | Assert.assertTrue("Expand event not fired", listener.isExpanded()); | ||||
Assert.assertFalse(listener.isCollapsed()); | Assert.assertFalse(listener.isCollapsed()); | ||||
tree.collapse("Foo"); | tree.collapse("Foo"); | ||||
Assert.assertFalse("Item not collapsed", tree.isExpanded("Foo")); | |||||
Assert.assertTrue("Collapse event not fired", listener.isCollapsed()); | Assert.assertTrue("Collapse event not fired", listener.isCollapsed()); | ||||
} | } | ||||
// Test expand event | // Test expand event | ||||
Assert.assertFalse(expandEventFired); | Assert.assertFalse(expandEventFired); | ||||
treeGrid.expand("Foo"); | treeGrid.expand("Foo"); | ||||
Assert.assertTrue("Item not expanded", treeGrid.isExpanded("Foo")); | |||||
Assert.assertTrue("Expand event not fired", expandEventFired); | Assert.assertTrue("Expand event not fired", expandEventFired); | ||||
// Test collapse event | // Test collapse event | ||||
Assert.assertFalse(collapseEventFired); | Assert.assertFalse(collapseEventFired); | ||||
treeGrid.collapse("Foo"); | treeGrid.collapse("Foo"); | ||||
Assert.assertFalse("Item not collapsed", treeGrid.isExpanded("Foo")); | |||||
Assert.assertTrue("Collapse event not fired", collapseEventFired); | Assert.assertTrue("Collapse event not fired", collapseEventFired); | ||||
} | } | ||||
} | } |