Search in sources :

Example 1 with AbstractBoolWidgetModel

use of org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel in project yamcs-studio by yamcs.

the class AbstractBoolControlEditPart 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()}.
 */
@Override
protected void registerCommonPropertyChangeHandlers() {
    configureButtonListener((AbstractBoolControlFigure) getFigure());
    super.registerCommonPropertyChangeHandlers();
    IWidgetPropertyChangeHandler toggleHandler = (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolControlFigure) refreshableFigure;
        figure.setToggle((Boolean) newValue);
        return true;
    };
    getWidgetModel().getProperty(PROP_TOGGLE_BUTTON).addPropertyChangeListener(evt -> toggleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure()));
    setPropertyChangeHandler(PROP_CONFIRM_DIALOG, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolControlFigure) refreshableFigure;
        figure.setShowConfirmDialog(getWidgetModel().getShowConfirmDialog());
        return true;
    });
    setPropertyChangeHandler(PROP_CONFIRM_TIP, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolControlFigure) refreshableFigure;
        figure.setConfirmTip((String) newValue);
        return true;
    });
    setPropertyChangeHandler(PROP_PASSWORD, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolControlFigure) refreshableFigure;
        figure.setPassword((String) newValue);
        return true;
    });
    // enabled. WidgetBaseEditPart will force the widget as disabled in edit model,
    // which is not the case for the bool control widget
    setPropertyChangeHandler(PROP_ENABLED, (oldValue, newValue, refreshableFigure) -> {
        var figure = (AbstractBoolControlFigure) refreshableFigure;
        figure.setEnabled((Boolean) newValue);
        return true;
    });
}
Also used : PROP_PVVALUE(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE) AbstractBoolFigure(org.csstudio.swt.widgets.figures.AbstractBoolFigure) PROP_CONFIRM_TIP(org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_CONFIRM_TIP) PROP_PASSWORD(org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_PASSWORD) PROP_ENABLED(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ENABLED) AbstractBaseEditPart(org.csstudio.opibuilder.editparts.AbstractBaseEditPart) PROP_PVNAME(org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME) PROP_CONFIRM_DIALOG(org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_CONFIRM_DIALOG) AbstractBoolWidgetModel(org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel) AbstractBoolControlFigure(org.csstudio.swt.widgets.figures.AbstractBoolControlFigure) PROP_TOGGLE_BUTTON(org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_TOGGLE_BUTTON) AbstractBoolControlModel(org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractBoolControlFigure(org.csstudio.swt.widgets.figures.AbstractBoolControlFigure)

Example 2 with AbstractBoolWidgetModel

use of org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel 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)2 PROP_PVNAME (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVNAME)2 PROP_PVVALUE (org.csstudio.opibuilder.model.IPVWidgetModel.PROP_PVVALUE)2 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)2 AbstractBoolWidgetModel (org.csstudio.opibuilder.widgets.model.AbstractBoolWidgetModel)2 AbstractBoolFigure (org.csstudio.swt.widgets.figures.AbstractBoolFigure)2 AbstractPVWidgetEditPart (org.csstudio.opibuilder.editparts.AbstractPVWidgetEditPart)1 ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)1 PROP_ENABLED (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_ENABLED)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 AbstractBoolControlModel (org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel)1 PROP_CONFIRM_DIALOG (org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_CONFIRM_DIALOG)1 PROP_CONFIRM_TIP (org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_CONFIRM_TIP)1 PROP_PASSWORD (org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_PASSWORD)1 PROP_TOGGLE_BUTTON (org.csstudio.opibuilder.widgets.model.AbstractBoolControlModel.PROP_TOGGLE_BUTTON)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