Search in sources :

Example 1 with PROP_TEXT

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

the class Draw2DButtonEditPartDelegate method registerPropertyChangeHandlers.

@Override
public void registerPropertyChangeHandlers() {
    editpart.setPropertyChangeHandler(PROP_TEXT, (oldValue, newValue, refreshableFigure) -> {
        var figure = (ActionButtonFigure) refreshableFigure;
        figure.setText(newValue.toString());
        figure.calculateTextPosition();
        return true;
    });
    editpart.setPropertyChangeHandler(PROP_IMAGE, (oldValue, newValue, refreshableFigure) -> {
        var figure = (ActionButtonFigure) refreshableFigure;
        var absolutePath = (String) newValue;
        if (absolutePath != null && !absolutePath.contains("://")) {
            var path = Path.fromPortableString(absolutePath);
            if (!path.isAbsolute()) {
                path = ResourceUtil.buildAbsolutePath(editpart.getWidgetModel(), path);
                absolutePath = path.toPortableString();
            }
        }
        figure.setImagePath(absolutePath);
        return true;
    });
    editpart.setPropertyChangeHandler(PROP_WIDTH, (oldValue, newValue, refreshableFigure) -> {
        var figure = (ActionButtonFigure) refreshableFigure;
        var height = (Integer) editpart.getPropertyValue(PROP_HEIGHT);
        figure.calculateTextPosition((Integer) newValue, height);
        return true;
    });
    editpart.setPropertyChangeHandler(PROP_HEIGHT, (oldValue, newValue, refreshableFigure) -> {
        var figure = (ActionButtonFigure) refreshableFigure;
        var width = (Integer) editpart.getPropertyValue(PROP_WIDTH);
        figure.calculateTextPosition(width, (Integer) newValue);
        return true;
    });
    IWidgetPropertyChangeHandler buttonStyleHandler = (oldValue, newValue, refreshableFigure) -> {
        var figure = (ActionButtonFigure) refreshableFigure;
        figure.setToggleStyle((Boolean) newValue);
        editpart.updatePropSheet();
        return true;
    };
    editpart.getWidgetModel().getProperty(PROP_TOGGLE_BUTTON).addPropertyChangeListener(evt -> buttonStyleHandler.handleChange(evt.getOldValue(), evt.getNewValue(), editpart.getFigure()));
}
Also used : ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure) OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) PROP_HEIGHT(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT) ResourceUtil(org.csstudio.opibuilder.util.ResourceUtil) PROP_TEXT(org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_TEXT) IFigure(org.eclipse.draw2d.IFigure) PROP_TOGGLE_BUTTON(org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_TOGGLE_BUTTON) PROP_IMAGE(org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_IMAGE) ActionButtonModel(org.csstudio.opibuilder.widgets.model.ActionButtonModel) Path(org.eclipse.core.runtime.Path) SWT(org.eclipse.swt.SWT) PROP_WIDTH(org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH) ExecutionMode(org.csstudio.opibuilder.editparts.ExecutionMode) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure)

Aggregations

ExecutionMode (org.csstudio.opibuilder.editparts.ExecutionMode)1 PROP_HEIGHT (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_HEIGHT)1 PROP_WIDTH (org.csstudio.opibuilder.model.AbstractWidgetModel.PROP_WIDTH)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 ResourceUtil (org.csstudio.opibuilder.util.ResourceUtil)1 OpenDisplayAction (org.csstudio.opibuilder.widgetActions.OpenDisplayAction)1 ActionButtonModel (org.csstudio.opibuilder.widgets.model.ActionButtonModel)1 PROP_IMAGE (org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_IMAGE)1 PROP_TEXT (org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_TEXT)1 PROP_TOGGLE_BUTTON (org.csstudio.opibuilder.widgets.model.ActionButtonModel.PROP_TOGGLE_BUTTON)1 ActionButtonFigure (org.csstudio.swt.widgets.figures.ActionButtonFigure)1 Path (org.eclipse.core.runtime.Path)1 IFigure (org.eclipse.draw2d.IFigure)1 SWT (org.eclipse.swt.SWT)1