From fd042737cb2cfdcba7d3c797230984801e01bbe2 Mon Sep 17 00:00:00 2001 From: Florian Hoelzl <hoelzl@fortiss.org> Date: Mon, 3 Feb 2020 13:38:15 +0100 Subject: [PATCH] Kernel: DynamicTreeTableUIProvider filter implementation improved. Issue-Ref: 3907 Issue-Url: https://af3-developer.fortiss.org/issues/3907 Signed-off-by: Florian Hoelzl <hoelzl@fortiss.org> --- .../ui/javafx/control/treetableview/.ratings | 6 ++-- .../DynamicTreeContentProviderBase.java | 23 +++++++++---- .../treetableview/DynamicTreeItem.java | 12 ++----- .../treetableview/DynamicTreeTableViewer.java | 32 +------------------ 4 files changed, 23 insertions(+), 50 deletions(-) diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings index 743dd3f6c..3102da926 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/.ratings @@ -1,7 +1,7 @@ -DynamicTreeContentProviderBase.java 767a518dc8f4ea755aeff0858d06db41c8721c0d GREEN -DynamicTreeItem.java f68e85125aecdb2e588450b7652ffa57c4dc9088 GREEN +DynamicTreeContentProviderBase.java e801da995a1b6e5a1b757247c1638bafb6073e6d YELLOW +DynamicTreeItem.java 15adce9e9a7fedf51f2369abf80e79ef659f066f YELLOW DynamicTreeTableUIProviderBase.java 7bfc1395283d3dc10026aff5e2e65df88d25f3a7 GREEN -DynamicTreeTableViewer.java 3b8850f097093230401aee834fe61a16250c215c GREEN +DynamicTreeTableViewer.java 80df0fbe814da719b3fa6dc1644ea3333cffee93 YELLOW DynamicTreeUIProviderBase.java 56fe4df4577b35f1e5e6e4c4be189b706c852d52 GREEN DynamicTreeViewer.java da5e24ae57777a482d8e12c8262513d8143bfa93 GREEN DynamicTreeViewerBase.java 47124c847de322a0ae26eb7a114f85ce4bd02d7e GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeContentProviderBase.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeContentProviderBase.java index 767a518dc..e801da995 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeContentProviderBase.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeContentProviderBase.java @@ -30,9 +30,20 @@ public abstract class DynamicTreeContentProviderBase<T> { /** Returns the children of the given parent in the tree. */ protected abstract Collection<? extends T> getChildren(T parent); - /** Returns whether the filter input should be enabled. */ - protected boolean enableFiltering() { - return false; + /** The current filter expression. */ + private String filterExpression = null; + + /** Sets the filter expression. */ + public void setFilterExpression(String filterExpression) { + this.filterExpression = filterExpression; + } + + /** + * Returns the filter expression. Sub-classes may override or simply use + * {@link #setFilterExpression(String)} + */ + protected String getFilterExpression() { + return filterExpression; } /** @@ -60,12 +71,12 @@ public abstract class DynamicTreeContentProviderBase<T> { } /** Returns the filtered children of the given element. */ - public final Collection<? extends T> getFilteredSortedChildren(T parent, String filterValue) { + public final Collection<? extends T> getFilteredSortedChildren(T parent) { Collection<? extends T> l = getChildren(parent); if(l == null) { return emptyList(); } - return l.stream().filter(getFilterPredicate(filterValue)).sorted(getSortingComparator()) - .collect(toList()); + return l.stream().filter(getFilterPredicate(getFilterExpression())) + .sorted(getSortingComparator()).collect(toList()); } } diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeItem.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeItem.java index f68e85125..15adce9e9 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeItem.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeItem.java @@ -36,14 +36,6 @@ public class DynamicTreeItem<T> extends TreeItem<T> { /** Updates the children of this item from the underlying content model. */ public void update() { - update(null); - } - - /** - * Updates the children of this item from the underlying content model using the given filter - * value. - */ - public void update(String filterValue) { // remember expanded state of children HashMap<T, TreeItem<T>> expanded = new HashMap<>(); for(TreeItem<T> c : getChildren()) { @@ -54,7 +46,7 @@ public class DynamicTreeItem<T> extends TreeItem<T> { // get list of children and create tree items getChildren().clear(); DynamicTreeContentProviderBase<T> cp = viewer.getContentProvider(); - for(T element : cp.getFilteredSortedChildren(getValue(), filterValue)) { + for(T element : cp.getFilteredSortedChildren(getValue())) { DynamicTreeItem<T> dti; if(expanded.containsKey(element)) { dti = (DynamicTreeItem<T>)expanded.get(element); @@ -62,7 +54,7 @@ public class DynamicTreeItem<T> extends TreeItem<T> { dti = new DynamicTreeItem<T>(element, viewer); } getChildren().add(dti); - dti.update(filterValue); + dti.update(); } } diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java index 3b8850f09..80df0fbe8 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/control/treetableview/DynamicTreeTableViewer.java @@ -16,14 +16,11 @@ package org.fortiss.tooling.common.ui.javafx.control.treetableview; import javafx.beans.property.SimpleObjectProperty; -import javafx.scene.Parent; import javafx.scene.control.SelectionMode; -import javafx.scene.control.TextField; import javafx.scene.control.TreeItem; import javafx.scene.control.TreeTableColumn; import javafx.scene.control.TreeTableView; import javafx.scene.control.TreeTableView.TreeTableViewSelectionModel; -import javafx.scene.layout.BorderPane; /** * A JavaFX {@link TreeTableView} based on an {@link DynamicTreeContentProviderBase} and @@ -39,12 +36,6 @@ import javafx.scene.layout.BorderPane; public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { /** The {@link TreeTableView} control to be managed. */ private final TreeTableView<T> view; - /** The filter text field if filtering is enabled in content provider. */ - private final TextField filter; - /** The pane for filter and tree widgets. */ - private final BorderPane pane; - /** The content provider of this tree-table. */ - private final DynamicTreeContentProviderBase<T> contentProvider; /** The UI provider of this tree-table. */ private final DynamicTreeTableUIProviderBase<T> uiProvider; @@ -53,22 +44,9 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { DynamicTreeContentProviderBase<T> contentProvider, DynamicTreeTableUIProviderBase<T> uiProvider) { super(contentProvider); - this.contentProvider = contentProvider; this.uiProvider = uiProvider; // construct view this.view = view; - if(contentProvider.enableFiltering()) { - filter = new TextField(); - filter.textProperty().addListener((obs, oVal, nVal) -> { - update(); - }); - pane = new BorderPane(); - pane.setTop(filter); - pane.setCenter(view); - } else { - filter = null; - pane = null; - } DynamicTreeItem<T> rootItem = new DynamicTreeItem<T>(root, this); view.setRoot(rootItem); view.setShowRoot(showRoot); @@ -97,7 +75,7 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { public void update() { // wild cast works: see constructor DynamicTreeItem<T> rootItem = (DynamicTreeItem<T>)view.getRoot(); - rootItem.update(filter != null ? filter.getText() : null); + rootItem.update(); } /** Expands items up to the given level. */ @@ -147,12 +125,4 @@ public final class DynamicTreeTableViewer<T> extends DynamicTreeViewerBase<T> { public TreeTableView<T> getControl() { return view; } - - /** Returns the filter pane or the tree view if filtering is disabled. */ - public Parent getFilterControl() { - if(contentProvider.enableFiltering()) { - return pane; - } - return getControl(); - } } -- GitLab