Search in sources :

Example 1 with VStringArray

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

the class ElementAtStringFormulaFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VStringArray stringArray = (VStringArray) args.get(0);
    VNumber index = (VNumber) args.get(1);
    int i = index.getValue().intValue();
    return newVString(stringArray.getData().get(i), stringArray, stringArray);
}
Also used : VNumber(org.diirt.vtype.VNumber) VStringArray(org.diirt.vtype.VStringArray)

Example 2 with VStringArray

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

the class EnumFromVNumberFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumber value = (VNumber) args.get(0);
    VNumberArray intervals = (VNumberArray) args.get(1);
    VStringArray labels = (VStringArray) args.get(2);
    int index = 0;
    while (index < intervals.getData().size() && value.getValue().doubleValue() >= intervals.getData().getDouble(index)) {
        index++;
    }
    return newVEnum(index, labels.getData(), value, latestValidTimeOrNowOf(args));
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber) VStringArray(org.diirt.vtype.VStringArray)

Example 3 with VStringArray

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

the class ColumnFromVStringArrayFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VString name = (VString) args.get(0);
    VStringArray data = (VStringArray) args.get(1);
    if (name == null || data == null) {
        return null;
    }
    return VTableFactory.column(name.getValue(), data);
}
Also used : VString(org.diirt.vtype.VString) VStringArray(org.diirt.vtype.VStringArray)

Example 4 with VStringArray

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

the class PVUtil method getStringArray.

/**
 * Get string array from pv.
 *
 * @param pv
 *            The PV.
 * @return String array. For string array, it's the actual strings. For numeric arrays, the numbers are formatted as
 *         strings. For enum array, the labels are returned. For scalar PVs, an array with a single string is
 *         returned.
 */
public static final String[] getStringArray(IPV pv) {
    final VType value = checkPVValue(pv);
    if (value instanceof VStringArray) {
        final List<String> list = ((VStringArray) value).getData();
        return list.toArray(new String[list.size()]);
    } else if (value instanceof VDoubleArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Double.toString(list.getDouble(i));
        return text;
    } else if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Long.toString(list.getLong(i));
        return text;
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final ListInt list = ((VEnumArray) value).getIndexes();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) {
            final int index = list.getInt(i);
            if (index >= 0 && index <= labels.size())
                text[i] = labels.get(index);
            else
                text[i] = "<" + index + ">";
        }
        return text;
    }
    return new String[] { getString(pv) };
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) VNumberArray(org.diirt.vtype.VNumberArray) VEnumArray(org.diirt.vtype.VEnumArray) ListNumber(org.diirt.util.array.ListNumber) ListInt(org.diirt.util.array.ListInt) VType(org.diirt.vtype.VType) List(java.util.List) VStringArray(org.diirt.vtype.VStringArray)

Example 5 with VStringArray

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

the class ArrayEditPart method registerPropertyChangeHandlers.

