Example usage for org.eclipse.jface.viewers IDecoration IDecoration

List of usage examples for org.eclipse.jface.viewers IDecoration IDecoration

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers IDecoration IDecoration.

Prototype

IDecoration

Source Link

Usage

From source file:com.rcpcompany.uibindings.extests.bindingMessages.LabelDecoratorTest.java

License:Open Source License

/**
 * Tests whether the element - if it is an {@link EObject} - has the specified message type and
 * whether the specified decorator has the specified decoration.
 * /*from   w  w w .j  a  v  a  2  s  .c  o  m*/
 * @param labelDecorator the decorator
 * @param element the element in question
 * @param messageType the expected message for the element
 * @param decorationType the expected decoration for the element
 */
private void testLD(ValidationLabelDecorator labelDecorator, Object element, int messageType,
        int decorationType) {
    if (element instanceof EObject) {
        assertEquals(messageType, myValidatorManager.getObjectSeverity((EObject) element));
    }
    if (decorationType == -1) {
        decorationType = messageType;
    }

    myCurrentOverlay = null;
    final IDecoration decoration = new IDecoration() {

        @Override
        public void setForegroundColor(Color color) {
            fail();
        }

        @Override
        public void setFont(Font font) {
            fail();
        }

        @Override
        public void setBackgroundColor(Color color) {
            fail();
        }

        @Override
        public IDecorationContext getDecorationContext() {
            return DecorationContext.DEFAULT_CONTEXT;
        }

        @Override
        public void addSuffix(String suffix) {
            fail();
        }

        @Override
        public void addPrefix(String prefix) {
            fail();
        }

        @Override
        public void addOverlay(ImageDescriptor overlay, int quadrant) {
            fail();
        }

        @Override
        public void addOverlay(ImageDescriptor overlay) {
            assertEquals(null, myCurrentOverlay);
            assertNotNull(overlay);
            myCurrentOverlay = overlay;
        }
    };
    labelDecorator.decorate(element, decoration);
    assertEquals(decorationType, labelDecorator.getElementSeverity(element));
    switch (decorationType) {
    case IMessageProvider.NONE:
        // No overlay expected
        assertEquals(null, myCurrentOverlay);
        break;
    case IMessageProvider.INFORMATION:
        // No overlay expected
        assertEquals(null, myCurrentOverlay);
        break;
    case IMessageProvider.WARNING:
        assertEquals(ValidationLabelDecorator.WARNING_IMAGE, myCurrentOverlay);
        break;
    case IMessageProvider.ERROR:
        assertEquals(ValidationLabelDecorator.ERROR_IMAGE, myCurrentOverlay);
        break;
    }
}

From source file:com.rcpcompany.uibindings.internal.decorators.extenders.ViewerSpecificLabelDecoratorExtender.java

License:Open Source License

@Override
public void extend(final IUIBindingDecoratorExtenderContext context) {
    final ValidationLabelDecorator labelDecorator = getLabelDecorator(context.getBinding());

    if (labelDecorator == null)
        return;//from   w  w w.  j  ava2  s.co m

    /*
     * We want to be notified next time the decorator changes...
     * 
     * Note that we expect the decorator to conform to the comment of #addListener(): "Adds a
     * listener to this label provider. Has no effect if an identical listener is already
     * registered.".
     * 
     * This is done this way to avoid any references from the extender to the decorator, as
     * these can be problematic when garbage collecting...
     */
    labelDecorator.addListener(this);

    final EObject element = context.getBinding().getModelObject();

    final IDecoration decoration = new IDecoration() {
        @Override
        public void addPrefix(String prefix) {
            // TODO
        }

        @Override
        public void addSuffix(String suffix) {
            // TODO
        }

        @Override
        public void addOverlay(ImageDescriptor overlay) {
            final DecorationPosition pos = IManager.Factory.getManager().getMessageDecorationPosition();
            switch (pos) {
            case TOP_LEFT:
            case CENTER_LEFT:
                addOverlay(overlay, IDecoration.TOP_LEFT);
                break;
            case BOTTOM_LEFT:
                addOverlay(overlay, IDecoration.BOTTOM_LEFT);
                break;
            case TOP_RIGHT:
            case CENTER_RIGHT:
                addOverlay(overlay, IDecoration.TOP_RIGHT);
                break;
            case BOTTOM_RIGHT:
                addOverlay(overlay, IDecoration.BOTTOM_RIGHT);
                break;
            default:
                LogUtils.error(this, "Unknown position: " + pos);
                addOverlay(overlay, IDecoration.TOP_LEFT);
                break;
            }
        }

        @Override
        public void addOverlay(ImageDescriptor overlay, int quadrant) {
            final Image image = getResourceManager().createImage(overlay);
            switch (quadrant) {
            case IDecoration.BOTTOM_LEFT:
                context.setDecoratingImage(DecorationPosition.BOTTOM_LEFT, false, image, null);
                break;
            case IDecoration.TOP_LEFT:
                context.setDecoratingImage(DecorationPosition.TOP_LEFT, false, image, null);
                break;
            case IDecoration.BOTTOM_RIGHT:
                context.setDecoratingImage(DecorationPosition.BOTTOM_RIGHT, false, image, null);
                break;
            case IDecoration.TOP_RIGHT:
                context.setDecoratingImage(DecorationPosition.TOP_RIGHT, false, image, null);
                break;
            case IDecoration.REPLACE:
                context.setImage(image);
                break;
            default:
                LogUtils.error(this, "Unknown quadrant: " + quadrant);
                break;
            }
        }

        @Override
        public void setForegroundColor(Color color) {
            context.setForegound(color);
        }

        @Override
        public void setBackgroundColor(Color color) {
            context.setBackgound(color);
        }

        @Override
        public void setFont(Font font) {
            context.setFont(font);
        }

        @Override
        public IDecorationContext getDecorationContext() {
            return DecorationContext.DEFAULT_CONTEXT;
        }
    };
    labelDecorator.decorate(element, decoration);
}