Search in sources :

Example 1 with LogEntryModel

use of org.phoebus.logbook.ui.write.LogEntryModel in project phoebus by ControlSystemStudio.

the class SendLogbookAction method submitLogEntry.

private void submitLogEntry(final Node parent, final String title, final String body, final File image_file) {
    LogEntryBuilder logEntryBuilder = new LogEntryBuilder();
    if (title != null)
        logEntryBuilder.title(title);
    if (body != null)
        logEntryBuilder.appendDescription(body);
    if (image_file != null) {
        try {
            final Attachment attachment = AttachmentImpl.of(image_file, "image", false);
            logEntryBuilder.attach(attachment);
        } catch (FileNotFoundException ex) {
            logger.log(Level.WARNING, "Cannot attach " + image_file, ex);
        }
    }
    final LogEntryModel model = new LogEntryModel(logEntryBuilder.createdDate(Instant.now()).build());
    new LogEntryEditorStage(parent, model, null).show();
}
Also used : LogEntryModel(org.phoebus.logbook.ui.write.LogEntryModel) FileNotFoundException(java.io.FileNotFoundException) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Attachment(org.phoebus.logbook.Attachment) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage)

Example 2 with LogEntryModel

use of org.phoebus.logbook.ui.write.LogEntryModel 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();
        }
    });
}
Also used : Button(javafx.scene.control.Button) LogEntry(org.phoebus.logbook.LogEntry) Arrays(java.util.Arrays) ColumnConstraints(javafx.scene.layout.ColumnConstraints) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FXCollections(javafx.collections.FXCollections) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) AttachmentsViewController(org.phoebus.logbook.ui.write.AttachmentsViewController) TimeParser(org.phoebus.util.time.TimeParser) FXMLLoader(javafx.fxml.FXMLLoader) Map(java.util.Map) KeyValue(javafx.animation.KeyValue) TableView(javafx.scene.control.TableView) GridPane(javafx.scene.layout.GridPane) SECONDS_FORMAT(org.phoebus.util.time.TimestampFormats.SECONDS_FORMAT) KeyCode(javafx.scene.input.KeyCode) Logbook(org.phoebus.logbook.Logbook) ImageCache(org.phoebus.ui.javafx.ImageCache) KeyFrame(javafx.animation.KeyFrame) TextField(javafx.scene.control.TextField) Label(javafx.scene.control.Label) Node(javafx.scene.Node) MapChangeListener(javafx.collections.MapChangeListener) Tag(org.phoebus.logbook.Tag) Timeline(javafx.animation.Timeline) IOException(java.io.IOException) KeyEvent(javafx.scene.input.KeyEvent) LogEntryModel(org.phoebus.logbook.ui.write.LogEntryModel) ObservableMap(javafx.collections.ObservableMap) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) Separator(javafx.scene.control.Separator) Text(javafx.scene.text.Text) Priority(javafx.scene.layout.Priority) List(java.util.List) Duration(javafx.util.Duration) Keys(org.phoebus.logbook.ui.LogbookQueryUtil.Keys) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ImageView(javafx.scene.image.ImageView) Entry(java.util.Map.Entry) ObservableList(javafx.collections.ObservableList) LogClient(org.phoebus.logbook.LogClient) Image(javafx.scene.image.Image) GridPane(javafx.scene.layout.GridPane) ColumnConstraints(javafx.scene.layout.ColumnConstraints) LogEntryModel(org.phoebus.logbook.ui.write.LogEntryModel) Node(javafx.scene.Node) Label(javafx.scene.control.Label) AttachmentsViewController(org.phoebus.logbook.ui.write.AttachmentsViewController) Text(javafx.scene.text.Text) IOException(java.io.IOException) FXMLLoader(javafx.fxml.FXMLLoader) IOException(java.io.IOException) Logbook(org.phoebus.logbook.Logbook) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) TableCell(javafx.scene.control.TableCell) Keys(org.phoebus.logbook.ui.LogbookQueryUtil.Keys) ImageView(javafx.scene.image.ImageView) Tag(org.phoebus.logbook.Tag) LogEntry(org.phoebus.logbook.LogEntry) Separator(javafx.scene.control.Separator) FXML(javafx.fxml.FXML)

Example 3 with LogEntryModel

use of org.phoebus.logbook.ui.write.LogEntryModel in project phoebus by ControlSystemStudio.

the class PACEInstance method doSaveChanges.

private void doSaveChanges(final JobMonitor monitor) {
    final String text = createElogText();
    final LogEntryBuilder builder = new LogEntryBuilder();
    builder.title(MessageFormat.format(Messages.ELogTitleFmt, model.getTitle()));
    builder.appendDescription(text);
    final LogEntry entry = builder.createdDate(Instant.now()).build();
    LogEntryModel logEntryModel = new LogEntryModel(entry);
    new LogEntryEditorStage(gui, logEntryModel, logEntry -> {
        if (logEntry != null) {
            final String user = logEntryModel.getUsername();
            try {
                // Change PVs
                model.saveUserValues(user);
                // On success, clear user values
                model.clearUserValues();
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Save failed", ex);
                // At least some saves failed, to revert
                try {
                    model.revertOriginalValues();
                } catch (Exception ex2) {
                    // Since saving didn't work, restoral will also fail.
                    // Hopefully those initial PVs that did get updated will
                    // also be restored...
                    logger.log(Level.WARNING, "Restore failed", ex2);
                }
                ExceptionDetailsErrorDialog.openError(gui, Messages.SaveError, Messages.PVWriteError, ex);
            }
        }
    }).show();
}
Also used : LogEntry(org.phoebus.logbook.LogEntry) JobManager(org.phoebus.framework.jobs.JobManager) Cell(org.csstudio.display.pace.model.Cell) AppInstance(org.phoebus.framework.spi.AppInstance) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) JobMonitor(org.phoebus.framework.jobs.JobMonitor) HashMap(java.util.HashMap) Instance(org.csstudio.display.pace.model.Instance) AppDescriptor(org.phoebus.framework.spi.AppDescriptor) LogEntryModel(org.phoebus.logbook.ui.write.LogEntryModel) Instant(java.time.Instant) MessageFormat(java.text.MessageFormat) Level(java.util.logging.Level) PACEApp.logger(org.csstudio.display.pace.PACEApp.logger) Platform(javafx.application.Platform) Model(org.csstudio.display.pace.model.Model) Map(java.util.Map) URI(java.net.URI) DockPane(org.phoebus.ui.docking.DockPane) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) ExceptionDetailsErrorDialog(org.phoebus.ui.dialog.ExceptionDetailsErrorDialog) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) GUI(org.csstudio.display.pace.gui.GUI) LogEntryModel(org.phoebus.logbook.ui.write.LogEntryModel) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) LogEntry(org.phoebus.logbook.LogEntry)

Aggregations

LogEntryModel (org.phoebus.logbook.ui.write.LogEntryModel)3 Map (java.util.Map)2 Level (java.util.logging.Level)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URI (java.net.URI)1 MessageFormat (java.text.MessageFormat)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Entry (java.util.Map.Entry)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1 KeyFrame (javafx.animation.KeyFrame)1 KeyValue (javafx.animation.KeyValue)1 Timeline (javafx.animation.Timeline)1 Platform (javafx.application.Platform)1