Search in sources :

Example 1 with ActionButtonFigure

use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.

the class Draw2DButtonEditPartDelegate method doCreateFigure.

/* (non-Javadoc)
     * @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#doCreateFigure()
     */
@Override
public IFigure doCreateFigure() {
    ActionButtonModel model = editpart.getWidgetModel();
    final ActionButtonFigure buttonFigure = new ActionButtonFigure(editpart.getExecutionMode() == ExecutionMode.RUN_MODE);
    buttonFigure.setText(model.getText());
    buttonFigure.setToggleStyle(model.isToggleButton());
    buttonFigure.setImagePath(model.getImagePath());
    editpart.updatePropSheet();
    return buttonFigure;
}
Also used : ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure) ActionButtonModel(org.csstudio.opibuilder.widgets.model.ActionButtonModel)

Example 2 with ActionButtonFigure

use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.

the class Draw2DButtonEditPartDelegate method registerPropertyChangeHandlers.

/* (non-Javadoc)
     * @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#registerPropertyChangeHandlers()
     */
@Override
public void registerPropertyChangeHandlers() {
    // text
    IWidgetPropertyChangeHandler textHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
            figure.setText(newValue.toString());
            figure.calculateTextPosition();
            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) {
            ActionButtonFigure figure = (ActionButtonFigure) 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);
    // width
    IWidgetPropertyChangeHandler widthHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
            Integer height = (Integer) editpart.getPropertyValue(ActionButtonModel.PROP_HEIGHT);
            figure.calculateTextPosition((Integer) newValue, height);
            return true;
        }
    };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_WIDTH, widthHandler);
    // height
    IWidgetPropertyChangeHandler heightHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
            Integer width = (Integer) editpart.getPropertyValue(ActionButtonModel.PROP_WIDTH);
            figure.calculateTextPosition(width, (Integer) newValue);
            return true;
        }
    };
    editpart.setPropertyChangeHandler(ActionButtonModel.PROP_HEIGHT, heightHandler);
    // button style
    final IWidgetPropertyChangeHandler buttonStyleHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            ActionButtonFigure figure = (ActionButtonFigure) refreshableFigure;
            figure.setToggleStyle((Boolean) newValue);
            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) ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with ActionButtonFigure

use of org.csstudio.swt.widgets.figures.ActionButtonFigure in project yamcs-studio by yamcs.

the class Draw2DButtonEditPartDelegate method hookMouseClickAction.

/* (non-Javadoc)
     * @see org.csstudio.opibuilder.widgets.editparts.IButtonEditPartDelegate#hookMouseClickAction()
     */
@Override
public void hookMouseClickAction() {
    ((ActionButtonFigure) editpart.getFigure()).addActionListener(new ButtonActionListener() {

        @Override
        public void actionPerformed(int mouseEventState) {
            List<AbstractWidgetAction> actions = editpart.getHookedActions();
            if (actions != null) {
                for (AbstractWidgetAction action : actions) {
                    if (action instanceof OpenDisplayAction)
                        ((OpenDisplayAction) action).runWithModifiers((mouseEventState & SWT.CONTROL) != 0, (mouseEventState & SWT.SHIFT) != 0);
                    else
                        action.run();
                }
            }
        }
    });
}
Also used : OpenDisplayAction(org.csstudio.opibuilder.widgetActions.OpenDisplayAction) List(java.util.List) ActionButtonFigure(org.csstudio.swt.widgets.figures.ActionButtonFigure) ButtonActionListener(org.csstudio.swt.widgets.figures.ActionButtonFigure.ButtonActionListener) AbstractWidgetAction(org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)

Aggregations

ActionButtonFigure (org.csstudio.swt.widgets.figures.ActionButtonFigure)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 List (java.util.List)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 AbstractWidgetAction (org.csstudio.opibuilder.widgetActions.AbstractWidgetAction)1 OpenDisplayAction (org.csstudio.opibuilder.widgetActions.OpenDisplayAction)1 ActionButtonModel (org.csstudio.opibuilder.widgets.model.ActionButtonModel)1 ButtonActionListener (org.csstudio.swt.widgets.figures.ActionButtonFigure.ButtonActionListener)1 IPath (org.eclipse.core.runtime.IPath)1 IFigure (org.eclipse.draw2d.IFigure)1