From 6b3482da66bb6781128fd2d34adec3655617fb6c Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Wed, 17 May 2017 11:08:35 +0300 Subject: Add convenience constructors for Tree component --- server/src/main/java/com/vaadin/ui/Tree.java | 52 +++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/com/vaadin/ui/Tree.java b/server/src/main/java/com/vaadin/ui/Tree.java index 6ecbaac597..85a9e3a615 100644 --- a/server/src/main/java/com/vaadin/ui/Tree.java +++ b/server/src/main/java/com/vaadin/ui/Tree.java @@ -26,9 +26,11 @@ import java.util.Set; import com.vaadin.data.Binder; import com.vaadin.data.HasHierarchicalDataProvider; import com.vaadin.data.SelectionModel; +import com.vaadin.data.TreeData; import com.vaadin.data.provider.DataGenerator; import com.vaadin.data.provider.DataProvider; import com.vaadin.data.provider.HierarchicalDataProvider; +import com.vaadin.data.provider.TreeDataProvider; import com.vaadin.event.CollapseEvent; import com.vaadin.event.CollapseEvent.CollapseListener; import com.vaadin.event.ConnectorEvent; @@ -220,7 +222,7 @@ public class Tree extends Composite } /** - * Constructs a new Tree Component. + * Constructs a new Tree Component with given caption. * * @param caption * the caption for component @@ -231,6 +233,54 @@ public class Tree extends Composite setCaption(caption); } + /** + * Constructs a new Tree Component with given caption and {@code TreeData}. + * + * @param caption + * the caption for component + * @param treeData + * the tree data for component + */ + public Tree(String caption, TreeData treeData) { + this(caption, new TreeDataProvider<>(treeData)); + } + + /** + * Constructs a new Tree Component with given caption and + * {@code HierarchicalDataProvider}. + * + * @param caption + * the caption for component + * @param dataProvider + * the hierarchical data provider for component + */ + public Tree(String caption, HierarchicalDataProvider dataProvider) { + this(caption); + + treeGrid.setDataProvider(dataProvider); + } + + /** + * Constructs a new Tree Component with given {@code TreeData}. + * + * @param treeData + * the tree data for component + */ + public Tree(TreeData treeData) { + this(null, new TreeDataProvider<>(treeData)); + } + + /** + * Constructs a new Tree Component with given + * {@code HierarchicalDataProvider}. + * + * @param dataProvider + * the hierarchical data provider for component + */ + public Tree(HierarchicalDataProvider dataProvider) { + this(null, dataProvider); + } + @Override public HierarchicalDataProvider getDataProvider() { return treeGrid.getDataProvider(); -- cgit v1.2.3