Search in sources :

Example 6 with WidgetProperty

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

the class PointsBinding method selectionChanged.

@Override
public void selectionChanged(final List<Widget> widgets) {
    if (widgets != null && widgets.size() == 1) {
        final Widget w = widgets.get(0);
        Optional<WidgetProperty<Points>> prop = w.checkProperty(propPoints);
        if (prop.isPresent()) {
            createEditor(w);
            return;
        }
    }
    // Not exactly one widget with "points" -> No editor
    disposeEditor();
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) Widget(org.csstudio.display.builder.model.Widget)

Example 7 with WidgetProperty

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

the class WidgetInfoDialog method createProperties.

private Tab createProperties(final Widget widget) {
    // Use text field to allow copying the name (for use in scripts)
    // and value, but not the localized description and category
    // which are just for information
    final TableColumn<WidgetProperty<?>, String> cat = new TableColumn<>(Messages.WidgetInfoDialog_Category);
    cat.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getCategory().getDescription()));
    final TableColumn<WidgetProperty<?>, String> descr = new TableColumn<>(Messages.WidgetInfoDialog_Property);
    descr.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getDescription()));
    final TableColumn<WidgetProperty<?>, String> name = new TableColumn<>(Messages.WidgetInfoDialog_Name);
    name.setCellFactory(TextFieldTableCell.forTableColumn());
    name.setCellValueFactory(param -> new ReadOnlyStringWrapper(param.getValue().getName()));
    final TableColumn<WidgetProperty<?>, String> value = new TableColumn<>(Messages.WidgetInfoDialog_Value);
    value.setCellFactory(TextFieldTableCell.forTableColumn());
    value.setCellValueFactory(param -> new ReadOnlyStringWrapper(Objects.toString(param.getValue().getValue())));
    final TableView<WidgetProperty<?>> table = new TableView<>(FXCollections.observableArrayList(widget.getProperties()));
    table.getColumns().add(cat);
    table.getColumns().add(descr);
    table.getColumns().add(name);
    table.getColumns().add(value);
    table.setEditable(true);
    table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    return new Tab(Messages.WidgetInfoDialog_TabProperties, table);
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) Tab(javafx.scene.control.Tab) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) TableColumn(javafx.scene.control.TableColumn) TableView(javafx.scene.control.TableView)

Example 8 with WidgetProperty

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

the class RulesWidgetProperty method writeToXML.

@Override
public void writeToXML(final ModelWriter model_writer, final XMLStreamWriter writer) throws Exception {
    logger.log(Level.FINE, "Write " + value.size() + " rules to XML");
    for (final RuleInfo info : value) {
        // <rule name="name" prop_id="prop" out_exp="true">
        writer.writeStartElement(XMLTags.RULE);
        writer.writeAttribute(XMLTags.NAME, info.getName());
        writer.writeAttribute("prop_id", info.getPropID());
        writer.writeAttribute("out_exp", String.valueOf(info.getPropAsExprFlag()));
        for (final ExpressionInfo<?> expr : info.getExpressions()) {
            // <exp bool_exp="foo==1">
            writer.writeStartElement("exp");
            writer.writeAttribute("bool_exp", expr.getBoolExp());
            if (info.getPropAsExprFlag()) {
                // <expression>
                writer.writeStartElement("expression");
                if (!(expr.getPropVal() instanceof String)) {
                    logger.log(Level.SEVERE, "Mismatch of rules output expression flag with expression value type, expected String, got ", expr.getPropVal().getClass());
                    writer.writeCharacters("ERROR");
                }
                // some string of the value or expression
                writer.writeCharacters((String) expr.getPropVal());
            } else {
                // <value>
                writer.writeStartElement("value");
                if (!(expr.getPropVal() instanceof WidgetProperty<?>)) {
                    logger.log(Level.SEVERE, "Mismatch of rules output expression flag with expression value type, expected Widget Property, got ", expr.getPropVal().getClass());
                    writer.writeCharacters("ERROR");
                }
                // write the property
                ((WidgetProperty<?>) expr.getPropVal()).writeToXML(model_writer, writer);
            }
            // </value> or </expression>
            writer.writeEndElement();
            // </exp>
            writer.writeEndElement();
        }
        for (final ScriptPV pv : info.getPVs()) {
            // <pv trig="true">
            writer.writeStartElement(XMLTags.PV_NAME);
            if (!pv.isTrigger())
                writer.writeAttribute(XMLTags.TRIGGER, Boolean.FALSE.toString());
            // some string of the pv name
            writer.writeCharacters(pv.getName());
            // </pv>
            writer.writeEndElement();
        }
        // </rule>
        writer.writeEndElement();
    }
}
Also used : WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) ExprInfoString(org.csstudio.display.builder.model.rules.RuleInfo.ExprInfoString) RuleInfo(org.csstudio.display.builder.model.rules.RuleInfo)

Example 9 with WidgetProperty

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

