Skip to content
Snippets Groups Projects
Commit 3ec4a1a6 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Common.UI JFX: Support for Stream-based TreeTables

parent e4f0ad74
No related branches found
No related tags found
1 merge request!1263541
DynamicList.java 6206ef9150c1f4bf07102820ae2a647ec3fb882b YELLOW
DynamicList.java 786300e2e914826da239329d190abea1710478ea YELLOW
DynamicListContentProvider.java 817cba44f246a361207a88ef9a4e1869215803f7 YELLOW
DynamicStreamContentProvider.java f46e91400609cba54793dd240be0fe2aa0d5cced YELLOW
DynamicTreeContentProviderBase.java 6760a6dc5721175b1dada8f30fd9da05f7bcc4b3 GREEN
DynamicTreeItem.java 7486071d20e896d6ca9a9101bf105caccf3656d0 YELLOW
DynamicTreeItemBase.java d883066ecc181120302ca32f328538de7a45b093 YELLOW
DynamicTreeTableUIProviderBase.java f78c0f8b52fbc939166b3f94f7f6006cc0f4d32b GREEN
DynamicTreeTableViewer.java 048e242856e2ac56969711d2698bdbb2c4235704 YELLOW
DynamicTreeTableViewer.java 8ce7fdb68560aab27bc2dbe4d3c52c4447cd8906 YELLOW
DynamicTreeUIProviderBase.java e9b68607683de279d0cb8712a28dc131c5c33ece GREEN
DynamicTreeViewer.java 7b22b9a99b7d34bfffdadd99db630bb683187d7f YELLOW
DynamicTreeViewerBase.java a2013538b62d86f6a09efdf2cd78babac2072484 GREEN
......
......@@ -17,6 +17,8 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import java.util.Collection;
import java.util.HashMap;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javafx.scene.control.TreeItem;
......@@ -28,7 +30,18 @@ public class DynamicList<T> extends DynamicTreeItemBase<T> {
/** The viewer. */
private DynamicTreeContentProviderBase<T> contentProvider;
/** Constructor. */
/**
* Constructor. The given {@link Supplier} is queried on updates to retrieve a recent list of
* elements to display.
*/
@SuppressWarnings("unchecked")
public DynamicList(Supplier<Stream<T>> data,
DynamicStreamContentProvider<T, Supplier<Stream<T>>> contentProvider) {
super((T)data);
this.contentProvider = contentProvider;
}
/** Constructor. The given collection must be updated by the initializer to reflect changes. */
@SuppressWarnings("unchecked")
public DynamicList(Collection<T> data, DynamicTreeContentProviderBase<T> contentProvider) {
super((T)data);
......
/*-------------------------------------------------------------------------+
| Copyright 2020 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.toList;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.stream.Stream;
/**
* Content provider whose element list is dynamically retrieved from a supplier.
*
* @author diewald
*/
public class DynamicStreamContentProvider<T, S extends Supplier<Stream<T>>>
extends DynamicTreeContentProviderBase<T> {
/** {@inheritDoc} */
@Override
protected Collection<? extends T> getChildren(T parent) {
if(parent instanceof Supplier) {
@SuppressWarnings("unchecked") Supplier<Stream<T>> supp = ((S)parent);
return supp.get().collect(toList());
}
return emptyList();
}
}
......@@ -18,6 +18,8 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview;
import static java.lang.Integer.MAX_VALUE;
import java.util.Collection;
import java.util.function.Supplier;
import java.util.stream.Stream;
import javafx.beans.property.SimpleObjectProperty;
import javafx.scene.control.SelectionMode;
......@@ -47,7 +49,21 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> {
/** The UI provider of this tree-table. */
private final DynamicTreeTableUIProviderBase<T> uiProvider;
/** Constructor. */
/**
* Constructor. The given {@link Supplier} is queried on updates to obtain a list of elements to
* display.
*/
public DynamicTreeTableViewer(TreeTableView<T> view, Supplier<Stream<T>> listFctn,
DynamicStreamContentProvider<T, Supplier<Stream<T>>> contentProvider,
DynamicTreeTableUIProviderBase<T> uiProvider) {
this(view, new DynamicList<T>(listFctn, contentProvider), false, 0, contentProvider,
uiProvider);
}
/**
* Constructor. The given input collection must be updated by the caller such that changes are
* reflected in the corresponding {@link TreeTableView}.
*/
public DynamicTreeTableViewer(TreeTableView<T> view, Collection<T> list,
DynamicListContentProvider<T> contentProvider,
DynamicTreeTableUIProviderBase<T> uiProvider) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment