Skip to content

Commit

Permalink
CSSTUDIO-2371 Introduce a setter method for LogEntryTableViewControll…
Browse files Browse the repository at this point in the history
…er.goBackAndGoForwardActions and make setting this field optional.
  • Loading branch information
abrahamwolk committed Aug 28, 2024
1 parent be5a85d commit 453a960
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,16 @@ public void newLogEntry(){

@FXML
public void goBack() {
logEntryTableViewController.goBackAndGoForwardActions.goBack();
if (logEntryTableViewController.goBackAndGoForwardActions.isPresent()) {
logEntryTableViewController.goBackAndGoForwardActions.get().goBack();
}
}

@FXML
public void goForward() {
logEntryTableViewController.goBackAndGoForwardActions.goForward();
if (logEntryTableViewController.goBackAndGoForwardActions.isPresent()) {
logEntryTableViewController.goBackAndGoForwardActions.get().goForward();
}
}

public void setLogEntry(LogEntry logEntry) {
Expand Down Expand Up @@ -187,7 +191,9 @@ public void updateLogEntry(LogEntry logEntry){

public void setLogEntryTableViewController(LogEntryTableViewController logEntryTableViewController){
this.logEntryTableViewController = logEntryTableViewController;
goBackButton.disableProperty().bind(Bindings.isEmpty(logEntryTableViewController.goBackAndGoForwardActions.goBackActions));
goForwardButton.disableProperty().bind(Bindings.isEmpty(logEntryTableViewController.goBackAndGoForwardActions.goForwardActions));
if (logEntryTableViewController.goBackAndGoForwardActions.isPresent()) {
goBackButton.disableProperty().bind(Bindings.isEmpty(logEntryTableViewController.goBackAndGoForwardActions.get().goBackActions));
goForwardButton.disableProperty().bind(Bindings.isEmpty(logEntryTableViewController.goBackAndGoForwardActions.get().goForwardActions));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public LogEntryTable(final LogEntryTableApp app) {
try {
if (app.getClient() != null) {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
return clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class, GoBackAndGoForwardActions.class)
.newInstance(app.getClient(), ologQueryManager, searchParameters, goBackAndGoForwardActions);
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class).newInstance(app.getClient(), ologQueryManager, searchParameters);
logEntryTableViewController.setGoBackAndGoForwardActions(goBackAndGoForwardActions);
return logEntryTableViewController;
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class, SearchParameters.class)
.newInstance(app.getClient(), searchParameters);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ public class LogEntryTableViewController extends LogbookSearchController {
*/
public LogEntryTableViewController(LogClient logClient,
OlogQueryManager ologQueryManager,
SearchParameters searchParameters,
LogEntryTable.GoBackAndGoForwardActions goBackAndGoForwardActions) {
SearchParameters searchParameters) {
setClient(logClient);
this.ologQueryManager = ologQueryManager;
this.searchParameters = searchParameters;
this.goBackAndGoForwardActions = goBackAndGoForwardActions;
}

protected void setGoBackAndGoForwardActions(LogEntryTable.GoBackAndGoForwardActions goBackAndGoForwardActions) {
this.goBackAndGoForwardActions = Optional.of(goBackAndGoForwardActions);
}

private final SimpleIntegerProperty hitCountProperty = new SimpleIntegerProperty(0);
Expand All @@ -125,8 +127,7 @@ public LogEntryTableViewController(LogClient logClient,

private final SearchParameters searchParameters;

protected final LogEntryTable.GoBackAndGoForwardActions goBackAndGoForwardActions;

protected Optional<LogEntryTable.GoBackAndGoForwardActions> goBackAndGoForwardActions = Optional.empty();

@FXML
public void initialize() {
Expand Down Expand Up @@ -188,9 +189,9 @@ public void initialize() {
tableView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
// Update detailed view, but only if selection contains a single item.
if (newValue != null && tableView.getSelectionModel().getSelectedItems().size() == 1) {
if (!goBackAndGoForwardActions.getIsRecordingHistoryDisabled()) {
goBackAndGoForwardActions.addGoBackAction();
goBackAndGoForwardActions.goForwardActions.clear();
if (goBackAndGoForwardActions.isPresent() && !goBackAndGoForwardActions.get().getIsRecordingHistoryDisabled()) {
goBackAndGoForwardActions.get().addGoBackAction();
goBackAndGoForwardActions.get().goForwardActions.clear();
}
logEntryDisplayController.setLogEntry(newValue.getLogEntry());
}
Expand Down Expand Up @@ -403,9 +404,14 @@ private void refresh() {
for (TableViewListItem item : tableView.getItems()) {
if (item.getLogEntry().getId().equals(selectedItem.getLogEntry().getId())) {
Platform.runLater(() -> {
goBackAndGoForwardActions.setIsRecordingHistoryDisabled(true); // Do not create a "Back" action for the automatic reload.
tableView.getSelectionModel().select(item);
goBackAndGoForwardActions.setIsRecordingHistoryDisabled(false);
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);
}
});
}
}
Expand Down

0 comments on commit 453a960

Please sign in to comment.