Search in sources :

Example 1 with TooltipLabel

use of org.csstudio.opibuilder.visualparts.TooltipLabel in project yamcs-studio by yamcs.

the class AbstractBaseEditPart method initFigure.

/**
 * initialize the figure
 *
 * @param figure
 */
protected void initFigure(final IFigure figure) {
    if (figure == null)
        throw new IllegalArgumentException(// $NON-NLS-1$
        "Editpart does not provide a figure!");
    Set<String> allPropIds = getWidgetModel().getAllPropertyIDs();
    if (allPropIds.contains(AbstractWidgetModel.PROP_COLOR_BACKGROUND))
        figure.setBackgroundColor(CustomMediaFactory.getInstance().getColor(getWidgetModel().getBackgroundColor()));
    if (allPropIds.contains(AbstractWidgetModel.PROP_COLOR_FOREGROUND))
        figure.setForegroundColor(CustomMediaFactory.getInstance().getColor(getWidgetModel().getForegroundColor()));
    if (allPropIds.contains(AbstractWidgetModel.PROP_FONT))
        figure.setFont(getWidgetModel().getFont().getSWTFont());
    if (allPropIds.contains(AbstractWidgetModel.PROP_VISIBLE))
        figure.setVisible(getExecutionMode() == ExecutionMode.RUN_MODE ? getWidgetModel().isVisible() : true);
    if (allPropIds.contains(AbstractWidgetModel.PROP_ENABLED))
        figure.setEnabled(getWidgetModel().isEnabled());
    if (allPropIds.contains(AbstractWidgetModel.PROP_WIDTH) && allPropIds.contains(AbstractWidgetModel.PROP_HEIGHT))
        figure.setSize(getWidgetModel().getSize());
    if (allPropIds.contains(AbstractWidgetModel.PROP_BORDER_COLOR) && allPropIds.contains(AbstractWidgetModel.PROP_BORDER_STYLE) && allPropIds.contains(AbstractWidgetModel.PROP_BORDER_WIDTH))
        figure.setBorder(BorderFactory.createBorder(getWidgetModel().getBorderStyle(), getWidgetModel().getBorderWidth(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
    if (allPropIds.contains(AbstractWidgetModel.PROP_TOOLTIP)) {
        if (!getWidgetModel().getTooltip().equals("")) {
            // $NON-NLS-1$
            tooltipLabel = new TooltipLabel(this);
            figure.setToolTip(tooltipLabel);
        }
    }
    // Disable tab traversal
    figure.setFocusTraversable(false);
    figure.setRequestFocusEnabled(false);
}
Also used : TooltipLabel(org.csstudio.opibuilder.visualparts.TooltipLabel)

Example 2 with TooltipLabel

use of org.csstudio.opibuilder.visualparts.TooltipLabel in project yamcs-studio by yamcs.

the class AbstractBaseEditPart method registerBasePropertyChangeHandlers.

protected void registerBasePropertyChangeHandlers() {
    IWidgetPropertyChangeHandler refreshVisualHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            refreshVisuals();
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_XPOS, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_YPOS, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_WIDTH, refreshVisualHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_HEIGHT, refreshVisualHandler);
    // add connection should not be ignored by widget listener.
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_SRC_CONNECTIONS).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            refreshSourceConnections();
        }
    });
    getWidgetModel().getProperty(AbstractWidgetModel.PROP_TGT_CONNECTIONS).addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            refreshTargetConnections();
        }
    });
    IWidgetPropertyChangeHandler backColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setBackgroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_BACKGROUND, backColorHandler);
    IWidgetPropertyChangeHandler foreColorHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setForegroundColor(CustomMediaFactory.getInstance().getColor(((OPIColor) newValue).getRGBValue()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_COLOR_FOREGROUND, foreColorHandler);
    IWidgetPropertyChangeHandler fontHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setFont(((OPIFont) newValue).getSWTFont());
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_FONT, fontHandler);
    IWidgetPropertyChangeHandler borderHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            setFigureBorder(calculateBorder());
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_STYLE, borderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_COLOR, borderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_BORDER_WIDTH, borderHandler);
    IWidgetPropertyChangeHandler labelBorderHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (figure.getBorder() instanceof LabeledBorder)
                figure.setBorder(BorderFactory.createBorder(getWidgetModel().getBorderStyle(), getWidgetModel().getBorderWidth(), getWidgetModel().getBorderColor(), getWidgetModel().getName()));
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_NAME, labelBorderHandler);
    setPropertyChangeHandler(AbstractWidgetModel.PROP_FONT, labelBorderHandler);
    IWidgetPropertyChangeHandler enableHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            figure.setEnabled((Boolean) newValue);
            figure.repaint();
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_ENABLED, enableHandler);
    IWidgetPropertyChangeHandler tooltipHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(Object oldValue, Object newValue, IFigure figure) {
            if (// $NON-NLS-1$
            newValue.toString().equals(""))
                figure.setToolTip(null);
            else {
                if (tooltipLabel == null)
                    tooltipLabel = new TooltipLabel(AbstractBaseEditPart.this);
                figure.setToolTip(tooltipLabel);
            }
            return false;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_TOOLTIP, tooltipHandler);
    IWidgetPropertyChangeHandler visibilityHandler = new IWidgetPropertyChangeHandler() {

        @Override
        public boolean handleChange(final Object oldValue, final Object newValue, final IFigure refreshableFigure) {
            boolean visible = (Boolean) newValue;
            final IFigure figure = getFigure();
            if (getExecutionMode() == ExecutionMode.RUN_MODE) {
                figure.setVisible(visible);
            } else {
                if (!visible) {
                    figure.setVisible(false);
                    UIJob job = new UIJob("reset") {

                        @Override
                        public IStatus runInUIThread(final IProgressMonitor monitor) {
                            figure.setVisible(true);
                            return Status.OK_STATUS;
                        }
                    };
                    job.schedule(2000);
                }
            }
            return true;
        }
    };
    setPropertyChangeHandler(AbstractWidgetModel.PROP_VISIBLE, visibilityHandler);
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) WidgetPropertyChangeListener(org.csstudio.opibuilder.properties.WidgetPropertyChangeListener) TooltipLabel(org.csstudio.opibuilder.visualparts.TooltipLabel) LabeledBorder(org.eclipse.draw2d.LabeledBorder) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IWidgetPropertyChangeHandler(org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler) UIJob(org.eclipse.ui.progress.UIJob) OPIColor(org.csstudio.opibuilder.util.OPIColor) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

TooltipLabel (org.csstudio.opibuilder.visualparts.TooltipLabel)2 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 IWidgetPropertyChangeHandler (org.csstudio.opibuilder.properties.IWidgetPropertyChangeHandler)1 WidgetPropertyChangeListener (org.csstudio.opibuilder.properties.WidgetPropertyChangeListener)1 OPIColor (org.csstudio.opibuilder.util.OPIColor)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IFigure (org.eclipse.draw2d.IFigure)1 LabeledBorder (org.eclipse.draw2d.LabeledBorder)1 UIJob (org.eclipse.ui.progress.UIJob)1