Search in sources :

Example 6 with AppResourceDescriptor

use of org.phoebus.framework.spi.AppResourceDescriptor in project phoebus by ControlSystemStudio.

the class FileBrowserController method createContextMenu.

@FXML
public void createContextMenu(ContextMenuEvent e) {
    final ObservableList<TreeItem<FileInfo>> selectedItems = treeView.selectionModelProperty().getValue().getSelectedItems();
    contextMenu.getItems().clear();
    if (selectedItems.isEmpty()) {
        // Create directory at root
        contextMenu.getItems().addAll(new CreateDirectoryAction(treeView, treeView.getRoot()));
        // Paste files at root
        if (Clipboard.getSystemClipboard().hasFiles())
            contextMenu.getItems().addAll(new PasteFiles(treeView, treeView.getRoot()));
    } else {
        // allMatch() would return true for empty, so only check if there are items
        if (selectedItems.stream().allMatch(item -> item.isLeaf()))
            contextMenu.getItems().add(open);
        // If just one entry selected, check if there are multiple apps from which to select
        if (selectedItems.size() == 1) {
            final File file = selectedItems.get(0).getValue().file;
            final URI resource = ResourceParser.getURI(file);
            final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
            if (applications.size() > 0) {
                openWith.getItems().clear();
                for (AppResourceDescriptor app : applications) {
                    final MenuItem open_app = new MenuItem(app.getDisplayName());
                    final URL icon_url = app.getIconURL();
                    if (icon_url != null)
                        open_app.setGraphic(new ImageView(icon_url.toExternalForm()));
                    open_app.setOnAction(event -> app.create(resource));
                    openWith.getItems().add(open_app);
                }
                contextMenu.getItems().add(openWith);
            }
            if (file.isDirectory()) {
                contextMenu.getItems().add(new SetBaseDirectory(file, this::setRoot));
                contextMenu.getItems().add(new SeparatorMenuItem());
            }
            SelectionService.getInstance().setSelection(this, Arrays.asList(file));
            List<ContextMenuEntry> supported = ContextMenuService.getInstance().listSupportedContextMenuEntries();
            supported.stream().forEach(action -> {
                MenuItem menuItem = new MenuItem(action.getName(), new ImageView(action.getIcon()));
                menuItem.setOnAction((ee) -> {
                    try {
                        action.call(SelectionService.getInstance().getSelection());
                    } catch (Exception ex) {
                        logger.log(Level.WARNING, "Failed to execute " + action.getName() + " from file browser.", ex);
                    }
                });
                contextMenu.getItems().add(menuItem);
            });
            if (!supported.isEmpty()) {
                contextMenu.getItems().add(new SeparatorMenuItem());
            }
        }
        contextMenu.getItems().add(new CopyPath(selectedItems));
        contextMenu.getItems().add(new SeparatorMenuItem());
    }
    if (selectedItems.size() >= 1) {
        final TreeItem<FileInfo> item = selectedItems.get(0);
        final boolean is_file = item.isLeaf();
        if (selectedItems.size() == 1) {
            if (is_file) {
                // Create directory within the _parent_
                contextMenu.getItems().addAll(new CreateDirectoryAction(treeView, item.getParent()));
                // Plain file can be duplicated, directory can't
                contextMenu.getItems().add(new DuplicateAction(treeView, item));
            } else
                // Within a directory, a new directory can be created
                contextMenu.getItems().addAll(new CreateDirectoryAction(treeView, item));
            contextMenu.getItems().addAll(new RenameAction(treeView, selectedItems.get(0)));
            if (Clipboard.getSystemClipboard().hasFiles())
                contextMenu.getItems().addAll(new PasteFiles(treeView, selectedItems.get(0)));
        }
        contextMenu.getItems().add(new DeleteAction(treeView, selectedItems));
        contextMenu.getItems().add(new SeparatorMenuItem());
        if (is_file)
            contextMenu.getItems().add(new RefreshAction(treeView, item.getParent()));
        else
            contextMenu.getItems().add(new RefreshAction(treeView, item));
    }
    if (selectedItems.size() == 1) {
        contextMenu.getItems().addAll(new PropertiesAction(treeView, selectedItems.get(0)));
    }
    contextMenu.show(treeView.getScene().getWindow(), e.getScreenX(), e.getScreenY());
}
Also used : TreeItem(javafx.scene.control.TreeItem) ContextMenuEntry(org.phoebus.ui.spi.ContextMenuEntry) URI(java.net.URI) URL(java.net.URL) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) ImageView(javafx.scene.image.ImageView) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) File(java.io.File) FXML(javafx.fxml.FXML)

