Search in sources :

Example 1 with PROP_DATA_TYPE

use of org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_DATA_TYPE 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)

Aggregations

AbstractBaseEditPart (org.csstudio.opibuilder.editparts.AbstractBaseEditPart)1 AbstractPVWidgetEditPart (org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart)1 PROP_PVNAME (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME)1 PROP_PVVALUE (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 AbstractBoolWidgetModel (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel)1 PROP_BIT (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_BIT)1 PROP_BOOL_LABEL_POS (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_BOOL_LABEL_POS)1 PROP_DATA_TYPE (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_DATA_TYPE)1 PROP_OFF_COLOR (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_COLOR)1 PROP_OFF_LABEL (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_LABEL)1 PROP_OFF_STATE (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_OFF_STATE)1 PROP_ON_COLOR (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_COLOR)1 PROP_ON_LABEL (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_LABEL)1 PROP_ON_STATE (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_ON_STATE)1 PROP_SHOW_BOOL_LABEL (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel.PROP_SHOW_BOOL_LABEL)1 AbstractBoolFigure (org.csstudio.swt.widgets.figures.AbstractBoolFigure)1 BoolLabelPosition (org.csstudio.swt.widgets.figures.AbstractBoolFigure.BoolLabelPosition)1 TotalBits (org.csstudio.swt.widgets.figures.AbstractBoolFigure.TotalBits)1