Search in sources :

Example 1 with ActionInfos

use of org.csstudio.display.builder.model.properties.ActionInfos 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 ActionInfos

use of org.csstudio.display.builder.model.properties.ActionInfos 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 ActionInfos

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

the class AllWidgetsAllProperties method main.

public static void main(String[] args) throws Exception {
    final DisplayModel model = new DisplayModel();
    for (final WidgetDescriptor widget_type : WidgetFactory.getInstance().getWidgetDescriptions()) {
        Widget widget = widget_type.createWidget();
        widget.setPropertyValue("name", widget_type.getName() + " 1");
        // For some widgets, adjust default values
        if (widget_type == ActionButtonWidget.WIDGET_DESCRIPTOR) {
            ActionButtonWidget button = (ActionButtonWidget) widget;
            final Macros macros = new Macros();
            macros.add("S", "Test");
            macros.add("N", "2");
            button.propActions().setValue(new ActionInfos(Arrays.asList(new OpenDisplayActionInfo("Display", "other.opi", macros, Target.REPLACE))));
        }
        model.runtimeChildren().addChild(widget);
    }
    ModelWriter.skip_defaults = false;
    try {
        final ModelWriter writer = new ModelWriter(new FileOutputStream(EXAMPLE_FILE));
        writer.writeModel(model);
        writer.close();
    } finally {
        ModelWriter.skip_defaults = true;
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) ActionInfos(org.csstudio.display.builder.model.properties.ActionInfos) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) Macros(org.csstudio.display.builder.model.macros.Macros) OpenDisplayActionInfo(org.csstudio.display.builder.model.properties.OpenDisplayActionInfo) ModelWriter(org.csstudio.display.builder.model.persist.ModelWriter)

Aggregations

ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)3 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)3 Macros (org.csstudio.display.builder.model.macros.Macros)2 ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)2 FileOutputStream (java.io.FileOutputStream)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 Widget (org.csstudio.display.builder.model.Widget)1 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)1 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)1 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)1 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)1 ActionButtonWidget (org.csstudio.display.builder.model.widgets.ActionButtonWidget)1 ActionsDialog (org.csstudio.display.builder.representation.javafx.ActionsDialog)1