Search in sources :

Example 1 with Tag

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);
}
Also used : LogClient(org.phoebus.logbook.LogClient) Parent(javafx.scene.Parent) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) LogbookException(org.phoebus.logbook.LogbookException) FileNotFoundException(java.io.FileNotFoundException) Logbook(org.phoebus.logbook.Logbook) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Tag(org.phoebus.logbook.Tag) File(java.io.File) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet)

Example 2 with Tag

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);
        });
    });
}
Also used : Button(javafx.scene.control.Button) LogEntry(org.phoebus.logbook.LogEntry) Initializable(javafx.fxml.Initializable) JobManager(org.phoebus.framework.jobs.JobManager) Arrays(java.util.Arrays) URL(java.net.URL) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) VBox(javafx.scene.layout.VBox) Side(javafx.geometry.Side) CustomMenuItem(javafx.scene.control.CustomMenuItem) ComboBox(javafx.scene.control.ComboBox) ContextMenu(javafx.scene.control.ContextMenu) PhoebusApplication.logger(org.phoebus.ui.application.PhoebusApplication.logger) TextField(javafx.scene.control.TextField) Logbook(org.phoebus.logbook.Logbook) ImageCache(org.phoebus.ui.javafx.ImageCache) MenuItem(javafx.scene.control.MenuItem) SecureStore(org.phoebus.security.store.SecureStore) LogService(org.phoebus.logbook.LogService) Collection(java.util.Collection) Tag(org.phoebus.logbook.Tag) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Messages(org.phoebus.logbook.olog.ui.Messages) Platform(javafx.application.Platform) FXML(javafx.fxml.FXML) List(java.util.List) OlogProperties(org.phoebus.olog.es.api.OlogProperties) ToggleButton(javafx.scene.control.ToggleButton) ObservableList(javafx.collections.ObservableList) ScopedAuthenticationToken(org.phoebus.security.tokens.ScopedAuthenticationToken) TextArea(javafx.scene.control.TextArea) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) FXCollections(javafx.collections.FXCollections) LogbookUIPreferences(org.phoebus.logbook.olog.ui.LogbookUIPreferences) TimestampFormats(org.phoebus.util.time.TimestampFormats) Bindings(javafx.beans.binding.Bindings) Level(java.util.logging.Level) LogbookPreferences(org.phoebus.logbook.LogbookPreferences) ResourceBundle(java.util.ResourceBundle) PasswordField(javafx.scene.control.PasswordField) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) PhoebusApplication(org.phoebus.ui.application.PhoebusApplication) CheckBox(javafx.scene.control.CheckBox) ListSelectionDialog(org.phoebus.ui.dialog.ListSelectionDialog) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image) LogClient(org.phoebus.logbook.LogClient) Collections(java.util.Collections) LogClient(org.phoebus.logbook.LogClient) CheckBox(javafx.scene.control.CheckBox) CustomMenuItem(javafx.scene.control.CustomMenuItem)

Example 3 with Tag

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);
}
Also used : LogClient(org.phoebus.logbook.LogClient) Parent(javafx.scene.Parent) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LogEntryEditorStage(org.phoebus.logbook.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) LogbookException(org.phoebus.logbook.LogbookException) FileNotFoundException(java.io.FileNotFoundException) Logbook(org.phoebus.logbook.Logbook) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Tag(org.phoebus.logbook.Tag) File(java.io.File) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet)

Example 4 with Tag

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);
}
Also used : LogClient(org.phoebus.logbook.LogClient) Parent(javafx.scene.Parent) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) LogEntryEditorStage(org.phoebus.logbook.olog.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) LogbookException(org.phoebus.logbook.LogbookException) FileNotFoundException(java.io.FileNotFoundException) Logbook(org.phoebus.logbook.Logbook) LogEntryBuilder(org.phoebus.logbook.LogEntryImpl.LogEntryBuilder) Tag(org.phoebus.logbook.Tag) File(java.io.File) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet)

Example 5 with Tag

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);
}
Also used : BorderPane(javafx.scene.layout.BorderPane) LogClient(org.phoebus.logbook.LogClient) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) Attachment(org.phoebus.logbook.Attachment) OlogLog(org.phoebus.olog.es.api.model.OlogLog) FXMLLoader(javafx.fxml.FXMLLoader) Logbook(org.phoebus.logbook.Logbook) OlogAttachment(org.phoebus.olog.es.api.model.OlogAttachment) Property(org.phoebus.logbook.Property) LogEntry(org.phoebus.logbook.LogEntry) HashSet(java.util.HashSet) LogEntryEditorStage(org.phoebus.logbook.olog.ui.write.LogEntryEditorStage) Scene(javafx.scene.Scene) LogbookException(org.phoebus.logbook.LogbookException) ResourceBundle(java.util.ResourceBundle) Tag(org.phoebus.logbook.Tag)

Aggregations

Logbook (org.phoebus.logbook.Logbook)13 Tag (org.phoebus.logbook.Tag)13 LogEntry (org.phoebus.logbook.LogEntry)12 FXMLLoader (javafx.fxml.FXMLLoader)10 LogClient (org.phoebus.logbook.LogClient)10 HashSet (java.util.HashSet)9 Scene (javafx.scene.Scene)9 File (java.io.File)8 FileNotFoundException (java.io.FileNotFoundException)8 ArrayList (java.util.ArrayList)8 LogEntryBuilder (org.phoebus.logbook.LogEntryImpl.LogEntryBuilder)8 LogbookException (org.phoebus.logbook.LogbookException)8 Parent (javafx.scene.Parent)6 ResourceBundle (java.util.ResourceBundle)4 ImageView (javafx.scene.image.ImageView)4 LogEntryEditorStage (org.phoebus.logbook.olog.ui.write.LogEntryEditorStage)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Level (java.util.logging.Level)3 Collectors (java.util.stream.Collectors)3