@Override
protected void registerPropertyChangeHandlers() {
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            for (AbstractWidgetModel child : getWidgetModel().getAllChildren()) {
                child.setEnabled((Boolean) newValue);
            }
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            VType value = (VType) newValue;
            if (value instanceof VNumberArray) {
                Object wrappedArray = VTypeHelper.getWrappedArray(((VNumberArray) value));
                if (wrappedArray != null)
                    setValue(wrappedArray);
                else
                    setValue(VTypeHelper.getDoubleArray(value));
            } else {
                if (value instanceof VEnum)
                    setValue(new String[] { ((VEnum) value).getValue() });
                else if (value instanceof VString)
                    setValue(new String[] { ((VString) value).getValue() });
                else if (value instanceof VStringArray)
                    setValue(((VStringArray) value).getData().toArray());
                else
                    setValue(VTypeHelper.getDoubleArray(value));
            }
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_PVVALUE, handler);
    getWidgetModel().getProperty(ArrayModel.PROP_PVNAME).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            updatePropSheet();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            registerLoadPVDataTypeListener();
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_PVNAME, handler);
    getWidgetModel().getProperty(ArrayModel.PROP_DATA_TYPE).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            initValueArray();
        }
    });
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            updateWidgetSize();
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_BORDER_STYLE, handler);
    setPropertyChangeHandler(ArrayModel.PROP_BORDER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            getArrayFigure().setArrayLength((Integer) newValue);
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_ARRAY_LENGTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setSpinnerWidth((Integer) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SPINNER_WIDTH, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setHorizontal((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_HORIZONTAL, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setShowScrollbar((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SHOW_SCROLLBAR, handler);
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            ((ArrayFigure) figure).setShowSpinner((Boolean) newValue);
            keepElementSize = true;
            getWidgetModel().setSize(((ArrayFigure) figure).getPreferredSize());
            keepElementSize = false;
            return false;
        }
    };
    setPropertyChangeHandler(ArrayModel.PROP_SHOW_SPINNER, handler);
    PropertyChangeListener sizePropertyChangeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (getWidgetModel().getChildren().size() == 0 || inSync || keepElementSize)
                return;
            Dimension elementSize = getArrayFigure().getElementSize();
            int delta = (Integer) evt.getNewValue() - (Integer) evt.getOldValue();
            int elementWH = elementSize.height;
            String propID = evt.getPropertyName();
            boolean elementCountDirection = false;
            if (getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_WIDTH)) {
                elementWH = elementSize.width;
                elementCountDirection = true;
            } else if (!getWidgetModel().isHorizontal() && propID.equals(AbstractWidgetModel.PROP_HEIGHT)) {
                elementWH = elementSize.height;
                elementCountDirection = true;
            }
            if (elementCountDirection) {
                int deltaElementsCount = Math.round((float) delta / elementWH);
                int idelta = (Math.round((float) delta / elementWH) * elementWH);
                setPropertyValue(propID, (Integer) evt.getOldValue() + idelta, false);
                int visibleElementsCount = getArrayFigure().getVisibleElementsCount() + deltaElementsCount;
                setPropertyValue(ArrayModel.PROP_VISIBLE_ELEMENTS_COUNT, visibleElementsCount);
                setValue(getValue());
            } else {
                int wh;
                if (propID.equals(AbstractWidgetModel.PROP_WIDTH))
                    wh = getArrayFigure().getElementSize().width;
                else
                    wh = getArrayFigure().getElementSize().height;
                syncAllChildrenProperties(propID, wh + delta);
            }
        }
    };
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_WIDTH).addPropertyChangeListener(sizePropertyChangeListener);
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_HEIGHT).addPropertyChangeListener(sizePropertyChangeListener);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) VEnum(org.diirt.vtype.VEnum) VString(org.diirt.vtype.VString) Dimension(org.eclipse.draw2d.geometry.Dimension) VNumberArray(org.diirt.vtype.VNumberArray) AbstractWidgetModel(org.csstudio.opibuilder.model.AbstractWidgetModel) VType(org.diirt.vtype.VType) ArrayFigure(org.csstudio.swt.widgets.figures.ArrayFigure) VString(org.diirt.vtype.VString) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) VStringArray(org.diirt.vtype.VStringArray) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

VStringArray (org.diirt.vtype.VStringArray)8 VString (org.diirt.vtype.VString)4 VNumberArray (org.diirt.vtype.VNumberArray)3 VNumber (org.diirt.vtype.VNumber)2 VType (org.diirt.vtype.VType)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 ArrayFigure (org.csstudio.swt.widgets.figures.ArrayFigure)1 ListInt (org.diirt.util.array.ListInt)1 ListNumber (org.diirt.util.array.ListNumber)1 VDoubleArray (org.diirt.vtype.VDoubleArray)1 VEnum (org.diirt.vtype.VEnum)1 VEnumArray (org.diirt.vtype.VEnumArray)1 VTable (org.diirt.vtype.VTable)1 IFigure (org.eclipse.draw2d.IFigure)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1