Search in sources :

Example 6 with VType

use of org.yamcs.studio.data.vtype.VType in project yamcs-studio by yamcs.

the class AbstractBoolEditPart method registerCommonPropertyChangeHandlers.

/**
 * Registers property change handlers for the properties defined in {@link AbstractBoolWidgetModel}. This method is
 * provided for the convenience of subclasses, which can call this method in their implementation of
 * {@link #registerPropertyChangeHandlers()}.
 */
protected void registerCommonPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_PVVALUE, (oldValue, newValue, refreshableFigure) -> {
        if (newValue == null || !(newValue instanceof VType)) {
            return false;
        }
        var figure = (AbstractBoolFigure) refreshableFigure;
        switch(VTypeHelper.getBasicDataType((VType) newValue)) {
            case SHORT:
                figure.setTotalBits(TotalBits.BITS_16);
                break;
            case INT:
            case ENUM:
                figure.setTotalBits(TotalBits.BITS_32);
                break;
            default:
                break;
        }
        updateFromValue((VType) newValue, figure);
        return true;
    });
    setPropertyChangeHandler(PROP_BIT, (oldValue, newValue, refreshableFigure) -> {
        if (getWidgetModel().getDataType() != 0) {
            return false;
        }
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setBit((Integer) newValue);
        updateFromValue(getPVValue(PROP_PVNAME), figure);
        return true;
    });
    IWidgetPropertyChangeHandler dataTypeHandler = (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        if ((Integer) newValue == 0) {
            figure.setBit(getWidgetModel().getBit());
        } else {
            figure.setBit(-1);
        }
        updateFromValue(getPVValue(PROP_PVNAME), figure);
        updatePropSheet((Integer) newValue);
        return true;
    };
    getWidgetModel().getProperty(PROP_DATA_TYPE).addPropertyChangeListener(evt -> dataTypeHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure()));
    setPropertyChangeHandler(PROP_ON_STATE, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        updateFromValue(getPVValue(PROP_PVNAME), figure);
        return true;
    });
    setPropertyChangeHandler(PROP_SHOW_BOOL_LABEL, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setShowBooleanLabel((Boolean) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_BOOL_LABEL_POS, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setBoolLabelPosition(BoolLabelPosition.values()[(Integer) newValue]);
        return false;
    });
    setPropertyChangeHandler(PROP_ON_LABEL, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setOnLabel((String) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_OFF_LABEL, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setOffLabel((String) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_ON_COLOR, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setOnColor(((OPIColor) newValue).getSWTColor());
        return true;
    });
    setPropertyChangeHandler(PROP_OFF_COLOR, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolFigure) refreshableFigure;
        figure.setOffColor(((OPIColor) newValue).getSWTColor());
        return true;
    });
}
Also used : PROP_PVVALUE(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE) PROP_BOOL_LABEL_POS(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_BOOL_LABEL_POS) PROP_ON_COLOR(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_COLOR) VTypeHelper(org.yamcs.studio.data.VTypeHelper) PROP_OFF_STATE(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_STATE) AbstractBoolFigure(org.csstudio.swt.widgets.figures.AbstractBoolFigure) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PROP_PVNAME(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME) PROP_OFF_LABEL(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_LABEL) CustomMediaFactory(org.csstudio.ui.util.CustomMediaFactory) BoolLabelPosition(org.csstudio.swt.widgets.figures.AbstractBoolFigure.BoolLabelPosition) PROP_BIT(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_BIT) AbstractBoolWidgetModel(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel) PROP_DATA_TYPE(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_DATA_TYPE) PROP_OFF_COLOR(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_COLOR) TotalBits(org.csstudio.swt.widgets.figures.AbstractBoolFigure.TotalBits) VType(org.yamcs.studio.data.vtype.VType) PROP_ON_LABEL(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_LABEL) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) PROP_ON_STATE(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_STATE) PROP_SHOW_BOOL_LABEL(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_SHOW_BOOL_LABEL) OPIColor(org.csstudio.opibuilder.util.OPIColor) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) VType(org.yamcs.studio.data.vtype.VType) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractBoolFigure(org.csstudio.swt.widgets.figures.AbstractBoolFigure)

Example 7 with VType

