Search in sources :

Example 1 with ActionInfo

use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.

the class ActionButtonRepresentation method makeBaseButton.

// private int calls = 0;
/**
 * Create <code>base</code>, either single-action button
 *  or menu for selecting one out of N actions
 */
private ButtonBase makeBaseButton() {
    final ActionInfos actions = model_widget.propActions().getValue();
    final ButtonBase result;
    if (actions.isExecutedAsOne() || actions.getActions().size() < 2) {
        final Button button = new Button();
        button.setOnAction(event -> handleActions(actions.getActions()));
        result = button;
    } else {
        final MenuButton button = new MenuButton();
        // Experimenting with ways to force update of popup location,
        // #226
        button.showingProperty().addListener((prop, old, showing) -> {
            if (showing) {
            // System.out.println("Showing " + model_widget + " menu: " + showing);
            // if (++calls > 2)
            // {
            // System.out.println("Hack!");
            // if (button.getPopupSide() == Side.BOTTOM)
            // button.setPopupSide(Side.LEFT);
            // else
            // button.setPopupSide(Side.BOTTOM);
            // // button.layout();
            // }
            }
        });
        for (final ActionInfo action : actions.getActions()) {
            final MenuItem item = new MenuItem(makeActionText(action), new ImageView(new Image(action.getType().getIconStream())));
            item.getStyleClass().add("action_button_item");
            item.setOnAction(event -> handleAction(action));
            button.getItems().add(item);
        }
        result = button;
    }
    result.setStyle(background);
    result.getStyleClass().add("action_button");
    result.setMnemonicParsing(false);
    // Model has width/height, but JFX widget has min, pref, max size.
    // updateChanges() will set the 'pref' size, so make min use that as well.
    result.setMinSize(ButtonBase.USE_PREF_SIZE, ButtonBase.USE_PREF_SIZE);
    // Monitor keys that modify the OpenDisplayActionInfo.Target.
    // Use filter to capture event that's otherwise already handled.
    result.addEventFilter(MouseEvent.MOUSE_PRESSED, this::checkModifiers);
    // Need to attach TT to the specific button, not the common jfx_node Pane
    TooltipSupport.attach(result, model_widget.propTooltip());
    result.setCursor(Cursor.HAND);
    return result;
}
Also used : Button(javafx.scene.control.Button) MenuButton(javafx.scene.control.MenuButton) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) MenuButton(javafx.scene.control.MenuButton) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) MenuItem(javafx.scene.control.MenuItem) ButtonBase(javafx.scene.control.ButtonBase) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 2 with ActionInfo

use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.

the class JFXActionsDialogDemo method start.

@Override
public void start(final Stage stage) {
    final Widget widget = new Widget("demo");
    final Macros macros = new Macros();
    macros.add("S", "Test");
    macros.add("N", "17");
    final ActionInfos actions = new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Related Display", "../opi/some_file.opi", macros, Target.TAB), new WritePVActionInfo("Reset", "Test:CS:Reset", "1"), new ExecuteScriptActionInfo("Script", new ScriptInfo(ScriptInfo.EMBEDDED_PYTHON, "print 'hi'", false, Collections.emptyList()))));
    final ActionsDialog dialog = new ActionsDialog(widget, actions);
    final Optional<ActionInfos> result = dialog.showAndWait();
    if (result.isPresent()) {
        if (result.get().isExecutedAsOne())
            System.out.println("Execute all commands as one:");
        for (ActionInfo info : result.get().getActions()) {
            if (info instanceof ExecuteScriptActionInfo) {
                final ExecuteScriptActionInfo action = (ExecuteScriptActionInfo) info;
                System.out.println("Execute " + action.getDescription() + ", " + action.getInfo() + ": " + action.getInfo().getText());
            } else
                System.out.println(info);
        }
    } else
        System.out.println("Cancelled");
}
Also used : ActionsDialog(org.csstudio.display.builder.representation.javafx.ActionsDialog) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) Widget(org.csstudio.display.builder.model.Widget) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) Macros(org.csstudio.display.builder.model.macros.Macros) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)

Example 3 with ActionInfo

use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.

