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-2572: Add a "Jump to Log Entry" TextField to the Logbook application #3195

Merged
merged 12 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -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
Loading