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

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

Introduction

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

Prototype

public DecorationOverlayIcon(Image baseImage, ImageDescriptor[] overlaysArray) 

Source Link

Document

Create the decoration overlay for the base image using the array of provided overlays.

Usage

From source file:org.eclipse.cdt.ui.SharedImagesFactory.java

License:Open Source License

/**
 * Retrieves an overlaid image from the internal repository of images.
 * If there is no image one will be created.
 *
 * The decoration overlay for the base image will use the array of
 * provided overlays. The indices of the array correspond to the values
 * of the 5 overlay constants defined on {@link IDecoration}, i.e.
 * {@link IDecoration#TOP_LEFT},/*from  w w  w . j  a  v  a 2  s  .c  o  m*/
 * {@link IDecoration#TOP_RIGHT},
 * {@link IDecoration#BOTTOM_LEFT},
 * {@link IDecoration#BOTTOM_RIGHT} or
 * {@link IDecoration#UNDERLAY}.
 *
 * @param baseKey the base image key.
 * @param overlayKeys the keys for the overlay images. Must be
 *    String[5], i.e. string array of 5 elements. Put {@code null} as
 *    an element to the array if no overlay should be added in given quadrant.
 */
public Image getImageOverlaid(String baseKey, String[] overlayKeys) {
    Assert.isTrue(overlayKeys.length == 5);

    String suffix = ""; //$NON-NLS-1$
    for (int i = 0; i < 5; i++) {
        String overlayKey = ""; //$NON-NLS-1$
        if (i < overlayKeys.length && overlayKeys[i] != null) {
            overlayKey = overlayKeys[i];
        }
        suffix = suffix + OVERLAY_SEPARATOR + overlayKey;
    }
    if (suffix.length() == 5) {
        // No overlays added
        Image result = getImage(baseKey);
        return result;
    }
    String compositeKey = baseKey + suffix;

    Image result = imageRegistry.get(compositeKey);
    if (result != null)
        return result;

    Image baseImage = getImage(baseKey);
    ImageDescriptor[] overlayDescriptors = new ImageDescriptor[5];
    for (int i = 0; i < 5; i++) {
        String overlayKey = overlayKeys[i];
        if (overlayKey != null) {
            overlayDescriptors[i] = getImageDescriptor(overlayKey);
        }
    }
    ImageDescriptor compositeDescriptor = new DecorationOverlayIcon(baseImage, overlayDescriptors);
    imageRegistry.put(compositeKey, compositeDescriptor);
    result = imageRegistry.get(compositeKey);
    return result;
}

From source file:org.eclipse.dltk.javascript.internal.ui.JSModelLabelProvider.java

License:Open Source License

public Image getImage(Object element) {
    if (element instanceof IMember) {
        final IMember method = (IMember) element;
        int flags;
        try {//from w w  w . j  av a 2  s . c  o m
            flags = method.getFlags();
        } catch (ModelException e) {
            flags = 0;
        }
        if ((flags & JSModifiers.DEPRECATED) != 0) {
            ImageDescriptor imageDescriptor = null;
            ImageDescriptor[] overlay = new ImageDescriptor[5];
            overlay[IDecoration.UNDERLAY] = DLTKPluginImages.DESC_OVR_DEPRECATED;
            if (element instanceof IMethod) {
                try {
                    if (((IMethod) element).isConstructor()) {
                        overlay[IDecoration.TOP_RIGHT] = DLTKPluginImages.DESC_OVR_CONSTRUCTOR;
                    }
                } catch (ModelException e) {
                }
                imageDescriptor = ScriptElementImageProvider.getMethodImageDescriptor(flags);
            } else if (element instanceof IField) {
                imageDescriptor = ScriptElementImageProvider.getFieldImageDescriptor(flags);
            } else {
                imageDescriptor = ScriptElementImageProvider.getTypeImageDescriptor(flags, false);
            }
            return registry.get(new DecorationOverlayIcon(registry.get(imageDescriptor), overlay));
        }
    }
    return null;
}

From source file:org.eclipse.dltk.ruby.internal.ui.editor.RubyOutlineLabelDecorator.java

License:Open Source License

public Image decorateImage(Image image, Object obj) {
    try {/*ww w  . j  a v a2 s. c om*/
        if (obj instanceof IMember) {
            final IMember member = (IMember) obj;
            if (member.exists()) {
                final int flags = member.getFlags();
                final ImageDescriptor left = getTopLeft(flags);
                final ImageDescriptor right = getTopRight(flags);
                if (left != null || right != null) {
                    final ImageDescriptor[] decorations = new ImageDescriptor[5];
                    decorations[IDecoration.TOP_LEFT] = left;
                    decorations[IDecoration.TOP_RIGHT] = right;
                    return registry.get(new DecorationOverlayIcon(image, decorations));
                }
            }
        }
    } catch (ModelException e) {
        if (DLTKCore.DEBUG) {
            e.printStackTrace();
        }
    }
    return image;
}

From source file:org.eclipse.mylyn.internal.builds.ui.view.BuildLabelProvider.java

License:Open Source License

@Override
public Image getImage(Object element) {
    ImageDescriptor descriptor = null;/*w w  w . jav  a  2s .c  o m*/
    ImageDescriptor bottomLeftDecoration = null;
    ImageDescriptor bottomRightDecoration = null;
    ImageDescriptor topRightDecoration = null;

    // bottom left decoration
    if (element instanceof IBuildElement) {
        bottomLeftDecoration = getBottomLeftDecoration((IBuildElement) element);
    }

    // main image
    if (element instanceof IBuildServer) {
        if (((IBuildServer) element).getLocation().isOffline()) {
            descriptor = BuildImages.SERVER_DISABLED;
        } else {
            descriptor = BuildImages.SERVER;
        }
    } else if (element instanceof IBuildPlan) {
        descriptor = getImageDescriptor(((IBuildPlan) element).getStatus());
        bottomRightDecoration = getBottomRightDecoration(((IBuildPlan) element).getState());
        topRightDecoration = getTopRightDecoration(((IBuildPlan) element).getFlags());
    } else if (element instanceof IBuild) {
        descriptor = BuildLabelProvider.getImageDescriptor(((IBuild) element).getStatus());
        bottomRightDecoration = getBottomRightDecoration(((IBuild) element).getState());
    }

    if (descriptor != null) {
        if (bottomRightDecoration != null || bottomLeftDecoration != null || topRightDecoration != null) {
            descriptor = new DecorationOverlayIcon(CommonImages.getImage(descriptor), new ImageDescriptor[] {
                    null, topRightDecoration, bottomLeftDecoration, bottomRightDecoration });
        }
        return CommonImages.getImage(descriptor);
    }
    return null;
}

From source file:org.eclipse.mylyn.reviews.r4e.ui.internal.navigator.ReviewNavigatorDecorator.java

License:Open Source License

/**
 * Method decorateImage./*from   w w w  . j av a2  s . c o  m*/
 * 
 * @param aBaseImage
 *            Image
 * @param aElement
 *            Object
 * @return Image
 * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(Image, Object)
 */
public Image decorateImage(Image aBaseImage, Object aElement) { // $codepro.audit.disable

    //If the image is not already loaded, do it here
    Image currentOverlayImage;
    if (null != aBaseImage) {
        currentOverlayImage = aBaseImage;
    } else {
        currentOverlayImage = ((IR4EUIModelElement) aElement)
                .getImage(((IR4EUIModelElement) aElement).getImageLocation());
    }

    ImageDescriptor topLeftOverlay = null;
    String topLeftOverlayId = ""; //$NON-NLS-1$

    ImageDescriptor topRightOverlay = null;
    String topRightOverlayId = ""; //$NON-NLS-1$

    ImageDescriptor bottomLeftOverlay = null;
    String bottomLeftOverlayId = ""; //$NON-NLS-1$

    ImageDescriptor bottomRightOverlay = null;
    String bottomRightOverlayId = ""; //$NON-NLS-1$

    ImageRegistry registry = R4EUIPlugin.getDefault().getImageRegistry();

    //Disabled element decorator
    if (!((IR4EUIModelElement) aElement).isEnabled()) {
        bottomRightOverlay = ImageDescriptor
                .createFromImage(((IR4EUIModelElement) aElement).getDisabledImage());
        bottomRightOverlayId = DECORATOR_DISABLED_ID;
    } else {
        if (((IR4EUIModelElement) aElement).isUserReviewed() || (aElement instanceof R4EUIAnomalyExtended
                && ((R4EUIAnomalyExtended) aElement).isTerminalState())) {
            //Completed element decorator
            bottomRightOverlay = ImageDescriptor
                    .createFromImage(((IR4EUIModelElement) aElement).getUserReviewedImage());
            bottomRightOverlayId = DECORATOR_REVIEWED_ID;
        }

        //Added, Removed or Modified file
        if (aElement instanceof R4EUIFileContext) {
            if (null == ((R4EUIFileContext) aElement).getBaseFileVersion()
                    && null != ((R4EUIFileContext) aElement).getTargetFileVersion()) {
                //Only target present, file was added
                bottomLeftOverlay = ImageDescriptor
                        .createFromImage(((R4EUIFileContext) aElement).getAddedImage());
                bottomLeftOverlayId = DECORATOR_ADDED_ID;
            } else if (null != ((R4EUIFileContext) aElement).getBaseFileVersion()
                    && null == ((R4EUIFileContext) aElement).getTargetFileVersion()) {
                //Only base present, file was removed
                bottomLeftOverlay = ImageDescriptor
                        .createFromImage(((R4EUIFileContext) aElement).getRemovedImage());
                bottomLeftOverlayId = DECORATOR_REMOVED_ID;
            } //else modified file
        }

        //Read-Only
        if (((IR4EUIModelElement) aElement).isReadOnly()) {
            topRightOverlay = ImageDescriptor
                    .createFromImage(((IR4EUIModelElement) aElement).getReadOnlyImage());
            topRightOverlayId = DECORATOR_READONLY_ID;
        }

        //Due date passed
        if (((IR4EUIModelElement) aElement).isDueDatePassed()) {
            topLeftOverlay = ImageDescriptor
                    .createFromImage(((IR4EUIModelElement) aElement).getDueDatePassedImage());
            topLeftOverlayId = DECORATOR_OVERDUE_ID;
        }
    }

    // Construct a new image identifier
    String baseImageId = ((IR4EUIModelElement) aElement).getImageLocation();
    String decoratedImageId = baseImageId + topLeftOverlayId + topRightOverlayId + bottomLeftOverlayId
            + bottomRightOverlayId;

    // Return the stored image if we have one
    if (registry.get(decoratedImageId) == null) {
        DecorationOverlayIcon decoratedImage = new DecorationOverlayIcon(currentOverlayImage,
                new ImageDescriptor[] { topLeftOverlay, topRightOverlay, bottomLeftOverlay, bottomRightOverlay,
                        null }) {
        };
        registry.put(decoratedImageId, decoratedImage);
    }
    return registry.get(decoratedImageId);
}

From source file:org.eclipse.objectteams.otdt.internal.ui.util.Images.java

License:Open Source License

public static Image decorateImage(Image baseImage, String overlayKey, int position) {
    ImageDescriptor[] descs = new ImageDescriptor[5];
    descs[position] = ImageManager.getSharedInstance().getDescriptor(overlayKey);
    DecorationOverlayIcon icon = new DecorationOverlayIcon(baseImage, descs);
    return JavaPlugin.getImageDescriptorRegistry().get(icon);
}

From source file:org.eclipse.rcptt.ecl.debug.ui.Images.java

License:Open Source License

private synchronized static ImageDescriptor getOverlayImageDescriptor(String key, String[] descriptorKeys) {
    ImageDescriptor[] decorators = new ImageDescriptor[descriptorKeys.length];
    for (int i = 0; i < decorators.length; i++) {
        if (descriptorKeys[i] != null) {
            decorators[i] = getImageDescriptor(descriptorKeys[i]);
        }//from   www. j a v a2s.  c  o m
    }
    return new DecorationOverlayIcon(getImage(key), decorators);
}

From source file:org.eclipse.rcptt.ecl.debug.ui.Images.java

License:Open Source License

private synchronized static ImageDescriptor getOverlayImageDescriptor(ImageDescriptor original, String key,
        String[] descriptorKeys) {
    ImageDescriptor[] decorators = new ImageDescriptor[descriptorKeys.length];
    for (int i = 0; i < decorators.length; i++) {
        if (descriptorKeys[i] != null) {
            decorators[i] = getImageDescriptor(descriptorKeys[i]);
        }/*from w ww  .ja  va  2 s .c o  m*/
    }
    return new DecorationOverlayIcon(original.createImage(), decorators);
}

From source file:org.eclipse.rcptt.tesla.jface.aspects.test.ImageSourcesTest.java

License:Open Source License

@Test
public void getImageData() {
    Image folder = SHARED_IMAGES.getImage(ISharedImages.IMG_OBJ_FOLDER);
    ImageDescriptor[] overlays = new ImageDescriptor[IDecoration.BOTTOM_RIGHT + 1];
    URL url = Platform.getBundle("org.eclipse.ui").getEntry("icons/full/ovr16/warning_ovr.png");
    overlays[IDecoration.BOTTOM_RIGHT] = ImageDescriptor.createFromURL(url);

    DecorationOverlayIcon icon = new DecorationOverlayIcon(folder, overlays);
    Image iconImage = (Image) icon.createResource(Display.getCurrent());
    try {/*from w  w w .j  av  a 2s .  co  m*/
        ImageSource imageSource = ImageSources.INSTANCE.find(iconImage);
        CompositeSource composite = (CompositeSource) imageSource;
        List<String> strings = composite.children.stream().map(Object::toString).collect(Collectors.toList());
        Assert.assertEquals(ImmutableList.of("org.eclipse.ui/icons/full/obj16/fldr_obj.png",
                "org.eclipse.ui/icons/full/ovr16/warning_ovr.png"), strings);
    } finally {
        iconImage.dispose();
    }
}

From source file:org.eclipse.sirius.ui.tools.internal.views.common.navigator.SiriusCommonLabelProvider.java

License:Open Source License

/**
 * {@inheritDoc}// ww w .  j ava2  s . c  o  m
 */
public Image getImage(Object element) {
    Image img = null;
    if (!(element instanceof IResource) && sessionLabelProvider != null) {
        try {

            // Let eclipse look for file and project icons + nature
            // decoration
            img = sessionLabelProvider.getImage(element);

            // If the current element is a dangling representation, its icon
            // is grayed. The grayed image is computed only once for each
            // type of representation.
            if (img != null && isDanglingRepresentation(element)) {
                DSemanticDecorator dSemanticDecorator = getDSemanticDecorator(element);
                String key = dSemanticDecorator.eClass().getName() + "_disabled";
                Image disabledImage = SiriusEditPlugin.getPlugin().getImageRegistry().get(key);
                if (disabledImage == null) {
                    ImageDescriptor desc = ImageDescriptor.createFromImage(img);
                    ImageDescriptor disabledDesc = ImageDescriptor.createWithFlags(desc, SWT.IMAGE_DISABLE);
                    SiriusEditPlugin.getPlugin().getImageRegistry().put(key, disabledDesc);
                    disabledImage = SiriusEditPlugin.getPlugin().getImageRegistry().get(key);
                }
                img = disabledImage;
            }
        } catch (IllegalStateException e) {
            // This can happen when trying to get the label of a CDOObject
            // which
            // Transaction has just been closed
            // Nothing to do, null will returned
        } catch (NullPointerException e) {
            // This can happen when trying to get the label of a CDOObject
            // which transaction has just been closed
            // Nothing to do, null will returned
        }
    } else if (element instanceof IFile) {
        // This file is not in a ModelingProject (check in
        // <possibleChildren> and <triggerPoints> of
        // "org.eclipse.ui.navigator.navigatorContent" of plugin.xml)
        IFile file = (IFile) element;

        if (new IFileQuery(file).isResourceHandledByOpenedSession()) {
            // Add "Sirius Modeling" overlay on this semantic file.
            String fileExtension = file.getFileExtension();
            // Create a key to store/restore the image in image registry of
            // SiriusEditPlugin
            String imgKey = fileExtension + "Decorated";
            // Get the existing image (if any)
            img = SiriusEditPlugin.getPlugin().getImageRegistry().get(imgKey);
            // If the image has already been computed, use it.
            if (img == null) {
                // Get the base image to overlay
                ImageDescriptor imageDescriptor = null;
                IWorkbenchAdapter wbAdapter = (IWorkbenchAdapter) file.getAdapter(IWorkbenchAdapter.class);
                if (wbAdapter != null) {
                    imageDescriptor = wbAdapter.getImageDescriptor(file);
                }
                if (imageDescriptor != null) {
                    // Add an overlay with the "Sirius Modeling" overlay
                    ImageDescriptor[] imageDescriptors = new ImageDescriptor[5];
                    imageDescriptors[IDecoration.TOP_RIGHT] = SIRIUS_MODELING_OVERLAY_DESC;
                    img = new DecorationOverlayIcon(imageDescriptor.createImage(), imageDescriptors)
                            .createImage();
                    SiriusEditPlugin.getPlugin().getImageRegistry().put(imgKey, img);
                }
            }
        }
    }
    return img;
}