Search in sources :

Example 1 with WritePVActionInfo

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

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

the class WidgetRuntime method start.

/**
 * Start: Connect to PVs, start scripts
 *  @throws Exception on error
 */
public void start() throws Exception {
    // Update "value" property from primary PV, if defined
    final Optional<WidgetProperty<String>> name = widget.checkProperty(propPVName);
    final Optional<WidgetProperty<VType>> value = widget.checkProperty(runtimePropPVValue);
    if (name.isPresent() && value.isPresent())
        pv_name_binding.set(new PVNameToValueBinding(this, name.get(), value.get(), true));
    // Prepare action-related PVs
    final List<ActionInfo> actions = widget.propActions().getValue().getActions();
    if (actions.size() > 0) {
        final List<RuntimePV> action_pvs = new ArrayList<>();
        for (final ActionInfo action : actions) {
            if (action instanceof WritePVActionInfo) {
                final String pv_name = ((WritePVActionInfo) action).getPV();
                final String expanded = MacroHandler.replace(widget.getMacrosOrProperties(), pv_name);
                final RuntimePV pv = PVFactory.getPV(expanded);
                action_pvs.add(pv);
                addPV(pv, true);
            }
        }
        if (action_pvs.size() > 0)
            this.writable_pvs = action_pvs;
    }
    widget.propClass().addPropertyListener(update_widget_class);
    // Start scripts in pool because Jython setup is expensive
    RuntimeUtil.getExecutor().execute(this::startScripts);
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) 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) WritePVActionInfo(org.csstudio.display.builder.model.properties.WritePVActionInfo)

Aggregations

ActionInfo (org.csstudio.display.builder.model.properties.ActionInfo)2 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)2 WritePVActionInfo (org.csstudio.display.builder.model.properties.WritePVActionInfo)2 ArrayList (java.util.ArrayList)1 Widget (org.csstudio.display.builder.model.Widget)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 Macros (org.csstudio.display.builder.model.macros.Macros)1 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)1 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)1 ScriptInfo (org.csstudio.display.builder.model.properties.ScriptInfo)1 ActionsDialog (org.csstudio.display.builder.representation.javafx.ActionsDialog)1 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)1