From 83f0a379553fca3a96e958a592e541b134fc7f8e Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 18 Dec 2024 12:28:18 +0100 Subject: [PATCH 1/2] CSSTUDIO-2880 Run refresh() atomically on the UI thread. --- .../olog/ui/LogEntryTableViewController.java | 36 +++++++++++-------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java index 4ba91940d5..b89dba75d6 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java @@ -436,24 +436,24 @@ public String getQuery() { } private synchronized void refresh() { - if (this.searchResult != null) { - List selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems()); + Runnable refreshRunnable = () -> { + if (this.searchResult != null) { + List selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems()); - List logEntries = searchResult.getLogs(); - logEntries.sort((o1, o2) -> -(o1.getCreatedDate().compareTo(o2.getCreatedDate()))); + List logEntries = searchResult.getLogs(); + logEntries.sort((o1, o2) -> -(o1.getCreatedDate().compareTo(o2.getCreatedDate()))); - boolean showDetailsBoolean = showDetails.get(); - var logs = logEntries.stream().map(le -> new TableViewListItem(le, showDetailsBoolean)).toList(); + boolean showDetailsBoolean = showDetails.get(); + var logs = logEntries.stream().map(le -> new TableViewListItem(le, showDetailsBoolean)).toList(); - ObservableList logsList = FXCollections.observableArrayList(logs); - tableView.setItems(logsList); + ObservableList logsList = FXCollections.observableArrayList(logs); + tableView.setItems(logsList); - // This will ensure that selected entries stay selected after the list has been - // updated from the search result. - for (TableViewListItem selectedItem : selectedLogEntries) { - for (TableViewListItem item : tableView.getItems()) { - if (item.getLogEntry().getId().equals(selectedItem.getLogEntry().getId())) { - Platform.runLater(() -> { + // This will ensure that selected entries stay selected after the list has been + // updated from the search result. + for (TableViewListItem selectedItem : selectedLogEntries) { + for (TableViewListItem item : tableView.getItems()) { + if (item.getLogEntry().getId().equals(selectedItem.getLogEntry().getId())) { if (goBackAndGoForwardActions.isPresent()) { goBackAndGoForwardActions.get().setIsRecordingHistoryDisabled(true); // Do not create a "Back" action for the automatic reload. tableView.getSelectionModel().select(item); @@ -461,10 +461,16 @@ private synchronized void refresh() { } else { tableView.getSelectionModel().select(item); } - }); + } } } } + }; + + if (Platform.isFxApplicationThread()) { + refreshRunnable.run(); + } else { + Platform.runLater(refreshRunnable); } } From 39a65fbf99d6586963512c7d12609391789821a4 Mon Sep 17 00:00:00 2001 From: Abraham Wolk Date: Wed, 18 Dec 2024 12:38:05 +0100 Subject: [PATCH 2/2] CSSTUDIO-2880 Remove "synchronized" from the definition of refresh(), since the function now always runs on the UI thread. --- .../phoebus/logbook/olog/ui/LogEntryTableViewController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java index b89dba75d6..8c692f72b9 100644 --- a/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java +++ b/app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java @@ -435,7 +435,7 @@ public String getQuery() { return query.getValue().getQuery(); } - private synchronized void refresh() { + private void refresh() { Runnable refreshRunnable = () -> { if (this.searchResult != null) { List selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems());