Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSSTUDIO-2880 Run refresh() atomically on the UI thread. #3215

Merged
merged 2 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading