Search in sources :

Example 1 with VEnum

use of org.diirt.vtype.VEnum in project yamcs-studio by yamcs.

the class LocalChannelHandler method write.

@Override
public void write(Object newValue, ChannelWriteCallback callback) {
    try {
        if (VEnum.class.equals(type)) {
            // Handle enum writes
            int newIndex = -1;
            VEnum firstEnum = (VEnum) initialValue;
            List<String> labels = firstEnum.getLabels();
            if (newValue instanceof Number) {
                newIndex = ((Number) newValue).intValue();
            } else if (newValue instanceof String) {
                newIndex = labels.indexOf((String) newValue);
                // parse a number.
                if (newIndex == -1) {
                    String value = (String) newValue;
                    try {
                        newIndex = Double.valueOf(value).intValue();
                    } catch (NumberFormatException ex) {
                    }
                }
            } else {
                throw new IllegalArgumentException("Value" + newValue + " can not be accepted by VEnum.");
            }
            newValue = ValueFactory.newVEnum(newIndex, firstEnum.getLabels(), alarmNone(), timeNow());
        } else if (VString.class.equals(type) && newValue instanceof String) {
            newValue = ValueFactory.newVString((String) newValue, alarmNone(), timeNow());
        } else {
            // If the string can be parsed to a number, do it
            if (newValue instanceof String) {
                String value = (String) newValue;
                try {
                    newValue = Double.valueOf(value);
                } catch (NumberFormatException ex) {
                // Not a double - continue
                }
            }
            // If new value is not a VType, try to convert it
            if (!(newValue instanceof VType)) {
                newValue = checkValue(ValueFactory.toVTypeChecked(newValue));
            }
        }
        processMessage(newValue);
        callback.channelWritten(null);
    } catch (Exception ex) {
        callback.channelWritten(ex);
    }
}
Also used : VType(org.diirt.vtype.VType) VEnum(org.diirt.vtype.VEnum) VString(org.diirt.vtype.VString)

Example 2 with VEnum

use of org.diirt.vtype.VEnum in project org.csstudio.display.builder by kasemir.

the class RadioRepresentation method selectionChanged.

private void selectionChanged(final ObservableValue<? extends Toggle> obs, final Toggle oldval, final Toggle newval) {
    if (!active && newval != null) {
        active = true;
        try {
            // For now reset to old value.
            // New value will be shown if the PV accepts it and sends a value update.
            toggle.selectToggle(oldval);
            final Object value;
            final VType pv_value = model_widget.runtimePropValue().getValue();
            if (pv_value instanceof VEnum || pv_value instanceof VNumber)
                // PV uses enumerated or numeric type, so write the index
                value = toggle.getToggles().indexOf(newval);
            else
                // PV uses text
                value = FormatOptionHandler.parse(pv_value, ((RadioButton) newval).getText(), FormatOption.DEFAULT);
            logger.log(Level.FINE, "Writing " + value);
            toolkit.fireWrite(model_widget, value);
        } finally {
            active = false;
        }
    }
}
Also used : VType(org.diirt.vtype.VType) VNumber(org.diirt.vtype.next.VNumber) VEnum(org.diirt.vtype.VEnum)

Example 3 with VEnum

use of org.diirt.vtype.VEnum in project org.csstudio.display.builder by kasemir.

the class ValueUtil method getLabels.

/**
 * Get labels for a {@link VEnum} value, or headers for a {@link VTable}.
 *  @param value Value of a PV
 *  @return Enum labels or empty array if not enum nor table
 */
public static String[] getLabels(final VType value) {
    if (value instanceof VEnum) {
        final List<String> labels = ((VEnum) value).getLabels();
        return labels.toArray(new String[labels.size()]);
    }
    if (value instanceof VTable) {
        final VTable table = (VTable) value;
        final int num = table.getColumnCount();
        final String[] headers = new String[num];
        for (int i = 0; i < num; ++i) headers[i] = table.getColumnName(i);
        return headers;
    }
    return new String[0];
}
Also used : VTable(org.diirt.vtype.VTable) VEnum(org.diirt.vtype.VEnum)

Example 4 with VEnum

use of org.diirt.vtype.VEnum in project yamcs-studio by yamcs.

the class AbstractChoiceEditPart method registerLoadItemsListener.

/**
 */
private void registerLoadItemsListener() {
    // load items from PV
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        if (getWidgetModel().isItemsFromPV()) {
            IPV pv = getPV(AbstractPVWidgetModel.PROP_PVNAME);
            if (pv != null) {
                if (loadItemsFromPVListener == null)
                    loadItemsFromPVListener = new IPVListener.Stub() {

                        @Override
                        public void valueChanged(IPV pv) {
                            VType value = pv.getValue();
                            if (value != null && value instanceof VEnum) {
                                List<String> new_meta = ((VEnum) value).getLabels();
                                getWidgetModel().setPropertyValue(AbstractChoiceModel.PROP_ITEMS, new_meta);
                            }
                        }
                    };
                pv.addListener(loadItemsFromPVListener);
            }
        }
    }
}
Also used : VType(org.diirt.vtype.VType) VEnum(org.diirt.vtype.VEnum) IPV(org.csstudio.simplepv.IPV)

Example 5 with VEnum

use of org.diirt.vtype.VEnum in project yamcs-studio by yamcs.

the class ComboEditPart method registerLoadItemsListener.

/**
 */
private void registerLoadItemsListener() {
    // load items from PV
    if (getExecutionMode() == ExecutionMode.RUN_MODE) {
        if (getWidgetModel().isItemsFromPV()) {
            IPV pv = getPV(AbstractPVWidgetModel.PROP_PVNAME);
            if (pv != null) {
                if (loadItemsFromPVListener == null)
                    loadItemsFromPVListener = new IPVListener.Stub() {

                        @Override
                        public void valueChanged(IPV pv) {
                            VType value = pv.getValue();
                            if (value != null && value instanceof VEnum) {
                                List<String> items = ((VEnum) value).getLabels();
                                getWidgetModel().setPropertyValue(ComboModel.PROP_ITEMS, items);
                            }
                        }
                    };
                pv.addListener(loadItemsFromPVListener);
            }
        }
    }
}
Also used : VType(org.diirt.vtype.VType) VEnum(org.diirt.vtype.VEnum) IPV(org.csstudio.simplepv.IPV)

Aggregations

VEnum (org.diirt.vtype.VEnum)12 VType (org.diirt.vtype.VType)7 VString (org.diirt.vtype.VString)4 IPV (org.csstudio.simplepv.IPV)3 ListNumber (org.diirt.util.array.ListNumber)3 VEnumArray (org.diirt.vtype.VEnumArray)3 VNumber (org.diirt.vtype.VNumber)3 VNumberArray (org.diirt.vtype.VNumberArray)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListInt (org.diirt.util.array.ListInt)2 VBoolean (org.diirt.vtype.VBoolean)2 VTable (org.diirt.vtype.VTable)2 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1 RotationStep (org.csstudio.display.builder.model.properties.RotationStep)1 ActionsInput (org.csstudio.opibuilder.widgetActions.ActionsInput)1 WritePVAction (org.csstudio.opibuilder.widgetActions.WritePVAction)1 VImage (org.diirt.vtype.VImage)1 VStringArray (org.diirt.vtype.VStringArray)1