use of org.yamcs.studio.data.vtype.VType in project yamcs-studio by yamcs.

the class AbstractChoiceEditPart method registerPropertyChangeHandlers.

@Override
@SuppressWarnings("unchecked")
protected void registerPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_PVNAME, (oldValue, newValue, figure) -> {
        registerLoadItemsListener();
        return false;
    });
    setPropertyChangeHandler(PROP_PVVALUE, (oldValue, newValue, refreshableFigure) -> {
        if (newValue != null && newValue instanceof VType) {
            var stringValue = VTypeHelper.getString((VType) newValue);
            ((AbstractChoiceFigure) refreshableFigure).setState(stringValue);
        }
        return false;
    });
    setPropertyChangeHandler(PROP_ITEMS, (oldValue, newValue, refreshableFigure) -> {
        if (newValue != null && newValue instanceof List) {
            ((AbstractChoiceFigure) refreshableFigure).setStates(((List<String>) newValue));
            if (getWidgetModel().isItemsFromPV()) {
                ((AbstractChoiceFigure) refreshableFigure).setState(VTypeHelper.getString(getPVValue(PROP_PVNAME)));
            }
        }
        return true;
    });
    IWidgetPropertyChangeHandler selectedColorHandler = (oldValue, newValue, figure) -> {
        ((AbstractChoiceFigure) figure).setSelectedColor(((OPIColor) newValue).getSWTColor());
        return false;
    };
    setPropertyChangeHandler(PROP_SELECTED_COLOR, selectedColorHandler);
    setPropertyChangeHandler(PROP_HORIZONTAL, (oldValue, newValue, figure) -> {
        ((AbstractChoiceFigure) figure).setHorizontal((Boolean) newValue);
        return true;
    });
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, refreshableFigure) -> {
        if (!(Boolean) newValue) {
            ((AbstractChoiceFigure) refreshableFigure).setStates((getWidgetModel().getItems()));
        }
        updatePropSheet((Boolean) newValue);
        return false;
    };
    getWidgetModel().getProperty(PROP_ITEMS_FROM_PV).addPropertyChangeListener(evt -> handler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure()));
}
Also used : PROP_PVVALUE(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE) VTypeHelper(org.yamcs.studio.data.VTypeHelper) VEnum(org.yamcs.studio.data.vtype.VEnum) PROP_HORIZONTAL(org.csstudio.opibuilder.widgets.model.AbstractChoiceModel.PROP_HORIZONTAL) PROP_PVNAME(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME) CustomMediaFactory(org.csstudio.ui.util.CustomMediaFactory) IFigure(org.eclipse.draw2d.IFigure) IPV(org.yamcs.studio.data.IPV) PROP_ITEMS_FROM_PV(org.csstudio.opibuilder.widgets.model.AbstractChoiceModel.PROP_ITEMS_FROM_PV) List(java.util.List) AbstractChoiceFigure(org.csstudio.swt.widgets.figures.AbstractChoiceFigure) VType(org.yamcs.studio.data.vtype.VType) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) IPVListener(org.yamcs.studio.data.IPVListener) PROP_SELECTED_COLOR(org.csstudio.opibuilder.widgets.model.AbstractChoiceModel.PROP_SELECTED_COLOR) OPIColor(org.csstudio.opibuilder.util.OPIColor) PROP_ITEMS(org.csstudio.opibuilder.widgets.model.AbstractChoiceModel.PROP_ITEMS) AbstractChoiceModel(org.csstudio.opibuilder.widgets.model.AbstractChoiceModel) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) VType(org.yamcs.studio.data.vtype.VType) AbstractChoiceFigure(org.csstudio.swt.widgets.figures.AbstractChoiceFigure) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) List(java.util.List) OPIColor(org.csstudio.opibuilder.util.OPIColor)

Example 8 with VType

use of org.yamcs.studio.data.vtype.VType in project yamcs-studio by yamcs.

the class ComboEditPart method registerPropertyChangeHandlers.

