Search in sources :

Example 1 with ActionButtonWidget

use of org.csstudio.display.builder.model.widgets.ActionButtonWidget 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)

Example 2 with ActionButtonWidget

use of org.csstudio.display.builder.model.widgets.ActionButtonWidget in project org.csstudio.display.builder by kasemir.

the class SelectedWidgetUITracker method createInlineEditor.

/**
 * Create an inline editor
 *
 *  <p>Depending on the widget's properties, it will edit
 *  the PV name or the text.
 *
 *  @param widget Widget on which to create an inline editor
 */
private void createInlineEditor(final Widget widget) {
    // Check for an inline-editable property
    Optional<WidgetProperty<String>> check;
    // Add Widget#getInlineEditableProperty()
    if (widget instanceof ActionButtonWidget)
        check = Optional.of(((ActionButtonWidget) widget).propText());
    else if (widget instanceof GroupWidget)
        check = Optional.of(((GroupWidget) widget).propName());
    else
        check = widget.checkProperty(CommonWidgetProperties.propPVName);
    if (!check.isPresent())
        check = widget.checkProperty(CommonWidgetProperties.propText);
    if (!check.isPresent())
        return;
    // Create text field, aligned with widget, but assert minimum size
    final MacroizedWidgetProperty<String> property = (MacroizedWidgetProperty<String>) check.get();
    inline_editor = new TextField(property.getSpecification());
    // 'Managed' text field would assume some default size,
    // but we set the exact size in here
    inline_editor.setManaged(false);
    // Not really shown since TextField will have focus
    inline_editor.setPromptText(property.getDescription());
    inline_editor.setTooltip(new Tooltip(property.getDescription()));
    inline_editor.relocate(tracker.getX(), tracker.getY());
    inline_editor.resize(Math.max(100, tracker.getWidth()), Math.max(20, tracker.getHeight()));
    getChildren().add(inline_editor);
    // add autocomplete menu if editing property PVName
    if (property.getName().equals(CommonWidgetProperties.propPVName.getName()))
        autocomplete_menu.attachField(inline_editor);
    // On enter, update the property. On Escape, just close
    inline_editor.setOnKeyPressed(event -> {
        switch(event.getCode()) {
            case ENTER:
                undo.execute(new SetMacroizedWidgetPropertyAction(property, inline_editor.getText()));
            // Fall through, close editor
            case ESCAPE:
                event.consume();
                closeInlineEditor();
            default:
        }
    });
    // Close when focus lost
    inline_editor.focusedProperty().addListener((prop, old, focused) -> {
        if (!focused)
            closeInlineEditor();
    });
    inline_editor.selectAll();
    inline_editor.requestFocus();
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) SetMacroizedWidgetPropertyAction(org.csstudio.display.builder.editor.undo.SetMacroizedWidgetPropertyAction) Tooltip(javafx.scene.control.Tooltip) TextField(javafx.scene.control.TextField) ActionButtonWidget(org.csstudio.display.builder.model.widgets.ActionButtonWidget) GroupWidget(org.csstudio.display.builder.model.widgets.GroupWidget)

Aggregations

ActionButtonWidget (org.csstudio.display.builder.model.widgets.ActionButtonWidget)2 FileOutputStream (java.io.FileOutputStream)1 TextField (javafx.scene.control.TextField)1 Tooltip (javafx.scene.control.Tooltip)1 SetMacroizedWidgetPropertyAction (org.csstudio.display.builder.editor.undo.SetMacroizedWidgetPropertyAction)1 MacroizedWidgetProperty (org.csstudio.display.builder.model.MacroizedWidgetProperty)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 Macros (org.csstudio.display.builder.model.macros.Macros)1 ModelWriter (org.csstudio.display.builder.model.persist.ModelWriter)1 ActionInfos (org.csstudio.display.builder.model.properties.ActionInfos)1 OpenDisplayActionInfo (org.csstudio.display.builder.model.properties.OpenDisplayActionInfo)1 GroupWidget (org.csstudio.display.builder.model.widgets.GroupWidget)1