Example 7 with AppResourceDescriptor

use of org.phoebus.framework.spi.AppResourceDescriptor in project phoebus by ControlSystemStudio.

the class DisplayNavigationViewController method createContextMenu.

private void createContextMenu(ContextMenuEvent e, final List<File> selectedItems, Control control) {
    contextMenu.getItems().clear();
    if (!selectedItems.isEmpty()) {
        open.setOnAction(event -> {
            selectedItems.forEach(item -> {
                openResource(item, null);
            });
        });
        copy.setOnAction(event -> {
            final ClipboardContent content = new ClipboardContent();
            content.putString(selectedItems.stream().map(f -> {
                return f.getPath();
            }).collect(Collectors.joining(System.getProperty("line.separator"))));
            Clipboard.getSystemClipboard().setContent(content);
        });
        contextMenu.getItems().add(copy);
        contextMenu.getItems().add(open);
    }
    // If just one entry selected, check if there are multiple apps from which to select
    if (selectedItems.size() == 1) {
        final File file = selectedItems.get(0);
        final URI resource = ResourceParser.getURI(file);
        final List<AppResourceDescriptor> applications = ApplicationService.getApplications(resource);
        if (applications.size() > 0) {
            openWith.getItems().clear();
            for (AppResourceDescriptor app : applications) {
                final MenuItem open_app = new MenuItem(app.getDisplayName());
                final URL icon_url = app.getIconURL();
                if (icon_url != null)
                    open_app.setGraphic(new ImageView(icon_url.toExternalForm()));
                open_app.setOnAction(event -> app.create(resource));
                openWith.getItems().add(open_app);
            }
            contextMenu.getItems().add(openWith);
        }
    }
    contextMenu.show(control.getScene().getWindow(), e.getScreenX(), e.getScreenY());
}
Also used : ClipboardContent(javafx.scene.input.ClipboardContent) MenuItem(javafx.scene.control.MenuItem) ImageView(javafx.scene.image.ImageView) File(java.io.File) URI(java.net.URI) URL(java.net.URL) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor)

Example 8 with AppResourceDescriptor

use of org.phoebus.framework.spi.AppResourceDescriptor in project phoebus by ControlSystemStudio.

the class ContextMenuSupport method fillMenu.

/**
 * Fill context menu with items for widget
 *
 * @param node
 * @param widget
 */
