Search in sources :

Example 16 with Property

use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.

the class LogPropertiesEditorDemo method getDummyLogClient.

private LogClient getDummyLogClient() {
    return new LogClient() {

        @Override
        public LogEntry set(LogEntry log) throws LogbookException {
            return null;
        }

        @Override
        public LogEntry getLog(Long logId) {
            return null;
        }

        @Override
        public Collection<Attachment> listAttachments(Long logId) {
            return null;
        }

        @Override
        public List<LogEntry> findLogs(Map<String, String> map) {
            return null;
        }

        @Override
        public Collection<LogEntry> listLogs() {
            return null;
        }

        @Override
        public Collection<Property> listProperties() {
            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);
            return Arrays.asList(experimentProperty);
        }
    };
}
Also used : LogClient(org.phoebus.logbook.LogClient) Attachment(org.phoebus.logbook.Attachment) Property(org.phoebus.logbook.Property) LogEntry(org.phoebus.logbook.LogEntry)

Example 17 with Property

use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.

the class LogPropertiesController method getProperties.

/**
 * @return The list of logentry properties
 */
public List<Property> getProperties() {
    List<Property> treeProperties = new ArrayList<>();
    treeTableView.getRoot().getChildren().stream().forEach(node -> {
        Map<String, String> att = node.getChildren().stream().map(TreeItem::getValue).collect(Collectors.toMap(PropertyTreeNode::getName, PropertyTreeNode::getValue));
        Property property = PropertyImpl.of(node.getValue().getName(), att);
        treeProperties.add(property);
    });
    return treeProperties;
}
Also used : ArrayList(java.util.ArrayList) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) Property(org.phoebus.logbook.Property) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Example 18 with Property

use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.

the class LogPropertiesDemo method start.

@Override
public void start(Stage primaryStage) throws IOException {
    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);
    Map<String, String> databrowser = new HashMap<>();
    databrowser.put("name", "vaccum db");
    databrowser.put("file", "sss");
    Property resourceProperty = PropertyImpl.of("Resource", databrowser);
    Map<String, String> empty = new HashMap<>();
    empty.put("name", null);
    empty.put("file", "");
    Property emptyProperty = PropertyImpl.of("empty", empty);
    ResourceBundle resourceBundle = NLS.getMessages(Messages.class);
    FXMLLoader loader = new FXMLLoader();
    loader.setResources(resourceBundle);
    loader.setLocation(this.getClass().getResource("LogProperties.fxml"));
    loader.load();
    final LogPropertiesController controller = loader.getController();
    Node tree = loader.getRoot();
    CheckBox checkBox = new CheckBox();
    BooleanProperty editable = new SimpleBooleanProperty();
    checkBox.selectedProperty().bindBidirectional(editable);
    controller.setProperties(Arrays.asList(track, experimentProperty, resourceProperty, emptyProperty));
    editable.addListener((observable, oldValue, newValue) -> {
        controller.setEditable(newValue);
    });
    VBox vbox = new VBox();
    vbox.getChildren().add(checkBox);
    vbox.getChildren().add(tree);
    vbox.setPrefHeight(Region.USE_COMPUTED_SIZE);
    Scene scene = new Scene(vbox, 400, 200);
    primaryStage.setScene(scene);
    primaryStage.show();
    primaryStage.setOnCloseRequest(v -> {
        controller.getProperties().stream().forEach(p -> {
            System.out.println(p.getName());
            p.getAttributes().entrySet().stream().forEach(e -> {
                System.out.println("     " + e.getKey() + " : " + e.getValue());
            });
        });
    });
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) HashMap(java.util.HashMap) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Node(javafx.scene.Node) Scene(javafx.scene.Scene) FXMLLoader(javafx.fxml.FXMLLoader) CheckBox(javafx.scene.control.CheckBox) ResourceBundle(java.util.ResourceBundle) Property(org.phoebus.logbook.Property) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) VBox(javafx.scene.layout.VBox)

Example 19 with Property

use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.

the class LogPropertiesController method initialize.