@Override
@SuppressWarnings("unchecked")
protected void registerPropertyChangeHandlers() {
    setPropertyChangeHandler(PROP_PVNAME, (oldValue, newValue, figure) -> {
        registerLoadItemsListener();
        return false;
    });
    autoSizeWidget((ComboFigure) getFigure());
    setPropertyChangeHandler(PROP_PVVALUE, (oldValue, newValue, refreshableFigure) -> {
        if (newValue != null) {
            var stringValue = VTypeHelper.getString((VType) newValue);
            if (Arrays.asList(combo.getItems()).contains(stringValue)) {
                combo.setText(stringValue);
            } else {
                combo.deselectAll();
            // 
            // if(getWidgetModel().isBorderAlarmSensitve())
            // autoSizeWidget((ComboFigure) refreshableFigure);
            }
        }
        return true;
    });
    setPropertyChangeHandler(PROP_ITEMS, (oldValue, newValue, refreshableFigure) -> {
        if (newValue != null && newValue instanceof List) {
            updateCombo((List<String>) newValue);
            if (getWidgetModel().isItemsFromPV()) {
                combo.setText(VTypeHelper.getString(getPVValue(PROP_PVNAME)));
            }
        }
        return true;
    });
    IWidgetPropertyChangeHandler handler = (oldValue, newValue, refreshableFigure) -> {
        updatePropSheet((Boolean) newValue);
        return false;
    };
    getWidgetModel().getProperty(PROP_ITEMS_FROM_PV).addPropertyChangeListener(evt -> handler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure()));
    // size change handlers--always apply the default height
    IWidgetPropertyChangeHandler handle = (oldValue, newValue, figure) -> {
        autoSizeWidget((ComboFigure) figure);
        return true;
    };
    setPropertyChangeHandler(PROP_WIDTH, handle);
    setPropertyChangeHandler(PROP_HEIGHT, handle);
    setPropertyChangeHandler(PROP_BORDER_STYLE, handle);
    setPropertyChangeHandler(PROP_BORDER_WIDTH, handle);
    setPropertyChangeHandler(PROP_FONT, handle);
}
Also used : PROP_PVVALUE(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE) Arrays(java.util.Arrays) PROP_BORDER_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH) ComboModel(org.csstudio.opibuilder.widgets.model.ComboModel) PROP_HEIGHT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT) PROP_ITEMS_FROM_PV(org.csstudio.opibuilder.widgets.model.ComboModel.PROP_ITEMS_FROM_PV) PROP_PVNAME(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME) IFigure(org.eclipse.draw2d.IFigure) PROP_ITEMS(org.csstudio.opibuilder.widgets.model.ComboModel.PROP_ITEMS) IPV(org.yamcs.studio.data.IPV) ComboFigure(org.csstudio.opibuilder.widgets.figures.ComboFigure) IPVListener(org.yamcs.studio.data.IPVListener) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Combo(org.eclipse.swt.widgets.Combo) VTypeHelper(org.yamcs.studio.data.VTypeHelper) VEnum(org.yamcs.studio.data.vtype.VEnum) PROP_FONT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_FONT) List(java.util.List) VType(org.yamcs.studio.data.vtype.VType) AbstractPVWidgetEditPart(org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PROP_BORDER_STYLE(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE) PROP_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) SelectionListener(org.eclipse.swt.events.SelectionListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) List(java.util.List) ComboFigure(org.csstudio.opibuilder.widgets.figures.ComboFigure)

Aggregations

VType (org.yamcs.studio.data.vtype.VType)8 PROP_PVNAME (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME)6 PROP_PVVALUE (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE)6 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)6 VTypeHelper (org.yamcs.studio.data.VTypeHelper)6 AbstractPVWidgetEditPart (org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart)5 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)5 IFigure (org.eclipse.draw2d.IFigure)5 List (java.util.List)4 IPV (org.yamcs.studio.data.IPV)4 IPVListener (org.yamcs.studio.data.IPVListener)4 VEnum (org.yamcs.studio.data.vtype.VEnum)4 PROP_BORDER_STYLE (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_STYLE)3 PROP_BORDER_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_BORDER_WIDTH)3 ITextFigure (org.csstudio.swt.widgets.figures.ITextFigure)3 EditPolicy (org.eclipse.gef.EditPolicy)3 Request (org.eclipse.gef.Request)3 RequestConstants (org.eclipse.gef.RequestConstants)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2