the class XYPlotWidgetRuntime method stop.

@Override
public void stop() {
    // Disconnect Marker PVs and listeners
    for (Map.Entry<WidgetProperty<?>, WidgetPropertyListener<?>> entry : marker_prop_listeners.entrySet()) entry.getKey().removePropertyListener(entry.getValue());
    marker_prop_listeners.clear();
    for (Map.Entry<RuntimePV, RuntimePVListener> entry : marker_pv_listeners.entrySet()) entry.getKey().removeListener(entry.getValue());
    marker_pv_listeners.clear();
    for (RuntimePV pv : marker_pvs) {
        removePV(pv);
        PVFactory.releasePV(pv);
    }
    marker_pvs.clear();
    for (PVNameToValueBinding binding : bindings) binding.dispose();
    super.stop();
}
Also used : TraceWidgetProperty(org.csstudio.display.builder.model.widgets.plots.PlotWidgetProperties.TraceWidgetProperty) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) PVNameToValueBinding(org.csstudio.display.builder.runtime.PVNameToValueBinding) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Example 10 with WidgetProperty

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

the class ImageWidgetRuntime method bindROI.

/**
 * Bind an ROI PV to an ROI value
 *  @param name_prop Property for the PV name
 *  @param value_prop Property for the value
 */
private void bindROI(final WidgetProperty<String> name_prop, final WidgetProperty<Double> value_prop) {
    final String pv_name = name_prop.getValue();
    if (pv_name.isEmpty())
        return;
    logger.log(Level.FINER, "Connecting {0} to ROI PV {1}", new Object[] { widget, pv_name });
    try {
        final RuntimePV pv = PVFactory.getPV(pv_name);
        addPV(pv);
        roi_pvs.add(pv);
        // Write value changes to the PV
        final WidgetPropertyListener<Double> prop_listener = (prop, old, value) -> {
            try {
                if (value == VTypeUtil.getValueNumber(pv.read()).doubleValue())
                    return;
                // System.out.println("Writing " + value_prop + " to PV " + pv_name);
                pv.write(value);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Error writing ROI value to PV " + pv_name, ex);
            }
        };
        value_prop.addPropertyListener(prop_listener);
        roi_prop_listeners.put(value_prop, prop_listener);
        // Write PV updates to the value
        final RuntimePVListener pv_listener = new RuntimePVListener() {

            @Override
            public void valueChanged(final RuntimePV pv, final VType value) {
                final double number = VTypeUtil.getValueNumber(value).doubleValue();
                if (number == value_prop.getValue())
                    return;
                // System.out.println("Writing from PV " + pv_name + " to " + value_prop);
                value_prop.setValue(number);
            }
        };
        pv.addListener(pv_listener);
        roi_pv_listeners.put(pv, pv_listener);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Error connecting ROI PV " + pv_name, ex);
    }
}
Also used : VTypeUtil(org.csstudio.display.builder.model.util.VTypeUtil) ROIWidgetProperty(org.csstudio.display.builder.model.widgets.plots.ImageWidget.ROIWidgetProperty) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) WidgetRuntime(org.csstudio.display.builder.runtime.WidgetRuntime) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener) PVFactory(org.csstudio.display.builder.runtime.pv.PVFactory) PVUtil(org.csstudio.display.builder.runtime.script.PVUtil) RuntimePlugin.logger(org.csstudio.display.builder.runtime.RuntimePlugin.logger) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) List(java.util.List) ImageWidget(org.csstudio.display.builder.model.widgets.plots.ImageWidget) Map(java.util.Map) WidgetPropertyListener(org.csstudio.display.builder.model.WidgetPropertyListener) RuntimeAction(org.csstudio.display.builder.runtime.RuntimeAction) WidgetProperty(org.csstudio.display.builder.model.WidgetProperty) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) VType(org.diirt.vtype.VType) RuntimePVListener(org.csstudio.display.builder.runtime.pv.RuntimePVListener)

Aggregations

WidgetProperty (org.csstudio.display.builder.model.WidgetProperty)20 ArrayList (java.util.ArrayList)7 Map (java.util.Map)6 Widget (org.csstudio.display.builder.model.Widget)6 WidgetPropertyListener (org.csstudio.display.builder.model.WidgetPropertyListener)6 List (java.util.List)5 Level (java.util.logging.Level)5 DisplayModel (org.csstudio.display.builder.model.DisplayModel)5 VType (org.diirt.vtype.VType)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)4 Collection (java.util.Collection)3 Label (javafx.scene.control.Label)3 ArrayWidgetProperty (org.csstudio.display.builder.model.ArrayWidgetProperty)3 RuntimePVListener (org.csstudio.display.builder.runtime.pv.RuntimePVListener)3 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 Platform (javafx.application.Platform)2 Insets (javafx.geometry.Insets)2 Pos (javafx.geometry.Pos)2 TextField (javafx.scene.control.TextField)2