the class ActionButtonRepresentation method createSWTControl.

@Override
protected Button createSWTControl(final Composite parent) throws Exception {
    final List<ActionInfo> actions = model_widget.propActions().getValue().getActions();
    final Button button = new Button(parent, SWT.PUSH);
    // Use basic button for single action
    if (actions.size() == 1) {
        final ActionInfo the_action = actions.get(0);
        button.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(final SelectionEvent event) {
                handleAction(the_action, event.stateMask);
            }
        });
    } else {
        // Add context menu if there are multiple actions
        final Menu menu = new Menu(button);
        for (final ActionInfo action : actions) {
            final MenuItem item = new MenuItem(menu, SWT.PUSH);
            item.setText(action.getDescription());
            final ActionInfo the_action = action;
            item.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(final SelectionEvent event) {
                    handleAction(the_action, event.stateMask);
                }
            });
        }
        button.setMenu(menu);
    }
    return button;
}
Also used : Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Example 4 with ActionInfo

use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.

the class ContextMenuSupport method fillContextMenu.

private void fillContextMenu(final IMenuManager manager) {
    final Widget context_menu_widget = view.getActiveWidget();
    if (context_menu_widget == null) {
        logger.log(Level.WARNING, "Missing context_menu_widget");
        manager.add(new Action("No widget") {
        });
    } else {
        // Widget info
        manager.add(new WidgetInfoAction(context_menu_widget));
        // Actions of the widget
        for (ActionInfo info : context_menu_widget.propActions().getValue().getActions()) {
            if (info.getType() == ActionType.OPEN_DISPLAY) {
                // Add variant for all the available Target types: Replace, new Tab, ...
                final OpenDisplayActionInfo open_info = (OpenDisplayActionInfo) info;
                for (Target target : Target.values()) {
                    // STANDALONE can be achieved via StandaloneAction on new display
                    if (target == Target.STANDALONE)
                        continue;
                    final String desc = target == Target.REPLACE ? open_info.getDescription() : open_info.getDescription() + " (" + target + ")";
                    manager.add(new ActionInfoWrapper(context_menu_widget, new OpenDisplayActionInfo(desc, open_info.getFile(), open_info.getMacros(), target)));
                }
            } else
                manager.add(new ActionInfoWrapper(context_menu_widget, info));
        }
        // Actions of the widget runtime
        final WidgetRuntime<Widget> runtime = RuntimeUtil.getRuntime(context_menu_widget);
        if (runtime == null)
            throw new NullPointerException("Missing runtime for " + context_menu_widget);
        for (RuntimeAction info : runtime.getRuntimeActions()) manager.add(new RuntimeActionWrapper(context_menu_widget, info));
    }
    // Placeholder for ProcessVariable object contributions
    manager.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
    manager.add(new Separator());
    if (context_menu_widget != null) {
        final Node node = JFXBaseRepresentation.getJFXNode(context_menu_widget);
        final Scene scene = node.getScene();
        manager.add(new SaveSnapshotAction(shell, scene));
        manager.add(new PrintAction(shell, scene));
        manager.add(new SendEMailAction(shell, scene));
        manager.add(new SendLogbookAction(shell, scene));
        manager.add(new FullScreenAction(view.getSite().getPage()));
        if (support_standalone)
            manager.add(new StandaloneAction(view));
    }
    // Placeholder for the display editor.
    // If editor.rcp plugin is included, it adds "Open in editor"
    manager.add(new Separator("display_editor"));
    manager.add(new ReloadDisplayAction());
}
Also used : Action(org.eclipse.jface.action.Action) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) Node(javafx.scene.Node) Widget(org.csstudio.display.builder.model.Widget) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) Scene(javafx.scene.Scene) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) Target(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo.Target) GroupMarker(org.eclipse.jface.action.GroupMarker) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) Separator(org.eclipse.jface.action.Separator)

Example 5 with ActionInfo

use of org.csstudio.display.builder.model.properties.ActionInfo in project org.csstudio.display.builder by kasemir.

the class WidgetRuntime method startScripts.

/**
 * Start Scripts
 */
