use of org.phoebus.logbook.ui.LogbookQueryUtil.Keys in project phoebus by ControlSystemStudio.
the class LogEntryCalenderViewController method initialize.
@FXML
public void initialize() {
resize.setText("<");
agenda = new Agenda();
agenda.setEditAppointmentCallback(new Callback<Agenda.Appointment, Void>() {
@Override
public Void call(Appointment appointment) {
return null;
}
});
agenda.setActionCallback((appointment) -> {
// show detailed view
try {
if (map != null) {
final Stage dialog = new Stage();
dialog.initModality(Modality.NONE);
logEntryControl = new LogEntryControl();
logEntryControl.setLog(map.get(appointment));
Scene dialogScene = new Scene(logEntryControl, 300, 200);
dialog.setScene(dialogScene);
dialog.show();
}
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to show details for : " + appointment.getSummary(), e);
}
return null;
});
agenda.allowDraggingProperty().set(false);
agenda.allowResizeProperty().set(false);
appointmentGroupMap = agenda.appointmentGroups().stream().collect(Collectors.toMap(AppointmentGroup::getDescription, Function.identity()));
try {
String styleSheetResource = LogbookUiPreferences.calendar_view_item_stylesheet;
agenda.getStylesheets().add(this.getClass().getResource(styleSheetResource).toString());
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to set css style", e);
}
AnchorPane.setTopAnchor(agenda, 6.0);
AnchorPane.setBottomAnchor(agenda, 6.0);
AnchorPane.setLeftAnchor(agenda, 6.0);
AnchorPane.setRightAnchor(agenda, 6.0);
agendaPane.getChildren().add(agenda);
searchParameters = FXCollections.<Keys, String>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);
searchParameters.addListener(new MapChangeListener<Keys, String>() {
@Override
public void onChanged(Change<? extends Keys, ? extends String> change) {
Platform.runLater(() -> {
query.setText(searchParameters.entrySet().stream().sorted(Map.Entry.comparingByKey()).map((e) -> {
return e.getKey().getName().trim() + "=" + e.getValue().trim();
}).collect(Collectors.joining("&")));
});
}
});
query.setText(searchParameters.entrySet().stream().sorted(Map.Entry.comparingByKey()).map((e) -> {
return e.getKey().getName().trim() + "=" + e.getValue().trim();
}).collect(Collectors.joining("&")));
VBox timeBox = new VBox();
TimeRelativeIntervalPane timeSelectionPane = new TimeRelativeIntervalPane(TEMPORAL_AMOUNTS_AND_NOW);
// TODO needs to be initialized from the values in the search parameters
TimeRelativeInterval initial = TimeRelativeInterval.of(java.time.Duration.ofHours(8), java.time.Duration.ZERO);
timeSelectionPane.setInterval(initial);
HBox hbox = new HBox();
hbox.setSpacing(5);
hbox.setAlignment(Pos.CENTER_RIGHT);
Button apply = new Button();
apply.setText("Apply");
apply.setPrefWidth(80);
apply.setOnAction((event) -> {
Platform.runLater(() -> {
TimeRelativeInterval interval = timeSelectionPane.getInterval();
if (interval.isStartAbsolute()) {
searchParameters.put(Keys.STARTTIME, TimestampFormats.MILLI_FORMAT.format(interval.getAbsoluteStart().get()));
} else {
searchParameters.put(Keys.STARTTIME, TimeParser.format(interval.getRelativeStart().get()));
}
if (interval.isEndAbsolute()) {
searchParameters.put(Keys.ENDTIME, TimestampFormats.MILLI_FORMAT.format(interval.getAbsoluteEnd().get()));
} else {
searchParameters.put(Keys.ENDTIME, TimeParser.format(interval.getRelativeEnd().get()));
}
});
});
Button cancel = new Button();
cancel.setText("Cancel");
cancel.setPrefWidth(80);
hbox.getChildren().addAll(apply, cancel);
timeBox.getChildren().addAll(timeSelectionPane, hbox);
// Bind ENTER key press to search
query.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
if (event.getCode() == KeyCode.ENTER) {
search();
}
});
}
use of org.phoebus.logbook.ui.LogbookQueryUtil.Keys 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();
}
});
}
Aggregations