Skip to content

Commit bac3f06

Browse files
authored
Merge pull request #3191 from ControlSystemStudio/CSSTUDIO-2167
CSSTUDIO-2167 Support for "decorations" in the Logbook application
2 parents a296786 + a906512 commit bac3f06

File tree

7 files changed

+166
-80
lines changed

7 files changed

+166
-80
lines changed

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/AdvancedSearchViewController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import javafx.beans.value.ObservableValue;
2525
import javafx.fxml.FXML;
2626
import javafx.geometry.Pos;
27+
import javafx.scene.Node;
2728
import javafx.scene.control.Button;
2829
import javafx.scene.control.ComboBox;
2930
import javafx.scene.control.Label;
@@ -113,10 +114,11 @@ public class AdvancedSearchViewController {
113114
private final SimpleBooleanProperty requireAttachments = new SimpleBooleanProperty(false);
114115

115116
private Runnable searchCallback = () -> {
116-
throw new IllegalStateException("Search callback is not set on AdvancedSearchViewConroller!");
117+
throw new IllegalStateException("Search callback is not set on AdvancedSearchViewController!");
117118
};
118119

119-
public AdvancedSearchViewController(LogClient logClient, SearchParameters searchParameters) {
120+
public AdvancedSearchViewController(LogClient logClient,
121+
SearchParameters searchParameters) {
120122
this.logClient = logClient;
121123
this.searchParameters = searchParameters;
122124
}

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryCellController.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import javafx.scene.control.Label;
77
import javafx.scene.image.Image;
88
import javafx.scene.image.ImageView;
9+
import javafx.scene.layout.HBox;
910
import javafx.scene.layout.Pane;
1011
import javafx.scene.layout.VBox;
1112
import org.commonmark.Extension;
@@ -16,9 +17,11 @@
1617
import org.phoebus.logbook.Logbook;
1718
import org.phoebus.logbook.Tag;
1819
import org.phoebus.logbook.olog.ui.LogEntryTableViewController.TableViewListItem;
20+
import org.phoebus.logbook.olog.ui.spi.Decoration;
1921
import org.phoebus.ui.javafx.ImageCache;
2022

2123
import java.util.Arrays;
24+
import java.util.LinkedList;
2225
import java.util.List;
2326
import java.util.stream.Collectors;
2427

@@ -40,11 +43,16 @@ public class LogEntryCellController {
4043
@FXML
4144
VBox root;
4245

46+
@FXML
47+
VBox logEntryCell;
48+
4349
@FXML
4450
Label time;
4551
@FXML
4652
Label owner;
4753
@FXML
54+
HBox decorationNodes;
55+
@FXML
4856
Label title;
4957
@FXML
5058
Label logbooks;
@@ -74,7 +82,6 @@ public class LogEntryCellController {
7482

7583
private SimpleBooleanProperty expanded = new SimpleBooleanProperty(true);
7684

77-
7885
public LogEntryCellController() {
7986

8087
List<Extension> extensions = Arrays.asList(TablesExtension.create(), ImageAttributesExtension.create());
@@ -92,8 +99,20 @@ public void initialize() {
9299
conversationIcon.setImage(conversation);
93100
}
94101

95-
@FXML
102+
private List<Decoration> decorations = new LinkedList<>();
103+
104+
public void setDecorations(List<Decoration> decorations) {
105+
this.decorations = decorations;
106+
}
107+
96108
public void refresh() {
109+
110+
decorationNodes.getChildren().clear();
111+
for (Decoration decoration : decorations) {
112+
Node decorationNode = decoration.createDecorationForLogEntryCell(logEntry.getLogEntry());
113+
decorationNodes.getChildren().add(decorationNode);
114+
}
115+
97116
if (logEntry != null) {
98117

99118
time.setText(SECONDS_FORMAT.format(logEntry.getLogEntry().getCreatedDate()));
@@ -126,8 +145,8 @@ public void refresh() {
126145

127146
logEntryId.setText(logEntry.getLogEntry().getId() != null ? logEntry.getLogEntry().getId().toString() : "");
128147
level.setText(logEntry.getLogEntry().getLevel());
129-
130148
}
149+
131150
}
132151

133152
public void setLogEntry(TableViewListItem logEntry) {

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTable.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
import org.phoebus.logbook.LogClient;
1212
import org.phoebus.logbook.LogEntry;
1313
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
14+
import org.phoebus.logbook.olog.ui.spi.Decoration;
1415
import org.phoebus.logbook.olog.ui.write.AttachmentsEditorController;
1516
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
1617
import org.phoebus.ui.docking.DockItem;
1718
import org.phoebus.ui.docking.DockPane;
1819

1920
import java.io.IOException;
2021
import java.net.URI;
22+
import java.util.LinkedList;
23+
import java.util.List;
2124
import java.util.Optional;
2225
import java.util.ResourceBundle;
26+
import java.util.ServiceLoader;
2327
import java.util.logging.Level;
2428
import java.util.logging.Logger;
2529

@@ -32,10 +36,18 @@ public class LogEntryTable implements AppInstance {
3236
private LogEntryTableViewController controller;
3337

3438
public GoBackAndGoForwardActions goBackAndGoForwardActions;
35-
3639
public LogEntryTable(final LogEntryTableApp app) {
3740
this.app = app;
3841
goBackAndGoForwardActions = new GoBackAndGoForwardActions();
42+
43+
List<Decoration> decorations = new LinkedList<>();
44+
{
45+
ServiceLoader<Decoration> decorationClasses = ServiceLoader.load(Decoration.class);
46+
for (Decoration decoration : decorationClasses) {
47+
decorations.add(decoration);
48+
}
49+
}
50+
3951
try {
4052
OlogQueryManager ologQueryManager = OlogQueryManager.getInstance();
4153
SearchParameters searchParameters = new SearchParameters();
@@ -51,10 +63,10 @@ public LogEntryTable(final LogEntryTableApp app) {
5163
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
5264
LogEntryTableViewController logEntryTableViewController = (LogEntryTableViewController) clazz.getConstructor(LogClient.class, OlogQueryManager.class, SearchParameters.class).newInstance(app.getClient(), ologQueryManager, searchParameters);
5365
logEntryTableViewController.setGoBackAndGoForwardActions(goBackAndGoForwardActions);
66+
logEntryTableViewController.setDecorations(decorations);
5467
return logEntryTableViewController;
5568
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
56-
return clazz.getConstructor(LogClient.class, SearchParameters.class)
57-
.newInstance(app.getClient(), searchParameters);
69+
return clazz.getConstructor(LogClient.class, SearchParameters.class).newInstance(app.getClient(), searchParameters);
5870
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
5971
SingleLogEntryDisplayController singleLogEntryDisplayController = (SingleLogEntryDisplayController) clazz.getConstructor(LogClient.class).newInstance(app.getClient());
6072
singleLogEntryDisplayController.setSelectLogEntryInUI(id -> goBackAndGoForwardActions.loadLogEntryWithID(id));

app/logbook/olog/ui/src/main/java/org/phoebus/logbook/olog/ui/LogEntryTableViewController.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.phoebus.logbook.SearchResult;
4949
import org.phoebus.logbook.olog.ui.query.OlogQuery;
5050
import org.phoebus.logbook.olog.ui.query.OlogQueryManager;
51+
import org.phoebus.logbook.olog.ui.spi.Decoration;
5152
import org.phoebus.logbook.olog.ui.write.LogEntryEditorStage;
5253
import org.phoebus.logbook.olog.ui.write.LogEntryUpdateStage;
5354
import org.phoebus.olog.es.api.model.LogGroupProperty;
@@ -232,6 +233,10 @@ public void initialize() {
232233
descriptionCol.setMaxWidth(1f * Integer.MAX_VALUE * 100);
233234
descriptionCol.setCellValueFactory(col -> new SimpleObjectProperty<>(col.getValue()));
234235
descriptionCol.setCellFactory(col -> new TableCell<>() {
236+
{
237+
setStyle("-fx-padding: -1px");
238+
}
239+
235240
private final Node graphic;
236241
private final PseudoClass childlessTopLevel =
237242
PseudoClass.getPseudoClass("grouped");
@@ -242,6 +247,7 @@ public void initialize() {
242247
FXMLLoader loader = new FXMLLoader(getClass().getResource("LogEntryCell.fxml"));
243248
graphic = loader.load();
244249
controller = loader.getController();
250+
controller.setDecorations(decorations);
245251
} catch (IOException exc) {
246252
throw new RuntimeException(exc);
247253
}
@@ -399,8 +405,20 @@ public void setLogs(List<LogEntry> logs) {
399405
throw new RuntimeException(new UnsupportedOperationException());
400406
}
401407

408+
private List<Decoration> decorations;
409+
protected void setDecorations(List<Decoration> decorations) {
410+
this.decorations = decorations;
411+
for (Decoration decoration : decorations) {
412+
decoration.setRefreshLogEntryTableView(() -> refresh());
413+
}
414+
}
415+
402416
private void setSearchResult(SearchResult searchResult) {
403417
this.searchResult = searchResult;
418+
419+
List<LogEntry> logEntries = searchResult.getLogs();
420+
decorations.forEach(decoration -> decoration.setLogEntries(logEntries));
421+
404422
Platform.runLater(() -> {
405423
hitCountProperty.set(searchResult.getHitCount());
406424
pageCountProperty.set(1 + (hitCountProperty.get() / pageSizeProperty.get()));
@@ -417,12 +435,19 @@ public String getQuery() {
417435
return query.getValue().getQuery();
418436
}
419437

420-
private void refresh() {
438+
private synchronized void refresh() {
421439
if (this.searchResult != null) {
422440
List<TableViewListItem> selectedLogEntries = new ArrayList<>(tableView.getSelectionModel().getSelectedItems());
423-
ObservableList<TableViewListItem> logsList = FXCollections.observableArrayList();
424-
logsList.addAll(searchResult.getLogs().stream().map(le -> new TableViewListItem(le, showDetails.get())).toList());
441+
442+
List<LogEntry> logEntries = searchResult.getLogs();
443+
logEntries.sort((o1, o2) -> -(o1.getCreatedDate().compareTo(o2.getCreatedDate())));
444+
445+
boolean showDetailsBoolean = showDetails.get();
446+
var logs = logEntries.stream().map(le -> new TableViewListItem(le, showDetailsBoolean)).toList();
447+
448+
ObservableList<TableViewListItem> logsList = FXCollections.observableArrayList(logs);
425449
tableView.setItems(logsList);
450+
426451
// This will ensure that selected entries stay selected after the list has been
427452
// updated from the search result.
428453
for (TableViewListItem selectedItem : selectedLogEntries) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.phoebus.logbook.olog.ui.spi;
2+
3+
import javafx.scene.Node;
4+
import org.phoebus.logbook.LogEntry;
5+
6+
import java.util.List;
7+
8+
public interface Decoration {
9+
void setLogEntries(List<LogEntry> logEntries);
10+
11+
void setRefreshLogEntryTableView(Runnable refreshLogEntryTableView);
12+
13+
Node createDecorationForLogEntryCell(LogEntry logEntry);
14+
}

app/logbook/olog/ui/src/main/resources/org/phoebus/logbook/olog/ui/AdvancedSearchView.fxml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@
121121
</GridPane.margin>
122122
</Label>
123123
<TextField fx:id="attachmentTypes" GridPane.columnSpan="2" GridPane.rowIndex="18" />
124-
125124
</children>
126125
</GridPane>
127126
</children>

0 commit comments

Comments
 (0)