Search in sources :

Example 1 with ActionsWidgetProperty

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

the class PropertyPanelSection method createPropertyUI.

/**
 * Add UI items for displaying or editing property
 *  @param property Property (on primary widget)
 *  @param other Zero or more additional widgets that have same type of property
 *  @param structureIndex Index of the array structure (element) being added. It is meaningful
 *                        only for properties instance of {@link StructuredWidgetProperty}.
 */
private void createPropertyUI(final UndoableActionManager undo, final WidgetProperty<?> property, final List<Widget> other, final int structureIndex, final int indentationLevel) {
    // Skip runtime properties
    if (property.getCategory() == WidgetPropertyCategory.RUNTIME)
        return;
    final Label label = new Label(property.getDescription());
    label.setMaxWidth(Double.MAX_VALUE);
    final String tooltip = property.getDescription() + " (" + property.getPath() + ")";
    label.setTooltip(new Tooltip(tooltip));
    // setGridLinesVisible(true); // For debugging the layout
    Node field = bindSimplePropertyField(undo, bindings, property, other);
    if (field != null) {
    // do nothing
    } else if (property instanceof MacrosWidgetProperty) {
        final MacrosWidgetProperty macros_prop = (MacrosWidgetProperty) property;
        final Button macros_field = new Button();
        macros_field.setMaxWidth(Double.MAX_VALUE);
        final MacrosPropertyBinding binding = new MacrosPropertyBinding(undo, macros_field, macros_prop, other);
        bindings.add(binding);
        binding.bind();
        field = macros_field;
    } else if (property instanceof ActionsWidgetProperty) {
        final ActionsWidgetProperty actions_prop = (ActionsWidgetProperty) property;
        final Button actions_field = new Button();
        actions_field.setMaxWidth(Double.MAX_VALUE);
        final ActionsPropertyBinding binding = new ActionsPropertyBinding(undo, actions_field, actions_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = actions_field;
    } else if (property instanceof ScriptsWidgetProperty) {
        final ScriptsWidgetProperty scripts_prop = (ScriptsWidgetProperty) property;
        final Button scripts_field = new Button();
        scripts_field.setMaxWidth(Double.MAX_VALUE);
        final ScriptsPropertyBinding binding = new ScriptsPropertyBinding(undo, scripts_field, scripts_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = scripts_field;
    } else if (property instanceof RulesWidgetProperty) {
        final RulesWidgetProperty rules_prop = (RulesWidgetProperty) property;
        final Button rules_field = new Button();
        rules_field.setMaxWidth(Double.MAX_VALUE);
        final RulesPropertyBinding binding = new RulesPropertyBinding(undo, rules_field, rules_prop, other, autocomplete_menu);
        bindings.add(binding);
        binding.bind();
        field = rules_field;
    } else if (property instanceof StructuredWidgetProperty) {
        // Don't allow editing structures and their elements in class mode
        if (class_mode)
            return;
        final StructuredWidgetProperty struct = (StructuredWidgetProperty) property;
        final Label header = new Label(struct.getDescription() + (structureIndex > 0 ? " " + String.valueOf(1 + structureIndex) : ""));
        header.getStyleClass().add("structure_property_name");
        header.setMaxWidth(Double.MAX_VALUE);
        final int row = getNextGridRow();
        fillIndent(indentationLevel, row);
        add(header, 0 + indentationLevel, row, 7 - 2 * indentationLevel, 1);
        final Separator separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
        for (WidgetProperty<?> elem : struct.getValue()) this.createPropertyUI(undo, elem, other, -1, indentationLevel);
        return;
    } else if (property instanceof ArrayWidgetProperty) {
        // Don't allow editing arrays and their elements in class mode
        if (class_mode)
            return;
        @SuppressWarnings("unchecked") final ArrayWidgetProperty<WidgetProperty<?>> array = (ArrayWidgetProperty<WidgetProperty<?>>) property;
        // UI for changing array size
        final Spinner<Integer> spinner = new Spinner<>(array.getMinimumSize(), 100, 0);
        final ArraySizePropertyBinding count_binding = new ArraySizePropertyBinding(this, undo, spinner, array, other);
        bindings.add(count_binding);
        count_binding.bind();
        // set size of array
        int row = getNextGridRow();
        label.getStyleClass().add("array_property_name");
        label.setMaxWidth(Double.MAX_VALUE);
        label.setMaxHeight(Double.MAX_VALUE);
        spinner.getStyleClass().add("array_property_value");
        spinner.setMaxWidth(Double.MAX_VALUE);
        fillHeaderIndent(indentationLevel, row);
        add(label, indentationLevel, row, 4 - indentationLevel, 1);
        add(spinner, 4, row, 2 - indentationLevel, 1);
        Separator separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 1 + indentationLevel, getNextGridRow(), 5 - 2 * indentationLevel, 1);
        // array elements
        final List<WidgetProperty<?>> wpeList = array.getValue();
        for (int i = 0; i < wpeList.size(); i++) {
            final WidgetProperty<?> elem = wpeList.get(i);
            createPropertyUI(undo, elem, other, i, indentationLevel + 1);
        }
        // mark end of array
        row = getNextGridRow();
        final Label endlabel = new Label();
        endlabel.setMaxWidth(Double.MAX_VALUE);
        GridPane.setHgrow(endlabel, Priority.ALWAYS);
        endlabel.getStyleClass().add("array_property_end");
        fillIndent(indentationLevel, row);
        add(endlabel, 0 + indentationLevel, row, 7 - 2 * indentationLevel, 1);
        separator = new Separator();
        separator.getStyleClass().add("property_separator");
        add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
        return;
    } else // As new property types are added, they might need to be handled:
    // else if (property instanceof SomeNewWidgetProperty) { ... }
    {
        // Fallback for unknown property: read-only
        final TextField text = new TextField();
        text.setText(String.valueOf(property.getValue()));
        text.setEditable(false);
        field = text;
    }
    // Display Label, Class indicator/checkbox, field
    final int row = getNextGridRow();
    label.getStyleClass().add("property_name");
    field.getStyleClass().add("property_value");
    // Allow label to shrink (can use tooltip to see),
    // but show the value
    // GridPane.setHgrow(label, Priority.ALWAYS);
    GridPane.setHgrow(field, Priority.ALWAYS);
    fillIndent(indentationLevel, row);
    add(label, indentationLevel, row, 3 - indentationLevel, 1);
    final Widget widget = property.getWidget();
    if (!(property == widget.getProperty("type") || property == widget.getProperty("name"))) {
        if (class_mode) {
            // Class definition mode:
            // Check box for 'use_class'
            final CheckBox check = new CheckBox();
            check.setTooltip(use_class_tooltip);
            final WidgetPropertyBinding<?, ?> binding = new UseWidgetClassBinding(undo, check, field, property, other);
            bindings.add(binding);
            binding.bind();
            add(check, 3, row);
        } else {
            // Display file mode:
            // Show if property is set by the class, not editable.
            final Label indicator = new Label();
            indicator.setTooltip(using_class_tooltip);
            final WidgetPropertyBinding<?, ?> binding = new ShowWidgetClassBinding(field, property, indicator);
            bindings.add(binding);
            binding.bind();
            add(indicator, 3, row);
        }
    }
    add(field, 4, row, 3 - indentationLevel, 1);
    final Separator separator = new Separator();
    separator.getStyleClass().add("property_separator");
    add(separator, 0 + indentationLevel, getNextGridRow(), 7 - 2 * indentationLevel, 1);
}
Also used : RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) ScriptsWidgetProperty(org.csstudio.display.builder.model.properties.ScriptsWidgetProperty) Spinner(javafx.scene.control.Spinner) Node(javafx.scene.Node) Label(javafx.scene.control.Label) Widget(org.csstudio.display.builder.model.Widget) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) Button(javafx.scene.control.Button) ToggleButton(javafx.scene.control.ToggleButton) TextField(javafx.scene.control.TextField) MacrosWidgetProperty(org.csstudio.display.builder.model.properties.MacrosWidgetProperty) Tooltip(javafx.scene.control.Tooltip) ScriptsWidgetProperty(org.csstudio.display.builder.model.properties.ScriptsWidgetProperty) StructuredWidgetProperty(org.csstudio.display.builder.model.StructuredWidgetProperty) MacrosWidgetProperty(org.csstudio.display.builder.model.properties.MacrosWidgetProperty) EnumWidgetProperty(org.csstudio.display.builder.model.properties.EnumWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) BooleanWidgetProperty(org.csstudio.display.builder.model.properties.BooleanWidgetProperty) MacroizedWidgetProperty(org.csstudio.display.builder.model.MacroizedWidgetProperty) ColorWidgetProperty(org.csstudio.display.builder.model.properties.ColorWidgetProperty) PointsWidgetProperty(org.csstudio.display.builder.model.properties.PointsWidgetProperty) PVNameWidgetProperty(org.csstudio.display.builder.model.properties.PVNameWidgetProperty) FilenameWidgetProperty(org.csstudio.display.builder.model.properties.FilenameWidgetProperty) RulesWidgetProperty(org.csstudio.display.builder.model.properties.RulesWidgetProperty) ArrayWidgetProperty(org.csstudio.display.builder.model.ArrayWidgetProperty) FontWidgetProperty(org.csstudio.display.builder.model.properties.FontWidgetProperty) ColorMapWidgetProperty(org.csstudio.display.builder.model.properties.ColorMapWidgetProperty) ActionsWidgetProperty(org.csstudio.display.builder.model.properties.ActionsWidgetProperty) ActionsWidgetProperty(org.csstudio.display.builder.model.properties.ActionsWidgetProperty) CheckBox(javafx.scene.control.CheckBox) StructuredWidgetProperty(org.csstudio.display.builder.model.StructuredWidgetProperty) Separator(javafx.scene.control.Separator)

