Skip to content

Commit

Permalink
CSSTUDIO-2880 Run refresh() atomically on the UI thread.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrahamwolk committed Dec 18, 2024
1 parent 368971f commit 83f0a37
Showing 1 changed file with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,35 +436,41 @@ public String getQuery() {
}

private synchronized void refresh() {
if (this.searchResult != null) {
List<TableViewListItem> selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems());
Runnable refreshRunnable = () -> {
if (this.searchResult != null) {
List<TableViewListItem> selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems());

List<LogEntry> logEntries = searchResult.getLogs();
logEntries.sort((o1, o2) -> -(o1.getCreatedDate().compareTo(o2.getCreatedDate())));
List<LogEntry> 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<TableViewListItem> logsList = FXCollections.observableArrayList(logs);
tableView.setItems(logsList);
ObservableList<TableViewListItem> 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);
goBackAndGoForwardActions.get().setIsRecordingHistoryDisabled(false);
} else {
tableView.getSelectionModel().select(item);
}
});
}
}
}
}
};

if (Platform.isFxApplicationThread()) {
refreshRunnable.run();
} else {
Platform.runLater(refreshRunnable);
}
}

Expand Down

0 comments on commit 83f0a37

Please sign in to comment.