Search in sources :

Example 1 with AbstractBoolFigure

use of org.csstudio.swt.widgets.figures.AbstractBoolFigure 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() {
    // value
    IWidgetPropertyChangeHandler handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            if (newValue == null || !(newValue instanceof VType))
                return false;
            AbstractBoolFigure 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(AbstractPVWidgetModel.PROP_PVVALUE, handler);
    // bit
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            if (getWidgetModel().getDataType() != 0)
                return false;
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setBit((Integer) newValue);
            updateFromValue(getPVValue(AbstractPVWidgetModel.PROP_PVNAME), figure);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_BIT, handler);
    // data type
    final IWidgetPropertyChangeHandler dataTypeHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            if ((Integer) newValue == 0)
                figure.setBit(getWidgetModel().getBit());
            else
                figure.setBit(-1);
            updateFromValue(getPVValue(AbstractPVWidgetModel.PROP_PVNAME), figure);
            updatePropSheet((Integer) newValue);
            return true;
        }
    };
    getWidgetModel().getProperty(AbstractBoolWidgetModel.PROP_DATA_TYPE).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            dataTypeHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
        }
    });
    // on state
    handler = new IWidgetPropertyChangeHandler() {

        public boolean handleChange(Object oldValue, Object newValue, IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            updateFromValue(getPVValue(AbstractPVWidgetModel.PROP_PVNAME), figure);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_ON_STATE, handler);
    // show bool label
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setShowBooleanLabel((Boolean) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_SHOW_BOOL_LABEL, handler);
    // bool label position
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setBoolLabelPosition(BoolLabelPosition.values()[(Integer) newValue]);
            return false;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_BOOL_LABEL_POS, handler);
    // on label
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setOnLabel((String) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_ON_LABEL, handler);
    // off label
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setOffLabel((String) newValue);
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_OFF_LABEL, handler);
    // on color
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setOnColor(((OPIColor) newValue).getSWTColor());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_ON_COLOR, handler);
    // off color
    handler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            AbstractBoolFigure figure = (AbstractBoolFigure) refreshableFigure;
            figure.setOffColor(((OPIColor) newValue).getSWTColor());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractBoolWidgetModel.PROP_OFF_COLOR, handler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) VType(org.diirt.vtype.VType) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) AbstractBoolFigure(org.csstudio.swt.widgets.figures.AbstractBoolFigure) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 AbstractBoolFigure (org.csstudio.swt.widgets.figures.AbstractBoolFigure)1 VType (org.diirt.vtype.VType)1 IFigure (org.eclipse.draw2d.IFigure)1