Aggregations

Node (javafx.scene.Node)1 Button (javafx.scene.control.Button)1 CheckBox (javafx.scene.control.CheckBox)1 Label (javafx.scene.control.Label)1 Separator (javafx.scene.control.Separator)1 Spinner (javafx.scene.control.Spinner)1 TextField (javafx.scene.control.TextField)1 ToggleButton (javafx.scene.control.ToggleButton)1 Tooltip (javafx.scene.control.Tooltip)1 ArrayWidgetProperty (org.csstudio.display.builder.model.ArrayWidgetProperty)1 MacroizedWidgetProperty (org.csstudio.display.builder.model.MacroizedWidgetProperty)1 StructuredWidgetProperty (org.csstudio.display.builder.model.StructuredWidgetProperty)1 Widget (org.csstudio.display.builder.model.Widget)1 WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)1 ActionsWidgetProperty (org.csstudio.display.builder.model.properties.ActionsWidgetProperty)1 BooleanWidgetProperty (org.csstudio.display.builder.model.properties.BooleanWidgetProperty)1 ColorMapWidgetProperty (org.csstudio.display.builder.model.properties.ColorMapWidgetProperty)1 ColorWidgetProperty (org.csstudio.display.builder.model.properties.ColorWidgetProperty)1 EnumWidgetProperty (org.csstudio.display.builder.model.properties.EnumWidgetProperty)1 FilenameWidgetProperty (org.csstudio.display.builder.model.properties.FilenameWidgetProperty)1