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

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

Introduction

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

Prototype

void addOverlay(ImageDescriptor overlay);

Source Link

Document

Adds an overlay to the element's image.

Usage

From source file:org.eclipse.ui.internal.ide.ContentTypeDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    if (!(element instanceof IFile))
        return;// w w  w  .j  a  v a 2 s .  c  o m
    IWorkbench workbench = PlatformUI.getWorkbench();
    if (workbench.isClosing())
        return;

    IFile file = (IFile) element;
    ImageDescriptor image = null;

    if (hasEditorAssociationOverrides()) {
        IEditorDescriptor d = IDE.getDefaultEditor(file);
        if (d != null)
            image = d.getImageDescriptor();
    } else {
        IContentDescription contentDescription = null;
        try {
            Job.getJobManager().beginRule(file, null);
            contentDescription = file.getContentDescription();
        } catch (CoreException e) {
            // We already have some kind of icon for this file so it's OK to not
            // find a better icon.
        } finally {
            Job.getJobManager().endRule(file);
        }

        if (contentDescription != null) {
            IContentType contentType = contentDescription.getContentType();
            if (contentType != null) {
                image = workbench.getEditorRegistry().getImageDescriptor(file.getName(), contentType);
            }
        }
    }

    // add the image descriptor as a session property so that it will be
    // picked up by the workbench label provider upon the next update.
    try {
        if (file.getSessionProperty(WorkbenchFile.IMAGE_CACHE_KEY) != image)
            file.setSessionProperty(WorkbenchFile.IMAGE_CACHE_KEY, image);
    } catch (CoreException e) {
        // ignore - not being able to cache the image is not fatal
    }
    if (image != null)
        decoration.addOverlay(image);
}

From source file:org.eclipse.ui.internal.ide.LinkedResourceDecorator.java

License:Open Source License

/**
 * Adds the linked resource overlay if the given element is a linked
 * resource./*from  ww w .j  a v a2 s  .  c o m*/
 * 
 * @param element element to decorate
 * @param decoration  The decoration we are adding to
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(Object, IDecoration)
 */
public void decorate(Object element, IDecoration decoration) {

    if (element instanceof IResource == false) {
        return;
    }
    IResource resource = (IResource) element;
    if (resource.isLinked() && !resource.isVirtual()) {
        IFileInfo fileInfo = null;
        URI location = resource.getLocationURI();
        if (location != null) {
            fileInfo = IDEResourceInfoUtils.getFileInfo(location);
        }
        if (fileInfo != null && fileInfo.exists()) {
            decoration.addOverlay(LINK);
        } else {
            decoration.addOverlay(LINK_WARNING);
        }
    }

}

From source file:org.eclipse.ui.internal.ide.SymlinkDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    if (element instanceof ResourceMapping)
        element = ((ResourceMapping) element).getModelObject();
    if (element instanceof IAdaptable)
        element = ((IAdaptable) element).getAdapter(IResource.class);
    if (element instanceof IResource) {
        IResource resource = (IResource) element;
        ResourceAttributes resourceAttributes = resource.getResourceAttributes();
        if (resourceAttributes != null && resourceAttributes.isSymbolicLink())
            decoration.addOverlay(SYMLINK);
    }/*from w w  w. j a v  a 2 s. c o  m*/
}

From source file:org.eclipse.ui.tests.decorators.TestLightweightDecoratorContributor.java

License:Open Source License

/**
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object, org.eclipse.jface.viewers.IDecoration)
 *///from  w  ww. j  a  v a 2  s .  c o  m
public void decorate(Object element, IDecoration decoration) {
    decoration.addOverlay(getOverlay(element));
    decoration.addPrefix(DECORATOR_PREFIX);
    decoration.addSuffix(DECORATOR_SUFFIX);
}

From source file:org.eclipse.wst.jsdt.ui.OverrideIndicatorLabelDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    int adornmentFlags = computeAdornmentFlags(element);
    if ((adornmentFlags & JavaScriptElementImageDescriptor.IMPLEMENTS) != 0) {
        if ((adornmentFlags & JavaScriptElementImageDescriptor.SYNCHRONIZED) != 0) {
            decoration.addOverlay(JavaPluginImages.DESC_OVR_SYNCH_AND_IMPLEMENTS);
        } else {/*from   www .  jav a 2 s .c  om*/
            decoration.addOverlay(JavaPluginImages.DESC_OVR_IMPLEMENTS);
        }
    } else if ((adornmentFlags & JavaScriptElementImageDescriptor.OVERRIDES) != 0) {
        if ((adornmentFlags & JavaScriptElementImageDescriptor.SYNCHRONIZED) != 0) {
            decoration.addOverlay(JavaPluginImages.DESC_OVR_SYNCH_AND_OVERRIDES);
        } else {
            decoration.addOverlay(JavaPluginImages.DESC_OVR_OVERRIDES);
        }
    }
}