@FXML
public void initialize() {
    // Read the attribute types
    String url = LogbookUIPreferences.log_attribute_desc;
    if (url.isEmpty()) {
        final URL resource = getClass().getResource("log_property_attributes.properties");
        url = resource.toExternalForm();
    }
    try (InputStream input = new URL(url).openStream()) {
        Properties prop = new Properties();
        prop.load(input);
        prop.stringPropertyNames().stream().forEach((p) -> {
            attributeTypes.put(p.toLowerCase(), prop.getProperty(p).toLowerCase());
        });
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    // create the property trees
    name.setMaxWidth(1f * Integer.MAX_VALUE * 40);
    name.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<PropertyTreeNode, String>, ObservableValue<String>>() {

        public ObservableValue<String> call(TreeTableColumn.CellDataFeatures<PropertyTreeNode, String> p) {
            return p.getValue().getValue().nameProperty();
        }
    });
    value.setMaxWidth(1f * Integer.MAX_VALUE * 60);
    value.setCellValueFactory(new Callback<TreeTableColumn.CellDataFeatures<PropertyTreeNode, ?>, SimpleObjectProperty<PropertyTreeNode>>() {

        public SimpleObjectProperty<PropertyTreeNode> call(TreeTableColumn.CellDataFeatures<PropertyTreeNode, ?> p) {
            return p.getValue().getValue().nodeProperty();
        }
    });
    value.setEditable(editable.getValue());
    value.setCellFactory(new Callback<TreeTableColumn<PropertyTreeNode, Object>, TreeTableCell<PropertyTreeNode, Object>>() {

        @Override
        public TreeTableCell<PropertyTreeNode, Object> call(TreeTableColumn<PropertyTreeNode, Object> param) {
            return new TreeTableCell<>() {

                private TextField textField;

                @Override
                public void startEdit() {
                    super.startEdit();
                    if (textField == null) {
                        createTextField();
                    }
                    setText(null);
                    setGraphic(textField);
                    textField.selectAll();
                }

                @Override
                public void cancelEdit() {
                    super.cancelEdit();
                    setText(((PropertyTreeNode) getItem()).getValue());
                    setGraphic(getTreeTableRow().getGraphic());
                }

                @Override
                public void updateItem(Object item, boolean empty) {
                    super.updateItem(item, empty);
                    if (empty) {
                        setGraphic(null);
                    } else {
                        PropertyTreeNode propertyItem = ((PropertyTreeNode) item);
                        if (attributeTypes.containsKey(propertyItem.getFullQualifiedName().toLowerCase())) {
                            switch(attributeTypes.get(propertyItem.getFullQualifiedName().toLowerCase())) {
                                case "url":
                                    final String url = propertyItem.getValue();
                                    final URI uri = URI.create(url);
                                    final Hyperlink urlLink = new Hyperlink(propertyItem.getValue());
                                    // TODO open url in some webclient
                                    urlLink.setOnContextMenuRequested((e) -> {
                                        ContextMenu contextMenu = new ContextMenu();
                                        final List<AppResourceDescriptor> applications = ApplicationService.getApplications(uri);
                                        applications.forEach(app -> {
                                            MenuItem menuItem = new MenuItem(app.getDisplayName());
                                            menuItem.setGraphic(ImageCache.getImageView(app.getIconURL()));
                                            menuItem.setOnAction(actionEvent -> app.create(uri));
                                            contextMenu.getItems().add(menuItem);
                                        });
                                        contextMenu.getItems().add(new SeparatorMenuItem());
                                        MenuItem copyMenuItem = new MenuItem("copy", copy);
                                        copyMenuItem.setOnAction(event -> {
                                            final ClipboardContent content = new ClipboardContent();
                                            content.putString(uri.toString());
                                            Clipboard.getSystemClipboard().setContent(content);
                                        });
                                        contextMenu.getItems().add(copyMenuItem);
                                        urlLink.setContextMenu(contextMenu);
                                    });
                                    setGraphic(urlLink);
                                    break;
                                case "resource":
                                    final String resourceURL = propertyItem.getValue();
                                    final URI resource = URI.create(resourceURL);
                                    final Hyperlink resourceLink = new Hyperlink(resourceURL);
                                    setGraphic(resourceLink);
                                    // Open resource using the default application
                                    resourceLink.setOnAction((e) -> {
                                        final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
                                        if (!applications.isEmpty()) {
                                            applications.get(0).create(resource);
                                        }
                                    });
                                    resourceLink.setOnContextMenuRequested((e) -> {
                                        ContextMenu contextMenu = new ContextMenu();
                                        final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
                                        applications.forEach(app -> {
                                            MenuItem menuItem = new MenuItem(app.getDisplayName());
                                            menuItem.setGraphic(ImageCache.getImageView(app.getIconURL()));
                                            menuItem.setOnAction(actionEvent -> app.create(resource));
                                            contextMenu.getItems().add(menuItem);
                                        });
                                        contextMenu.getItems().add(new SeparatorMenuItem());
                                        MenuItem copyMenuItem = new MenuItem("copy", copy);
                                        copyMenuItem.setOnAction(event -> {
                                            final ClipboardContent content = new ClipboardContent();
                                            content.putString(resource.toString());
                                            Clipboard.getSystemClipboard().setContent(content);
                                        });
                                        contextMenu.getItems().add(copyMenuItem);
                                        resourceLink.setContextMenu(contextMenu);
                                    });
                                    break;
                                default:
                                    setGraphic(new Label(propertyItem.getValue()));
                            }
                        } else {
                            setGraphic(new Label(propertyItem.getValue()));
                        }
                    }
                }

                private void createTextField() {
                    textField = new TextField(getString());
                    textField.setOnKeyReleased((KeyEvent t) -> {
                        if (t.getCode() == KeyCode.ENTER) {
                            ((PropertyTreeNode) getItem()).setValue(textField.getText());
                            commitEdit(getItem());
                        } else if (t.getCode() == KeyCode.ESCAPE) {
                            cancelEdit();
                        }
                    });
                }

                private String getString() {
                    if (getItem() != null && ((PropertyTreeNode) getItem()).getValue() != null) {
                        return ((PropertyTreeNode) getItem()).getValue();
                    } else {
                        return "";
                    }
                }
            };
        }
    });
    editable.addListener((observable, oldValue, newValue) -> {
        value.setEditable(newValue);
    });
    // Hide the headers
    treeTableView.widthProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> ov, Number t, Number t1) {
            // Get the table header
            Pane header = (Pane) treeTableView.lookup("TableHeaderRow");
            if (header != null && header.isVisible()) {
                header.setMaxHeight(0);
                header.setMinHeight(0);
                header.setPrefHeight(0);
                header.setVisible(false);
                header.setManaged(false);
            }
        }
    });
}
Also used : java.util(java.util) javafx.scene.control(javafx.scene.control) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) URL(java.net.URL) Bindings(javafx.beans.binding.Bindings) ApplicationService(org.phoebus.framework.workbench.ApplicationService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Preferences(org.phoebus.ui.Preferences) Level(java.util.logging.Level) Property(org.phoebus.logbook.Property) ResourceParser(org.phoebus.framework.util.ResourceParser) SelectionService(org.phoebus.framework.selection.SelectionService) URI(java.net.URI) Callback(javafx.util.Callback) Pane(javafx.scene.layout.Pane) KeyCode(javafx.scene.input.KeyCode) ImageCache(org.phoebus.ui.javafx.ImageCache) ContextMenuService(org.phoebus.ui.application.ContextMenuService) IOException(java.io.IOException) KeyEvent(javafx.scene.input.KeyEvent) Preference(org.phoebus.framework.preferences.Preference) FileInputStream(java.io.FileInputStream) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) FXML(javafx.fxml.FXML) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Clipboard(javafx.scene.input.Clipboard) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) ContextMenuEntry(org.phoebus.ui.spi.ContextMenuEntry) ImageView(javafx.scene.image.ImageView) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) ObservableValue(javafx.beans.value.ObservableValue) PropertyImpl(org.phoebus.logbook.PropertyImpl) ClipboardContent(javafx.scene.input.ClipboardContent) ChangeListener(javafx.beans.value.ChangeListener) Image(javafx.scene.image.Image) InputStream(java.io.InputStream) ClipboardContent(javafx.scene.input.ClipboardContent) ObservableValue(javafx.beans.value.ObservableValue) URI(java.net.URI) URL(java.net.URL) KeyEvent(javafx.scene.input.KeyEvent) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Pane(javafx.scene.layout.Pane) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) FXML(javafx.fxml.FXML)

