Skip to content

Commit 32bbac9

Browse files
committed
Bug fix filter handling in save&restore
1 parent 9afc568 commit 32bbac9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

app/save-and-restore/app/src/main/java/org/phoebus/applications/saveandrestore/ui/SaveAndRestoreController.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javafx.beans.property.ObjectProperty;
2828
import javafx.beans.property.SimpleBooleanProperty;
2929
import javafx.beans.property.SimpleObjectProperty;
30+
import javafx.beans.value.ObservableValue;
3031
import javafx.collections.FXCollections;
3132
import javafx.collections.ObservableList;
3233
import javafx.concurrent.Task;
@@ -202,6 +203,7 @@ public class SaveAndRestoreController extends SaveAndRestoreBaseController
202203
private final MenuItem compareSnapshotsMenuItem = new MenuItem(Messages.contextMenuCompareSnapshots, ImageCache.getImageView(ImageCache.class, "/icons/save-and-restore/compare.png"));
203204
private final MenuItem deleteNodeMenuItem = new MenuItem(Messages.contextMenuDelete, ImageCache.getImageView(ImageCache.class, "/icons/delete.png"));
204205
private final MenuItem pasteMenuItem = new MenuItem(Messages.paste, ImageCache.getImageView(ImageCache.class, "/icons/paste.png"));
206+
private final ObservableValue<? extends ObservableList<Filter>> comboBoxItems = new SimpleObjectProperty<>(filtersList);
205207

206208
private final BooleanProperty autoFilterActive = new SimpleBooleanProperty();
207209

@@ -273,6 +275,7 @@ public void initialize(URL url, ResourceBundle resourceBundle) {
273275

274276
filtersComboBox.disableProperty().bind(Bindings.createBooleanBinding(autoFilterActive::get, autoFilterActive));
275277
filtersComboBox.valueProperty().bindBidirectional(currentFilterProperty);
278+
currentFilterProperty.addListener((obs, o, n) -> applyFilter(n));
276279

277280
treeView.setEditable(true);
278281

@@ -335,8 +338,7 @@ public Filter fromString(String s) {
335338
}
336339
});
337340

338-
filtersComboBox.itemsProperty().bind(new SimpleObjectProperty<>(filtersList));
339-
341+
filtersComboBox.itemsProperty().bind(comboBoxItems);
340342

341343
// Clear clipboard to make sure that only custom data format is
342344
// considered in paste actions.
@@ -1118,10 +1120,14 @@ public boolean matchesFilter(Node node) {
11181120
* Applies a {@link Filter} selected by user. The service will be queries for {@link Node}s matching
11191121
* the {@link Filter}, then the {@link TreeView} is updated based on the search result.
11201122
*
1121-
* @param filter {@link Filter} selected by user.
1123+
* @param filter {@link Filter} selected by user or through business logic. If <code>null</code>, then the
1124+
* <code>no filter</code> {@link Filter} is applied.
11221125
*/
11231126
private void applyFilter(Filter filter) {
11241127
treeView.getSelectionModel().clearSelection();
1128+
if(filter == null){
1129+
return;
1130+
}
11251131
Map<String, String> searchParams =
11261132
SearchQueryUtil.parseHumanReadableQueryString(filter.getQueryString());
11271133
// In this case we want to hit all matching, i.e. no pagination.
@@ -1164,9 +1170,9 @@ private void filterAddedOrUpdated(Filter filter) {
11641170
final int index = filtersList.indexOf(filter);
11651171
filtersList.set(index, filter);
11661172
filtersComboBox.valueProperty().set(filter);
1167-
// If this is the active filter, update the tree view
1173+
// If this is the current filter, update the tree view
11681174
if (filter.equals(filtersComboBox.getSelectionModel().getSelectedItem())) {
1169-
applyFilter(filter);
1175+
currentFilterProperty.set(filter);
11701176
}
11711177
}
11721178
}
@@ -1186,8 +1192,10 @@ private void filterRemoved(String name) {
11861192
Filter filterToRemove = new Filter();
11871193
filterToRemove.setName(name);
11881194
Platform.runLater(() -> {
1195+
if (filterToRemove.equals(filtersComboBox.getSelectionModel().getSelectedItem())) {
1196+
currentFilterProperty.set(null);
1197+
}
11891198
filtersList.remove(filterToRemove);
1190-
currentFilterProperty.set(null);
11911199
});
11921200
}
11931201
}

0 commit comments

Comments
 (0)