From source file:org.eclipsetrader.news.internal.ui.NewsDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    if (enabled) {
        if (element instanceof IViewItem) {
            IViewItem viewItem = (IViewItem) element;
            ISecurity security = (ISecurity) viewItem.getAdapter(ISecurity.class);
            if (security != null) {
                if (newsService.hasUnreadedHeadLinesFor(security)) {
                    decoration.addOverlay(unreadedDescriptor);
                } else if (newsService.hasHeadLinesFor(security)) {
                    decoration.addOverlay(readedDescriptor);
                }/*from   w  w w.  j ava 2  s.co m*/
            }
        }
    }
}

From source file:org.fusesource.ide.project.decorator.CamelProblemDecorator.java

License:Open Source License

/**
 * @param cme/*from  w  ww .  j av a2 s.c  om*/
 * @param decoration
 */
private void decorationForCamelModelElement(AbstractCamelModelElement cme, IDecoration decoration) {
    try {
        for (IMarker marker : getFuseMarkers(cme)) {
            String id = (String) marker.getAttribute(IFuseMarker.CAMEL_ID);
            if (id != null && id.equals(cme.getId())) {
                decoration.addOverlay(getOverlay((int) marker.getAttribute(IMarker.SEVERITY)));
                return;
            }
        }
    } catch (CoreException e) {
        Activator.getLogger().error(e);
    }

}

From source file:org.fusesource.ide.project.decorator.CamelProblemDecorator.java

License:Open Source License

/**
 * @param element//from  w  ww . j  a  v a  2  s .co  m
 * @param decoration
 */
private void decorationForCamelVirtualFolder(Object element, IDecoration decoration) {
    for (IResource resource : ((CamelVirtualFolder) element).getCamelFiles()) {
        try {
            int maxProblemSeverity = resource.findMaxProblemSeverity(IMarker.PROBLEM, true,
                    IResource.DEPTH_ZERO);
            decoration.addOverlay(getOverlay(maxProblemSeverity));
        } catch (CoreException e) {
            Activator.getLogger().error(e);
        }
    }
}

From source file:org.fusesource.ide.project.decorator.CamelProblemDecorator.java

License:Open Source License

/**
 * @param camelRoute//from   w w  w .java 2  s  .c  om
 * @param decoration
 */
private void decorationForCamelRoute(CamelRouteElement camelRoute, IDecoration decoration) {
    try {
        for (IMarker marker : getFuseMarkers(camelRoute)) {
            String id = (String) marker.getAttribute(IFuseMarker.CAMEL_ID);
            if (id != null && isInsideRoute(camelRoute, id)) {
                decoration.addOverlay(getOverlay((int) marker.getAttribute(IMarker.SEVERITY)));
                return;
            }
        }
    } catch (CoreException e) {
        Activator.getLogger().error(e);
    }
}

From source file:org.gluster.storage.management.console.views.NavigationTreeLabelDecorator.java

License:Open Source License

@SuppressWarnings("rawtypes")
@Override//from w  w  w.j  a v a  2 s. co m
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof Volume) {
        Volume volume = (Volume) element;
        if (volume.getStatus() == Volume.VOLUME_STATUS.OFFLINE) {
            decoration.addOverlay(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,
                    IImageKeys.OVERLAY_OFFLINE_8x8));
        } else {
            decoration.addOverlay(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,
                    IImageKeys.OVERLAY_ONLINE_8x8));
        }
    }

    if (element instanceof GlusterServer) {
        GlusterServer server = (GlusterServer) element;
        if (server.getStatus() == GlusterServer.SERVER_STATUS.OFFLINE) {
            decoration.addOverlay(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,
                    IImageKeys.OVERLAY_OFFLINE_8x8));
        } else {
            decoration.addOverlay(AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID,
                    IImageKeys.OVERLAY_ONLINE_8x8));
        }
    }

    if (element instanceof Server) {
        decoration.addOverlay(
                AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.OVERLAY_STAR_8x8));
    }

    if (element instanceof EntityGroup && ((EntityGroup) element).getEntityType() == Server.class) {
        decoration.addOverlay(
                AbstractUIPlugin.imageDescriptorFromPlugin(Application.PLUGIN_ID, IImageKeys.OVERLAY_STAR_8x8));
    }
}