diff options
4 files changed, 18 insertions, 26 deletions
diff --git a/documentation/components/components-treegrid.asciidoc b/documentation/components/components-treegrid.asciidoc index 7f444602d9..d85178507d 100644 --- a/documentation/components/components-treegrid.asciidoc +++ b/documentation/components/components-treegrid.asciidoc @@ -37,20 +37,11 @@ Populating a [classname]#TreeGrid# with in-memory data can be done as follows [source, java] ---- -Project rootProject = getRootRroject(); - -TreeData<Project> data = new TreeData<>(); -// add a root level item with null parent -data.addItem(null, rootProject); - -// Add all children for root item -rootProject.flattened().forEach( - project -> data.addItems(project, project.getSubProjects())); - +// Initialize a TreeGrid and set in-memory data TreeGrid<Project> treeGrid = new TreeGrid<>(); -treeGrid.setDataProvider(new TreeDataProvider<>(data)); +treeGrid.setItems(getRootProjects(), Project::getSubProjects); -// the first column gets the hierarchy indicator by default +// The first column gets the hierarchy indicator by default treeGrid.addColumn(Project::getName).setCaption("Project Name"); treeGrid.addColumn(Project::getHoursDone).setCaption("Hours Done"); treeGrid.addColumn(Project::getLastModified).setCaption("Last Modified"); diff --git a/documentation/datamodel/datamodel-hierarchical.asciidoc b/documentation/datamodel/datamodel-hierarchical.asciidoc index f405bc775f..24605adc53 100644 --- a/documentation/datamodel/datamodel-hierarchical.asciidoc +++ b/documentation/datamodel/datamodel-hierarchical.asciidoc @@ -27,7 +27,7 @@ Collection<Project> projects = service.getProjects(); TreeData<Project> data = new TreeData<>(); // add root level items -data.addItems(null, projects); +data.addItems(null, Project::getSubProjects); // add children for the root level items projects.forEach(project -> data.addItems(project, project.getChildren())); @@ -42,7 +42,7 @@ When adding or removing items from the [classname]#TreeData#, you need to always [source, java] ---- -TreeData<Project> data = dataProvider.getData(); +TreeData<Project> data = dataProvider.getTreeData(); data.addItem(null, newProject); data.addItems(newProject, newProject.getChildren()); @@ -93,8 +93,9 @@ The following code snippet shows a simple example on how to building a lazy hier [source, java] ---- -class FileSystemDataProvider - extends AbstractHierarchicalDataProvider<File, FilenameFilter> { +class FileSystemDataProvider extends + AbstractBackEndHierarchicalDataProvider<File, FilenameFilter> { + private final File root; public FileSystemDataProvider(File root) { @@ -108,7 +109,7 @@ class FileSystemDataProvider } @Override - public Stream<File> fetchChildren( + public Stream<File> fetchChildrenFromBackEnd( HierarchicalQuery<File, FilenameFilter> query) { final File parent = query.getParentOptional().orElse(root); return query.getFilter() @@ -121,11 +122,6 @@ class FileSystemDataProvider public boolean hasChildren(File item) { return item.list() != null && item.list().length > 0; } - - @Override - public boolean isInMemory() { - return false; - } } ---- diff --git a/server/src/main/java/com/vaadin/data/TreeData.java b/server/src/main/java/com/vaadin/data/TreeData.java index def69745ef..f5f9709462 100644 --- a/server/src/main/java/com/vaadin/data/TreeData.java +++ b/server/src/main/java/com/vaadin/data/TreeData.java @@ -25,8 +25,12 @@ import java.util.Map; import java.util.Objects; import java.util.stream.Stream; +import com.vaadin.data.provider.TreeDataProvider; + /** * Class for representing hierarchical data. + * <p> + * Typically used as a backing data source for {@link TreeDataProvider}. * * @author Vaadin Ltd * @since 8.1 @@ -203,7 +207,7 @@ public class TreeData<T> implements Serializable { /** * Adds the given items as root items and uses the given value provider to * recursively populate children of the root items. - * + * * @param rootItems * the root items to add * @param childItemProvider diff --git a/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java b/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java index cce1af22d0..ed5e710cc8 100644 --- a/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java +++ b/server/src/main/java/com/vaadin/data/provider/TreeDataProvider.java @@ -26,7 +26,8 @@ import com.vaadin.server.SerializableFunction; import com.vaadin.server.SerializablePredicate; /** - * {@link HierarchicalDataProvider} wrapper for {@link TreeData}. + * An in-memory data provider for listing components that display hierarchical + * data. Uses an instance of {@link TreeData} as its source of data. * * @author Vaadin Ltd * @since 8.1 @@ -47,8 +48,8 @@ public class TreeDataProvider<T> /** * Constructs a new TreeDataProvider. * <p> - * All changes made to the given {@link TreeData} object will also be - * visible through this data provider. + * This data provider should be refreshed after making changes to the + * underlying {@link TreeData} instance. * * @param treeData * the backing {@link TreeData} for this provider, not |