private void fillMenu(final Node node, final Widget widget) {
    final ObservableList<MenuItem> items = menu.getItems();
    items.setAll(new WidgetInfoAction(widget));
    // launch the info dialog for the entire OPI.
    try {
        Widget topWidget = widget.getTopDisplayModel();
        if (!topWidget.equals(widget)) {
            items.add(new SeparatorMenuItem());
            items.add(new WidgetInfoAction(widget.getTopDisplayModel()));
        }
    } catch (Exception exception) {
        logger.log(Level.WARNING, "Unable to get top display model", exception);
    }
    // Widget actions
    for (ActionInfo info : widget.propActions().getValue().getActions()) {
        if (info.getType() == ActionType.OPEN_DISPLAY) {
            final OpenDisplayActionInfo open_info = (OpenDisplayActionInfo) info;
            // Expand macros in action description
            String desc;
            try {
                desc = MacroHandler.replace(widget.getEffectiveMacros(), open_info.getDescription());
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Cannot expand macros in action description '" + open_info.getDescription() + "'", ex);
                desc = open_info.getDescription();
            }
            // Add the requested target as default
            final Target requestedTarget = open_info.getTarget();
            items.add(createMenuItem(widget, new OpenDisplayActionInfo(desc, open_info.getFile(), open_info.getMacros(), requestedTarget)));
            // Add variant for all the available Target types: Replace, new Tab, ...
            for (Target target : Target.values()) {
                if (target == Target.STANDALONE || target == requestedTarget)
                    continue;
                // Mention non-default targets in the description
                items.add(createMenuItem(widget, new OpenDisplayActionInfo(desc + " (" + target + ")", open_info.getFile(), open_info.getMacros(), target)));
            }
        } else
            items.add(createMenuItem(widget, info));
    }
    // Actions of the widget runtime
    final WidgetRuntime<Widget> runtime = RuntimeUtil.getRuntime(widget);
    if (runtime == null)
        throw new NullPointerException("Missing runtime for " + widget);
    for (RuntimeAction info : runtime.getRuntimeActions()) {
        // Load image for action from that action's class loader
        final ImageView icon = ImageCache.getImageView(info.getClass(), info.getIconPath());
        final MenuItem item = new MenuItem(info.getDescription(), icon);
        item.setOnAction(event -> info.run());
        items.add(item);
    }
    items.add(new SeparatorMenuItem());
    // Does widget have a PV name?
    final Optional<WidgetProperty<String>> name_prop = widget.checkProperty(CommonWidgetProperties.propPVName);
    List<ProcessVariable> processVariables;
    if (name_prop.isPresent()) {
        processVariables = List.of(new ProcessVariable(name_prop.get().getValue()));
    } else {
        // Add all PVs referenced by the widget.
        Collection<RuntimePV> runtimePvs = runtime.getPVs();
        processVariables = runtimePvs.stream().map(runtimePV -> new ProcessVariable(runtimePV.getName())).collect(Collectors.toList());
    }
    if (!processVariables.isEmpty()) {
        // Set the 'selection' to the PV of this widget
        SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, processVariables);
        // Add PV-based menu entries
        ContextMenuHelper.addSupportedEntries(node, menu);
        items.add(new SeparatorMenuItem());
    }
    // If toolbar is hidden, offer forward/backward navigation
    if (!instance.isToolbarVisible()) {
        boolean navigate = false;
        final DisplayNavigation navigation = instance.getNavigation();
        if (navigation.getBackwardDisplays().size() > 0) {
            final MenuItem item = new MenuItem(Messages.NavigateBack_TT, new ImageView(NavigationAction.backward));
            item.setOnAction(event -> instance.loadDisplayFile(navigation.goBackward(1)));
            items.add(item);
            navigate = true;
        }
        if (navigation.getForwardDisplays().size() > 0) {
            final MenuItem item = new MenuItem(Messages.NavigateForward_TT, new ImageView(NavigationAction.forward));
            item.setOnAction(event -> instance.loadDisplayFile(navigation.goForward(1)));
            items.add(item);
            navigate = true;
        }
        if (navigate)
            items.add(new SeparatorMenuItem());
    }
    final Parent model_parent = instance.getRepresentation().getModelParent();
    items.add(new PrintAction(model_parent));
    items.add(new SaveSnapshotAction(model_parent));
    try {
        final DisplayModel model = widget.getDisplayModel();
        // Add context menu actions based on the selection (i.e. email, logbook, etc...)
        final Selection originalSelection = SelectionService.getInstance().getSelection();
        final List<SelectionInfo> newSelection = Arrays.asList(SelectionInfo.forModel(model, model_parent));
        SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, newSelection);
        List<ContextMenuEntry> supported = ContextMenuService.getInstance().listSupportedContextMenuEntries();
        supported.stream().forEach(action -> {
            MenuItem menuItem = new MenuItem(action.getName(), new ImageView(action.getIcon()));
            menuItem.setOnAction((e) -> {
                try {
                    SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, newSelection);
                    action.call(model_parent, SelectionService.getInstance().getSelection());
                } catch (Exception ex) {
                    logger.log(Level.WARNING, "Failed to execute " + action.getName() + " from display builder.", ex);
                }
            });
            items.add(menuItem);
        });
        SelectionService.getInstance().setSelection(DisplayRuntimeApplication.NAME, originalSelection);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to construct context menu actions", ex);
    }
    items.add(new SeparatorMenuItem());
    items.add(new DisplayToolbarAction(instance));
    // If the editor is available, add "Open in Editor"
    final AppResourceDescriptor editor = ApplicationService.findApplication("display_editor");
    if (editor != null && AuthorizationService.hasAuthorization("edit_display"))
        items.add(new OpenInEditorAction(editor, widget));
    items.add(new SeparatorMenuItem());
    items.add(new ReloadDisplayAction(instance));
}
Also used : Parent(javafx.scene.Parent) PrintAction(org.phoebus.ui.javafx.PrintAction) ProcessVariable(org.phoebus.core.types.ProcessVariable) Selection(org.phoebus.framework.selection.Selection) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) Widget(org.csstudio.display.builder.model.Widget) SaveSnapshotAction(org.phoebus.ui.application.SaveSnapshotAction) ContextMenuEntry(org.phoebus.ui.spi.ContextMenuEntry) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) Target(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo.Target) ImageView(javafx.scene.image.ImageView) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) DisplayModel(org.csstudio.display.builder.model.DisplayModel)

