use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntryTableDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
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());
}
} 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).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 FieldsViewController method setupLogbooksAndTags.
/**
* Retrieves logbooks and tags from service and populates all the data structures that depend
* on the result. The call to the remote service is asynchronous.
*/
private void setupLogbooksAndTags() {
JobManager.schedule("Fetch Logbooks and Tags", monitor -> {
LogClient logClient = LogService.getInstance().getLogFactories().get(LogbookPreferences.logbook_factory).getLogClient();
availableLogbooks = logClient.listLogbooks();
availableLogbooksAsStringList = FXCollections.observableArrayList(availableLogbooks.stream().map(logbook -> logbook.getName()).collect(Collectors.toList()));
Collections.sort(availableLogbooksAsStringList);
List<String> preSelectedLogbooks = logEntry.getLogbooks().stream().map(l -> l.getName()).collect(Collectors.toList());
List<String> defaultLogbooks = Arrays.asList(LogbookUIPreferences.default_logbooks);
availableLogbooksAsStringList.forEach(logbook -> {
CheckBox checkBox = new CheckBox(logbook);
CustomMenuItem newLogbook = new CustomMenuItem(checkBox);
newLogbook.setHideOnClick(false);
checkBox.setOnAction(e -> {
CheckBox source = (CheckBox) e.getSource();
String text = source.getText();
if (source.isSelected()) {
selectedLogbooks.add(text);
} else {
selectedLogbooks.remove(text);
}
});
if (!preSelectedLogbooks.isEmpty() && preSelectedLogbooks.contains(logbook)) {
checkBox.setSelected(preSelectedLogbooks.contains(logbook));
selectedLogbooks.add(logbook);
} else if (defaultLogbooks.contains(logbook)) {
checkBox.setSelected(defaultLogbooks.contains(logbook));
selectedLogbooks.add(logbook);
}
logbookDropDown.getItems().add(newLogbook);
});
availableTags = logClient.listTags();
availableTagsAsStringList = FXCollections.observableArrayList(availableTags.stream().map(tag -> tag.getName()).collect(Collectors.toList()));
Collections.sort(availableLogbooksAsStringList);
List<String> preSelectedTags = logEntry.getTags().stream().map(t -> t.getName()).collect(Collectors.toList());
availableTagsAsStringList.forEach(tag -> {
CheckBox checkBox = new CheckBox(tag);
CustomMenuItem newTag = new CustomMenuItem(checkBox);
newTag.setHideOnClick(false);
checkBox.setOnAction(e -> {
CheckBox source = (CheckBox) e.getSource();
String text = source.getText();
if (source.isSelected()) {
selectedTags.add(text);
} else {
selectedTags.remove(text);
}
});
checkBox.setSelected(preSelectedTags.contains(tag));
if (preSelectedTags.contains(tag)) {
selectedTags.add(tag);
}
tagDropDown.getItems().add(newTag);
});
});
}
use of org.phoebus.logbook.Tag in project phoebus by ControlSystemStudio.
the class LogEntrySearchDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
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());
}
} 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"));
String path = "C:\\Users\\Kunal Shroff\\Pictures\\screenshot-git\\log-att";
File folder = new File(path);
List<File> listOfFiles = Arrays.asList(folder.listFiles());
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).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 LogEntryCalenderDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(this.getClass().getResource("LogEntryCalenderView.fxml"));
loader.setControllerFactory(clazz -> {
try {
if (clazz.isAssignableFrom(LogEntryCalenderViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
} else if (clazz.isAssignableFrom(AdvancedSearchViewController.class)) {
return clazz.getConstructor(LogClient.class).newInstance(getLogClient());
}
} catch (Exception e) {
Logger.getLogger(LogEntryEditorStage.class.getName()).log(Level.SEVERE, "Failed to construct controller for log calendar view", e);
}
return null;
});
loader.load();
LogEntryCalenderViewController 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().minusSeconds(i * 60 * 60)).inLogbooks(logbooks).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 LogEntryDisplayDemo method start.
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("LogEntry Display demo");
BorderPane root;
ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
FXMLLoader loader = new FXMLLoader();
loader.setResources(resourceBundle);
loader.setLocation(this.getClass().getResource("LogEntryDisplay.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(LogClient.class).newInstance(getLogClient());
} 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();
LogEntryDisplayController 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(() -> {
OlogLog ologLog = new OlogLog(1L);
ologLog.setDescription("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.");
ologLog.setCreatedDate(Instant.now());
runLater(() -> {
controller.setLogEntry(ologLog);
});
}, 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"));
LogEntry logEntry = controller.getLogEntry();
runLater(() -> {
OlogLog anotherLog = new OlogLog(2L);
anotherLog.setDescription(controller.getLogEntry().getDescription());
anotherLog.setCreatedDate(controller.getLogEntry().getCreatedDate());
anotherLog.setTags(tags);
anotherLog.setLogbooks(logbooks);
controller.setLogEntry(anotherLog);
});
}, 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"));
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);
runLater(() -> {
OlogLog ologLog = new OlogLog(3L);
ologLog.setCreatedDate(Instant.now());
ologLog.setTitle("A report on the orbit studies");
ologLog.setDescription("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.");
ologLog.setTags(new HashSet(Arrays.asList(TagImpl.of("Orbit", "active"), TagImpl.of("Studies", "active"))));
ologLog.setLogbooks(new HashSet(Arrays.asList(LogbookImpl.of("Operations", "active"))));
ologLog.setProperties(Arrays.asList(track, experimentProperty));
List<Attachment> attachments = new ArrayList<>();
OlogAttachment attachment1 = new OlogAttachment("image_1.png");
attachment1.setFileName("image_1.png");
attachment1.setContentType("image");
OlogAttachment attachment2 = new OlogAttachment("file_phoebus.txt");
attachment2.setFileName("file_phoebus.txt");
attachment2.setContentType("text");
attachments.add(attachment1);
attachments.add(attachment2);
ologLog.setAttachments(attachments);
controller.setLogEntry(ologLog);
});
}, 2, TimeUnit.SECONDS);
}
Aggregations