Search in sources :

Example 1 with NativeButtonFigure

use of org.csstudio.opibuilder.widgets.figures.NativeButtonFigure in project yamcs-studio by yamcs.

the class NativeButtonEditPart method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
protected void registerPropertyChangeHandlers() {
    // text
    IWidgetPropertyChangeHandler textHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            button.setText(newValue.toString());
            button.setSize(button.getSize());
            return true;
        }
    };
    setPropertyChangeHandler(ActionButtonModel.PROP_TEXT, textHandler);
    // image
    IWidgetPropertyChangeHandler imageHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            NativeButtonFigure figure = (NativeButtonFigure) refreshableFigure;
            IPath absolutePath = (IPath) newValue;
            if (absolutePath != null && !absolutePath.isEmpty() && !absolutePath.isAbsolute())
                absolutePath = ResourceUtil.buildAbsolutePath(getWidgetModel(), absolutePath);
            figure.setImagePath(absolutePath);
            return true;
        }
    };
    setPropertyChangeHandler(ActionButtonModel.PROP_IMAGE, imageHandler);
    // button style
    final IWidgetPropertyChangeHandler buttonStyleHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            updatePropSheet((Boolean) newValue);
            return true;
        }
    };
    getWidgetModel().getProperty(ActionButtonModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            buttonStyleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), getFigure());
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IPath(org.eclipse.core.runtime.IPath) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) NativeButtonFigure(org.csstudio.opibuilder.widgets.figures.NativeButtonFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with NativeButtonFigure

use of org.csstudio.opibuilder.widgets.figures.NativeButtonFigure in project yamcs-studio by yamcs.

the class NativeButtonEditPart method doCreateFigure.

/**
 * {@inheritDoc}
 */
@Override
protected IFigure doCreateFigure() {
    NativeButtonModel model = getWidgetModel();
    int style = SWT.None;
    style |= model.isToggleButton() ? SWT.TOGGLE : SWT.PUSH;
    style |= SWT.WRAP;
    final NativeButtonFigure buttonFigure = new NativeButtonFigure(this, style);
    button = buttonFigure.getSWTWidget();
    button.setText(model.getText());
    buttonFigure.setImagePath(model.getImagePath());
    updatePropSheet(model.isToggleButton());
    markAsControlPV(AbstractPVWidgetModel.PROP_PVNAME, AbstractPVWidgetModel.PROP_PVVALUE);
    return buttonFigure;
}
Also used : NativeButtonModel(org.csstudio.opibuilder.widgets.model.NativeButtonModel) NativeButtonFigure(org.csstudio.opibuilder.widgets.figures.NativeButtonFigure)

Example 3 with NativeButtonFigure

use of org.csstudio.opibuilder.widgets.figures.NativeButtonFigure in project yamcs-studio by yamcs.

the class NativeButtonEditPartDelegate method doCreateFigure.

@Override
public IFigure doCreateFigure() {
    ActionButtonModel model = editpart.getWidgetModel();
    int style = SWT.None;
    style |= model.isToggleButton() ? SWT.TOGGLE : SWT.PUSH;
    style |= SWT.WRAP;
    final NativeButtonFigure buttonFigure = new NativeButtonFigure(editpart, style);
    button = buttonFigure.getSWTWidget();
    button.setText(model.getText());
    button.addTraverseListener(e -> {
        if (skipTraverse)
            return;
        e.doit = false;
        skipTraverse = true;
        if (e.stateMask == 0) {
            SingleSourceHelper.swtControlTraverse(button, SWT.TRAVERSE_TAB_PREVIOUS);
        } else {
            SingleSourceHelper.swtControlTraverse(button, SWT.TRAVERSE_TAB_NEXT);
        }
        skipTraverse = false;
    });
    buttonFigure.setImagePath(model.getImagePath());
    return buttonFigure;
}
Also used : NativeButtonFigure(org.csstudio.opibuilder.widgets.figures.NativeButtonFigure) ActionButtonModel(org.csstudio.opibuilder.widgets.model.ActionButtonModel)

Example 4 with NativeButtonFigure

use of org.csstudio.opibuilder.widgets.figures.NativeButtonFigure in project yamcs-studio by yamcs.

the class NativeButtonEditPartDelegate method registerPropertyChangeHandlers.

/**
 * {@inheritDoc}
 */
@Override
public void registerPropertyChangeHandlers() {
    // text
    IWidgetPropertyChangeHandler textHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            button.setText(newValue.toString());
            button.setSize(button.getSize());
            return true;
        }
    };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_TEXT, textHandler);
    // image
    IWidgetPropertyChangeHandler imageHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            NativeButtonFigure figure = (NativeButtonFigure) refreshableFigure;
            IPath absolutePath = (IPath) newValue;
            if (absolutePath != null && !absolutePath.isEmpty() && !absolutePath.isAbsolute())
                absolutePath = ResourceUtil.buildAbsolutePath(editpart.getWidgetModel(), absolutePath);
            figure.setImagePath(absolutePath);
            return true;
        }
    };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_IMAGE, imageHandler);
    // button style
    final IWidgetPropertyChangeHandler buttonStyleHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            editpart.updatePropSheet();
            return true;
        }
    };
    editpart.getWidgetModel().getProperty(ActionButtonModel.PROP_TOGGLE_BUTTON).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            buttonStyleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), editpart.getFigure());
        }
    });
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) IPath(org.eclipse.core.runtime.IPath) PropertyChangeListener(java.beans.PropertyChangeListener) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) NativeButtonFigure(org.csstudio.opibuilder.widgets.figures.NativeButtonFigure) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

NativeButtonFigure (org.csstudio.opibuilder.widgets.figures.NativeButtonFigure)4 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)2 IPath (org.eclipse.core.runtime.IPath)2 IFigure (org.eclipse.draw2d.IFigure)2 ActionButtonModel (org.csstudio.opibuilder.widgets.model.ActionButtonModel)1 NativeButtonModel (org.csstudio.opibuilder.widgets.model.NativeButtonModel)1