private void startScripts() {
    // Start scripts triggered by PVs
    final List<ScriptInfo> script_infos = widget.propScripts().getValue();
    final List<RuleInfo> rule_infos = widget.propRules().getValue();
    if ((script_infos.size() > 0) || (rule_infos.size() > 0)) {
        final List<RuntimeScriptHandler> handlers = new ArrayList<>(script_infos.size() + rule_infos.size());
        for (final ScriptInfo script_info : script_infos) {
            try {
                handlers.add(new RuntimeScriptHandler(widget, script_info));
            } catch (final Exception ex) {
                final StringBuilder buf = new StringBuilder();
                buf.append("Script failed to compile\n");
                try {
                    final DisplayModel model = widget.getDisplayModel();
                    buf.append("Display '").append(model.getDisplayName()).append("', ");
                } catch (Exception ignore) {
                // Skip display model
                }
                buf.append(widget).append(", ").append(script_info.getPath());
                logger.log(Level.WARNING, buf.toString(), ex);
            }
        }
        for (final RuleInfo rule_info : rule_infos) {
            try {
                handlers.add(new RuntimeScriptHandler(widget, rule_info));
            } catch (final Exception ex) {
                final StringBuilder buf = new StringBuilder();
                buf.append("Rule failed to compile\n");
                try {
                    final DisplayModel model = widget.getDisplayModel();
                    buf.append("Display '").append(model.getDisplayName()).append("', ");
                } catch (Exception ignore) {
                // Skip display model
                }
                buf.append(widget).append(", ").append(rule_info.getName());
                logger.log(Level.WARNING, buf.toString(), ex);
            }
        }
        script_handlers = handlers;
    }
    // Compile scripts invoked by actions
    final List<ActionInfo> actions = widget.propActions().getValue().getActions();
    if (actions.size() > 0) {
        final Map<ExecuteScriptActionInfo, Script> scripts = new HashMap<>();
        for (ActionInfo action_info : actions) {
            if (!(action_info instanceof ExecuteScriptActionInfo))
                continue;
            final ExecuteScriptActionInfo script_action = (ExecuteScriptActionInfo) action_info;
            try {
                final MacroValueProvider macros = widget.getMacrosOrProperties();
                final Script script = RuntimeScriptHandler.compileScript(widget, macros, script_action.getInfo());
                scripts.put(script_action, script);
            } catch (final Exception ex) {
                final StringBuilder buf = new StringBuilder();
                buf.append("Script for action failed to compile\n");
                try {
                    final DisplayModel model = widget.getDisplayModel();
                    buf.append("Display '").append(model.getDisplayName()).append("', ");
                } catch (Exception ignore) {
                // Skip display model
                }
                buf.append(widget).append(", ").append(script_action);
                logger.log(Level.WARNING, buf.toString(), ex);
            }
        }
        if (scripts.size() > 0)
            action_scripts = scripts;
    }
    // Signal that start() has completed
    started.countDown();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) HashMap(java.util.HashMap) ScriptInfo(org.csstudio.display.builder.model.properties.ScriptInfo) ArrayList(java.util.ArrayList) ActionInfo(org.csstudio.display.builder.model.properties.ActionInfo) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) MacroValueProvider(org.csstudio.display.builder.model.macros.MacroValueProvider) DisplayModel(org.csstudio.display.builder.model.DisplayModel) RuntimeScriptHandler(org.csstudio.display.builder.runtime.script.internal.RuntimeScriptHandler) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

Aggregations

ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)6 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)4 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)3 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)3 ArrayList (java.util.ArrayList)2 Widget (org.csstudio.display.builder.model.Widget)2 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)2 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)2 HashMap (java.util.HashMap)1 Node (javafx.scene.Node)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 ButtonBase (javafx.scene.control.ButtonBase)1 MenuButton (javafx.scene.control.MenuButton)1 MenuItem (javafx.scene.control.MenuItem)1 Image (javafx.scene.image.Image)1 ImageView (javafx.scene.image.ImageView)1 DisplayModel (org.csstudio.display.builder.model.DisplayModel)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 MacroValueProvider (org.csstudio.display.builder.model.macros.MacroValueProvider)1