Example 20 with Property

use of org.phoebus.logbook.Property in project phoebus by ControlSystemStudio.

the class OlogPropertyTest method testHashCode.

@Test
public void testHashCode() {
    Property property1 = new OlogProperty("name1");
    Property property2 = new OlogProperty("name2");
    assertNotEquals(property1.hashCode(), property2.hashCode());
    property2 = new OlogProperty("name1");
    assertEquals(property1.hashCode(), property2.hashCode());
    assertNotEquals(property1.hashCode(), new Object().hashCode());
}
Also used : Property(org.phoebus.logbook.Property) Test(org.junit.Test)

Aggregations

Property (org.phoebus.logbook.Property)21 HashMap (java.util.HashMap)10 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)5 BooleanProperty (javafx.beans.property.BooleanProperty)5 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)5 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)5 FXMLLoader (javafx.fxml.FXMLLoader)5 Scene (javafx.scene.Scene)5 LogClient (org.phoebus.logbook.LogClient)5 LogEntry (org.phoebus.logbook.LogEntry)5 LogbookException (org.phoebus.logbook.LogbookException)5 VBox (javafx.scene.layout.VBox)4 IOException (java.io.IOException)3 ResourceBundle (java.util.ResourceBundle)3 Collectors (java.util.stream.Collectors)3 FXML (javafx.fxml.FXML)3 Logbook (org.phoebus.logbook.Logbook)3 Tag (org.phoebus.logbook.Tag)3 Arrays (java.util.Arrays)2