use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntryTableDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
FXMLLoader loader = new FXMLLoader();
loader.setResources(resourceBundle);
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));
loader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
return clazz.getConstructor(String.class).newInstance(getLogClient().getServiceUrl());
} else if (clazz.isAssignableFrom(LogPropertiesController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(AttachmentsPreviewController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(LogEntryCellController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(MergedLogEntryDisplayController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
return clazz.getConstructor(String.class).newInstance(getLogClient().getServiceUrl());
} else {
throw new RuntimeException("No controller for class " + clazz.getName());
}
} catch (Exception e) {
Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
}
return null;
});
loader.load();
LogEntryTableViewController controller = loader.getController();
Parent root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
List<LogEntry> logs = new ArrayList<LogEntry>();
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
File imageFile = new File(this.getClass().getClassLoader().getResource("image_1.png").toURI());
File textFile = new File(this.getClass().getClassLoader().getResource("file_phoebus.txt").toURI());
List<File> listOfFiles = Arrays.asList(imageFile, textFile);
Map<String, String> tracAttributes = new HashMap<>();
tracAttributes.put("id", "1234");
tracAttributes.put("URL", "https://trac.epics.org/tickets/1234");
Property track = PropertyImpl.of("Track", tracAttributes);
Map<String, String> experimentAttributes = new HashMap<>();
experimentAttributes.put("id", "1234");
experimentAttributes.put("type", "XPD xray diffraction");
experimentAttributes.put("scan-id", "6789");
Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);
for (int i = 0; i < 10; i++) {
Thread.sleep(500);
LogEntryBuilder lb = LogEntryBuilder.log().owner("Owner").title("log " + i).description("First line for log " + i).createdDate(Instant.now()).inLogbooks(logbooks).id(Long.valueOf(i)).withTags(tags);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i; j++) {
sb.append("Some additional log text");
}
lb.appendDescription(sb.toString());
if (i % 2 != 0) {
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
lb.appendProperty(experimentProperty);
lb.appendProperty(track);
}
logs.add(lb.build());
}
controller.setLogs(logs);
}
use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntrySearchDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
FXMLLoader loader = new FXMLLoader();
loader.setResources(resourceBundle);
loader.setLocation(this.getClass().getResource("LogEntryTableView.fxml"));
loader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(LogEntryTableViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(LogPropertiesController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(AttachmentsPreviewController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(LogEntryCellController.class)) {
return clazz.getConstructor().newInstance();
} else if (clazz.isAssignableFrom(LogEntryDisplayController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(MergedLogEntryDisplayController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(SingleLogEntryDisplayController.class)) {
return clazz.getConstructor(String.class).newInstance(getLogClient().getServiceUrl());
} else {
throw new RuntimeException("No controller for class " + clazz.getName());
}
} catch (Exception e) {
Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
}
return null;
});
loader.load();
LogEntryTableViewController controller = loader.getController();
Parent root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
List<LogEntry> logs = new ArrayList<LogEntry>();
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
File imageFile = new File(this.getClass().getClassLoader().getResource("image_1.png").toURI());
File textFile = new File(this.getClass().getClassLoader().getResource("file_phoebus.txt").toURI());
List<File> listOfFiles = Arrays.asList(imageFile, textFile);
for (int i = 0; i < 10; i++) {
LogEntryBuilder lb = LogEntryBuilder.log().owner("Owner").title("log " + i).description("First line for log " + i).createdDate(Instant.now()).inLogbooks(logbooks).id(Long.valueOf(i)).withTags(tags);
StringBuilder sb = new StringBuilder();
for (int j = 0; j < i; j++) {
sb.append("Some additional log text");
}
lb.appendDescription(sb.toString());
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
logs.add(lb.build());
}
controller.setLogs(logs);
}
use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntryTableViewController method initialize.
@FXML
public void initialize() {
resize.setText("<");
searchParameters = FXCollections.observableHashMap();
searchParameters.put(Keys.SEARCH, "*");
searchParameters.put(Keys.STARTTIME, TimeParser.format(java.time.Duration.ofHours(8)));
searchParameters.put(Keys.ENDTIME, TimeParser.format(java.time.Duration.ZERO));
advancedSearchViewController.setSearchParameters(searchParameters);
query.setText(searchParameters.entrySet().stream().sorted(Map.Entry.comparingByKey()).map((e) -> e.getKey().getName().trim() + "=" + e.getValue().trim()).collect(Collectors.joining("&")));
searchParameters.addListener((MapChangeListener<Keys, String>) change -> query.setText(searchParameters.entrySet().stream().sorted(Entry.comparingByKey()).map((e) -> e.getKey().getName().trim() + "=" + e.getValue().trim()).collect(Collectors.joining("&"))));
// The display table.
tableView.getColumns().clear();
tableView.setEditable(false);
timeOwnerCol = new TableColumn<>("Time");
descriptionCol = new TableColumn<>("Log");
metaCol = new TableColumn<>("Logbook/Tags");
timeOwnerCol.setMaxWidth(1f * Integer.MAX_VALUE * 25);
timeOwnerCol.setCellValueFactory(col -> new SimpleObjectProperty(col.getValue()));
timeOwnerCol.setCellFactory(col -> {
final GridPane pane = new GridPane();
final Label timeText = new Label();
timeText.setStyle("-fx-font-weight: bold");
final Label ownerText = new Label();
pane.addColumn(0, timeText, ownerText);
return new TableCell<>() {
@Override
public void updateItem(LogEntry logEntry, boolean empty) {
super.updateItem(logEntry, empty);
if (empty) {
setGraphic(null);
} else {
if (logEntry.getCreatedDate() != null) {
timeText.setText(SECONDS_FORMAT.format(logEntry.getCreatedDate()));
}
ownerText.setText(logEntry.getOwner());
setGraphic(pane);
}
}
};
});
descriptionCol.setMaxWidth(1f * Integer.MAX_VALUE * 50);
descriptionCol.setCellValueFactory(col -> new SimpleObjectProperty(col.getValue()));
descriptionCol.setCellFactory(col -> {
final GridPane pane = new GridPane();
final Label titleText = new Label();
titleText.setStyle("-fx-font-weight: bold");
final Text descriptionText = new Text();
descriptionText.wrappingWidthProperty().bind(descriptionCol.widthProperty());
Node parent = topLevelNode.getScene().getRoot();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("write/AttachmentsView.fxml"));
fxmlLoader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(AttachmentsViewController.class)) {
AttachmentsViewController attachmentsViewController = (AttachmentsViewController) clazz.getConstructor(Node.class, Boolean.class).newInstance(parent, false);
return attachmentsViewController;
}
} catch (Exception e) {
Logger.getLogger(LogEntryTableViewController.class.getName()).log(Level.SEVERE, "Failed to construct controller for attachments view", e);
}
return null;
});
try {
Node node = fxmlLoader.load();
pane.addColumn(0, titleText, descriptionText, node);
} catch (IOException e) {
Logger.getLogger(LogEntryTableViewController.class.getName()).log(Level.WARNING, "Unable to load fxml for attachments view", e);
}
ColumnConstraints cc = new ColumnConstraints();
cc.setHgrow(Priority.ALWAYS);
pane.getColumnConstraints().add(cc);
return new TableCell<>() {
@Override
public void updateItem(LogEntry logEntry, boolean empty) {
super.updateItem(logEntry, empty);
if (empty) {
setGraphic(null);
} else {
if (logEntry.getTitle() == null || logEntry.getTitle().isEmpty()) {
titleText.setVisible(false);
} else {
titleText.setVisible(true);
titleText.setText(logEntry.getTitle());
}
descriptionText.setText(logEntry.getDescription());
AttachmentsViewController controller = fxmlLoader.getController();
LogEntryModel model = new LogEntryModel(logEntry);
controller.setImages(model.getImages());
controller.setFiles(model.getFiles());
setGraphic(pane);
}
}
};
});
metaCol.setMaxWidth(1f * Integer.MAX_VALUE * 25);
metaCol.setCellValueFactory(col -> new SimpleObjectProperty(col.getValue()));
metaCol.setCellFactory(col -> {
final GridPane pane = new GridPane();
final Label logbooks = new Label();
final Separator seperator = new Separator();
final Label tags = new Label();
pane.addColumn(0, logbooks, seperator, tags);
return new TableCell<>() {
@Override
public void updateItem(LogEntry logEntry, boolean empty) {
super.updateItem(logEntry, empty);
if (empty) {
setGraphic(null);
} else {
logbooks.setText(logEntry.getLogbooks().stream().map(Logbook::getName).collect(Collectors.joining(System.lineSeparator())));
logbooks.setGraphic(new ImageView(logbook));
tags.setText(logEntry.getTags().stream().map(Tag::getName).collect(Collectors.joining(System.lineSeparator())));
tags.setGraphic(new ImageView(tag));
setGraphic(pane);
}
}
};
});
tableView.getColumns().add(timeOwnerCol);
tableView.getColumns().add(descriptionCol);
tableView.getColumns().add(metaCol);
// Bind ENTER key press to search
query.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
search();
}
});
}
use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class SingleLogEntryDisplayController method setLogEntry.
public void setLogEntry(LogEntry logEntry) {
this.logEntry = logEntry;
// Always expand properties pane.
attachmentsPane.setExpanded(true);
// Get the attachments from service
fetchAttachments();
// attachmentsPreviewController
// .setAttachments(FXCollections.observableArrayList(logEntry.getAttachments()));
List<String> hiddenPropertiesNames = Arrays.asList(LogbookUIPreferences.hidden_properties);
// Remove the hidden properties
List<Property> propertiesToShow = logEntry.getProperties().stream().filter(property -> !hiddenPropertiesNames.contains(property.getName())).collect(Collectors.toList());
propertiesController.setProperties(propertiesToShow);
logTime.setText(SECONDS_FORMAT.format(logEntry.getCreatedDate()));
logOwner.setText(logEntry.getOwner());
logTitle.setWrapText(true);
logTitle.setText(logEntry.getTitle());
// Content is defined by the source (default) or description field. If both are null
// or empty, do no load any content to the WebView.
WebEngine webEngine = logDescription.getEngine();
webEngine.setUserStyleSheetLocation(getClass().getResource("/detail_log_webview.css").toExternalForm());
if (logEntry.getSource() != null) {
webEngine.loadContent(getFullHtml(logEntry.getSource()));
} else if (logEntry.getDescription() != null) {
webEngine.loadContent(getFullHtml(logEntry.getDescription()));
}
ObservableList<String> logbookList = FXCollections.observableArrayList();
logbookList.addAll(logEntry.getLogbooks().stream().map(Logbook::getName).collect(Collectors.toList()));
ObservableList<String> tagList = FXCollections.observableArrayList();
tagList.addAll(logEntry.getTags().stream().map(Tag::getName).collect(Collectors.toList()));
if (!logEntry.getLogbooks().isEmpty()) {
logbooks.setWrapText(false);
logbooks.setText(logEntry.getLogbooks().stream().map(Logbook::getName).collect(Collectors.joining(",")));
}
if (!logEntry.getTags().isEmpty()) {
tags.setText(logEntry.getTags().stream().map(Tag::getName).collect(Collectors.joining(",")));
} else {
tags.setText(null);
}
logEntryId.setText(Long.toString(logEntry.getId()));
level.setText(logEntry.getLevel());
}
use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntryDisplayDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("LogEntry Display demo");
VBox root = new VBox();
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("LogEntryDisplay.fxml"));
loader.setRoot(root);
loader.setController(new LogEntryController());
loader.load();
LogEntryController controller = loader.getController();
root = loader.getRoot();
primaryStage.setScene(new Scene(root, 400, 400));
primaryStage.show();
// Every few seconds add a new log entry
ex.schedule(() -> {
LogEntry log = LogEntryBuilder.log().description("Fast correctors for the vertical orbit have glitched to near saturation. Archiver shows there have been several episodes the past 24 hrs. Appears that FOFB in vertical plane might have momentary bad BPM reading.").createdDate(Instant.now()).build();
runLater(() -> {
controller.setLogEntry(log);
});
}, 2, TimeUnit.SECONDS);
ex.schedule(() -> {
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
runLater(() -> {
controller.setLogEntry(LogEntryBuilder.log(controller.getLogEntry()).inLogbooks(logbooks).withTags(tags).build());
});
}, 2, TimeUnit.SECONDS);
ex.schedule(() -> {
Set<Tag> tags = new HashSet<Tag>();
tags.add(TagImpl.of("tag1", "active"));
tags.add(TagImpl.of("tag2", "active"));
Set<Logbook> logbooks = new HashSet<Logbook>();
logbooks.add(LogbookImpl.of("logbook1", "active"));
logbooks.add(LogbookImpl.of("logbook2", "active"));
String path = "C:\\Users\\Kunal Shroff\\Pictures\\screenshot-git\\log-att";
File folder = new File(path);
List<File> listOfFiles = Arrays.asList(folder.listFiles());
runLater(() -> {
LogEntryBuilder lb = LogEntryBuilder.log().createdDate(Instant.now()).description("Fast correctors for the vertical orbit have glitched to near saturation. Archiver shows there have been several episodes the past 24 hrs. Appears that FOFB in vertical plane might have momentary bad BPM reading.").withTags(new HashSet<Tag>(Arrays.asList(TagImpl.of("Orbit", "active"), TagImpl.of("Studies", "active")))).inLogbooks(new HashSet<Logbook>(Arrays.asList(LogbookImpl.of("Operations", "active"))));
listOfFiles.forEach(file -> {
try {
lb.attach(AttachmentImpl.of(file));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
controller.setLogEntry(lb.build());
});
}, 2, TimeUnit.SECONDS);
}
Aggregations