Skip to content

Commit

Permalink
Merge pull request #3195 from ControlSystemStudio/CSSTUDIO-2572
Browse files Browse the repository at this point in the history
CSSTUDIO-2572: Add a "Jump to Log Entry" TextField to the Logbook application
  • Loading branch information
abrahamwolk authored Nov 20, 2024
2 parents e660df0 + 3eb00b2 commit 8559774
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToolBar;
import javafx.scene.image.ImageView;
Expand All @@ -40,9 +41,14 @@
import org.phoebus.olog.es.api.model.OlogLog;
import org.phoebus.ui.javafx.ImageCache;

import java.util.logging.Level;
import java.util.logging.Logger;


public class LogEntryDisplayController {

static Logger log = Logger.getLogger(LogEntryDisplayController.class.getName());

@FXML
@SuppressWarnings("unused")
private SingleLogEntryDisplayController singleLogEntryDisplayController;
Expand All @@ -69,6 +75,8 @@ public class LogEntryDisplayController {
private Node singleLogEntryDisplay;
@FXML
private Node mergedLogEntryDisplay;
@FXML
private TextField jumpToLogEntryTextField;

ImageView goBackButtonIcon = ImageCache.getImageView(LogEntryDisplayController.class, "/icons/backward_nav.png");
ImageView goBackButtonIconDisabled = ImageCache.getImageView(LogEntryDisplayController.class, "/icons/backward_disabled.png");
Expand Down Expand Up @@ -112,6 +120,19 @@ public void initialize() {
goForwardButton.disableProperty().addListener(goForwardButtonDisabledPropertyChangeListener);
goForwardButtonDisabledPropertyChangeListener.changed(goForwardButton.disableProperty(), false, true);
}

jumpToLogEntryTextField.setPromptText(Messages.LogEntryID);
jumpToLogEntryTextField.focusedProperty().addListener((property, oldValue, newValue) -> {
if (oldValue && !newValue) {
// When clicking away without first pressing enter, restore the current value of jumpToLogEntryTextField:
if (logEntryProperty.get() != null) {
jumpToLogEntryTextField.setText(logEntryProperty.get().getId().toString());
}
else {
jumpToLogEntryTextField.setText("");
}
}
});
}

@FXML
Expand All @@ -133,6 +154,28 @@ public void showHideLogEntryGroup() {
}
}

@FXML
public void jumpToLogEntry() {
String logEntryIDToJumpToString = jumpToLogEntryTextField.getText();
long logEntryIDToJumpTo;
try {
logEntryIDToJumpTo = Long.parseLong(logEntryIDToJumpToString);
}
catch (NumberFormatException numberFormatException) {
return;
}

if (logEntryIDToJumpTo > 0) {
if (logEntryTableViewController.goBackAndGoForwardActions.isPresent()) {
boolean success = logEntryTableViewController.goBackAndGoForwardActions.get().loadLogEntryWithID(logEntryIDToJumpTo);
if (!success) {
log.log(Level.WARNING, "Error loading entry with log entry ID: " + logEntryIDToJumpTo + ".");
}
}
}
Platform.runLater(() -> jumpToLogEntryTextField.end());
}

@FXML
public void reply() {
// Show a new editor dialog. When user selects to save the reply entry, update the original log entry
Expand Down Expand Up @@ -175,7 +218,8 @@ public void setLogEntry(LogEntry logEntry) {
currentViewProperty.set(SINGLE);
showHideLogEntryGroupButton.selectedProperty().set(false);
hasLinkedEntriesProperty.set(logEntry.getProperties()
.stream().anyMatch(p -> p.getName().equals(LogGroupProperty.NAME)));;
.stream().anyMatch(p -> p.getName().equals(LogGroupProperty.NAME)));
jumpToLogEntryTextField.setText(logEntryProperty.get().getId().toString());
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,17 @@ private void addGoForwardAction() {
}
}

private void loadLogEntryWithID(Long id) {
goForwardActions.clear();
addGoBackAction();

LogEntry logEntry = controller.client.getLog(id);
gotoLogEntry(logEntry);
protected boolean loadLogEntryWithID(Long id) {
try {
LogEntry logEntry = controller.client.getLog(id);
goForwardActions.clear();
addGoBackAction();
gotoLogEntry(logEntry);
return true;
}
catch (RuntimeException runtimeException) {
return false;
}
}

protected void goBack() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ public class Messages
Forward,
GroupingFailed,
GroupSelectedEntries,
JumpToLogEntry,
Level,
Logbook,
LogbookNotSupported,
LogbooksSearchFailTitle,
LogbookServiceUnavailableTitle,
LogbookServiceHasNoLogbooks,
LogEntryID,
NewLogEntry,
NoAttachments,
NoClipboardContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
<ToggleButton fx:id="showHideLogEntryGroupButton" contentDisplay="RIGHT" mnemonicParsing="false"
text="%ShowHideLogEntryGroup" disable="true" onAction="#showHideLogEntryGroup"/>
<Region fx:id="spring" /> <!-- Spring to make the next elements right-aligned. -->
<Label text="%JumpToLogEntry" />
<TextField fx:id="jumpToLogEntryTextField" onAction="#jumpToLogEntry" alignment="CENTER_LEFT" prefWidth="100"/>
<Button fx:id="goBackButton" mnemonicParsing="false"
onAction="#goBack" text="%Back" disable="true" />
<Button fx:id="goForwardButton" mnemonicParsing="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Help=Help
HitsPerPage=Hits per page:
ImageWidth=Width
ImageHeight=Height
JumpToLogEntry=Jump to Log Entry:
Level=Level
Logbook=Logbook
Logbooks=Logbooks:
Expand All @@ -64,6 +65,7 @@ LogbookServiceHasNoLogbooks=Logbook service "{0}" has no logbooks or is not avai
LogbooksSearchFailTitle=Logbook Search Error
LogbooksTitle=Select Logbooks
LogbooksTooltip=Add logbook to the log entry.
LogEntryID=Log Entry ID
NoClipboardContent=Clipboard does not contain any content that may be added as attachment.
NoAttachments=No Attachments
NoProperties=No Properties
Expand Down

0 comments on commit 8559774

Please sign in to comment.