Example 9 with AppResourceDescriptor

use of org.phoebus.framework.spi.AppResourceDescriptor 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 10 with AppResourceDescriptor

use of org.phoebus.framework.spi.AppResourceDescriptor in project phoebus by ControlSystemStudio.

the class PhoebusApplication method createTopResourcesMenu.

/**
 * Fill the {@link #top_resources_menu} and {@link #top_resources_button}
 */
private void createTopResourcesMenu() {
    // Create top resources menu items off UI thread
    JobManager.schedule("Get top resources", monitor -> {
        final TopResources tops = TopResources.parse(Preferences.top_resources);
        final int N = tops.size();
        if (N <= 0)
            return;
        final MenuItem[] menu_items = new MenuItem[N];
        final MenuItem[] toolbar_items = new MenuItem[N];
        for (int i = 0; i < N; ++i) {
            final String description = tops.getDescription(i);
            final URI resource = tops.getResource(i);
            menu_items[i] = new MenuItem(description);
            menu_items[i].setOnAction(event -> openResource(resource, false));
            toolbar_items[i] = new MenuItem(description);
            toolbar_items[i].setOnAction(event -> openResource(resource, false));
            // Lookup application icon
            final AppResourceDescriptor application = findApplication(resource, false);
            if (application != null) {
                final Image icon = ImageCache.getImage(application.getIconURL());
                if (icon != null) {
                    menu_items[i].setGraphic(new ImageView(icon));
                    toolbar_items[i].setGraphic(new ImageView(icon));
                }
            }
        }
        // Back to UI thread to hook into menu
        Platform.runLater(() -> {
            top_resources_menu.getItems().setAll(menu_items);
            top_resources_menu.setDisable(false);
            top_resources_button.getItems().setAll(toolbar_items);
            top_resources_button.setDisable(false);
        });
    });
}
Also used : CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image) URI(java.net.URI) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor)

Aggregations

AppResourceDescriptor (org.phoebus.framework.spi.AppResourceDescriptor)12 URI (java.net.URI)7 ImageView (javafx.scene.image.ImageView)7 File (java.io.File)6 Logger (java.util.logging.Logger)5 MenuItem (javafx.scene.control.MenuItem)5 List (java.util.List)4 Level (java.util.logging.Level)4 SeparatorMenuItem (javafx.scene.control.SeparatorMenuItem)4 Image (javafx.scene.image.Image)4 FileInputStream (java.io.FileInputStream)3 URL (java.net.URL)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3 FXML (javafx.fxml.FXML)3 Stage (javafx.stage.Stage)3 ApplicationService (org.phoebus.framework.workbench.ApplicationService)3 IOException (java.io.IOException)2 Optional (java.util.Optional)2 Dialog (javafx.scene.control.Dialog)2