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.rubypeople.rdt.ui.ProblemsLabelDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    int adornmentFlags = computeAdornmentFlags(element);
    if (adornmentFlags == ERRORTICK_ERROR) {
        decoration.addOverlay(RubyPluginImages.DESC_OVR_ERROR);
    } else if (adornmentFlags == ERRORTICK_WARNING) {
        decoration.addOverlay(RubyPluginImages.DESC_OVR_WARNING);
    }/*from   w w  w.j a  va  2  s .  co  m*/
}

From source file:org.sonarlint.eclipse.ui.internal.SonarLintProjectDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    IProject project = null;/*from ww  w.  j  av  a 2 s. c o  m*/
    if (element instanceof IProject) {
        project = (IProject) element;
    } else if (element instanceof IAdaptable) {
        project = (IProject) ((IAdaptable) element).getAdapter(IProject.class);
    }
    if (project != null && project.isAccessible()) {
        SonarLintProject p = SonarLintProject.getInstance(project);
        if (!p.isAutoEnabled()) {
            return;
        }
        if (p.getServerId() != null && ServersManager.getInstance().getServer(p.getServerId()) != null) {
            decoration.addOverlay(SonarLintImages.SQ_LABEL_DECORATOR);
        }
    }
}

From source file:org.spearce.egit.ui.internal.decorators.GitResourceDecorator.java

License:Open Source License

public void decorate(final Object element, final IDecoration decoration) {
    final IResource rsrc = toIResource(element);
    if (rsrc == null)
        return;/*from   ww  w. j av  a2 s .  c om*/

    // If the workspace has not been refreshed properly a resource might
    // not actually exist, so we ignore these and do not decorate them
    if (!rsrc.exists() && !rsrc.isPhantom()) {
        Activator.trace("Tried to decorate non-existent resource " + rsrc);
        return;
    }

    RepositoryMapping mapped = RepositoryMapping.getMapping(rsrc);

    // TODO: How do I see a renamed resource?
    // TODO: Even trickier: when a path change from being blob to tree?
    try {
        if (mapped != null) {
            Repository repository = mapped.getRepository();
            GitIndex index = repository.getIndex();
            String repoRelativePath = mapped.getRepoRelativePath(rsrc);
            Tree headTree = repository.mapTree("HEAD");
            TreeEntry blob = headTree != null ? headTree.findBlobMember(repoRelativePath) : null;
            Entry entry = index.getEntry(repoRelativePath);
            if (entry == null) {
                if (blob == null) {
                    if (rsrc instanceof IContainer) {
                        Integer df = (Integer) rsrc.getSessionProperty(GITFOLDERDIRTYSTATEPROPERTY);
                        Boolean f = df == null ? isDirty(rsrc) : Boolean.valueOf(df.intValue() == CHANGED);
                        if (f != null) {
                            if (f.booleanValue()) {
                                decoration.addPrefix(">"); // Have not
                                // seen
                                orState(rsrc, CHANGED);
                            } else {
                                orState(rsrc, UNCHANGED);
                                // decoration.addSuffix("=?");
                            }
                        } else {
                            decoration.addSuffix(" ?* ");
                        }

                        if (rsrc instanceof IProject) {
                            Repository repo = mapped.getRepository();
                            try {
                                String branch = repo.getBranch();
                                if (repo.isStGitMode()) {
                                    String patch = repo.getPatch();
                                    decoration.addSuffix(" [StGit " + patch + "@" + branch + "]");
                                } else {
                                    RepositoryState repositoryState = repo.getRepositoryState();
                                    String statename;
                                    if (repositoryState.equals(RepositoryState.SAFE))
                                        statename = "";
                                    else
                                        statename = repositoryState.getDescription() + " ";
                                    decoration.addSuffix(" [Git " + statename + "@ " + branch + "]");
                                }
                            } catch (IOException e) {
                                e.printStackTrace();
                                decoration.addSuffix(" [Git ?]");
                            }
                            decoration.addOverlay(UIIcons.OVR_SHARED);
                        }

                    } else {
                        if (Team.isIgnoredHint(rsrc)) {
                            decoration.addSuffix("(ignored)");
                        } else {
                            decoration.addPrefix(">");
                            decoration.addSuffix("(untracked)");
                            orState(rsrc.getParent(), CHANGED);
                        }
                    }
                } else {
                    if (!(rsrc instanceof IContainer)) {
                        decoration.addSuffix("(deprecated)"); // Will drop on
                        // commit
                        decoration.addOverlay(UIIcons.OVR_PENDING_REMOVE);
                        orState(rsrc.getParent(), CHANGED);
                    }
                }
            } else {
                if (entry.getStage() != GitIndex.STAGE_0) {
                    decoration.addSuffix("(conflict)");
                    decoration.addOverlay(UIIcons.OVR_CONFLICT);
                    orState(rsrc.getParent(), CHANGED);
                    return;
                }

                if (blob == null) {
                    decoration.addOverlay(UIIcons.OVR_PENDING_ADD);
                    orState(rsrc.getParent(), CHANGED);
                } else {

                    if (entry.isAssumedValid()) {
                        decoration.addOverlay(UIIcons.OVR_ASSUMEVALID);
                        return;
                    }

                    decoration.addOverlay(UIIcons.OVR_SHARED);

                    if (entry.isModified(mapped.getWorkDir(), true)) {
                        decoration.addPrefix(">");
                        decoration.addSuffix("(not updated)");
                        orState(rsrc.getParent(), CHANGED);
                    } else {
                        if (!entry.getObjectId().equals(blob.getId()))
                            decoration.addPrefix(">");
                        else
                            decoration.addPrefix(""); // set it to avoid further calls
                    }
                }
            }
        }
    } catch (IOException e) {
        decoration.addSuffix("?");
        // If we throw an exception Eclipse will log the error and
        // unregister us thereby preventing us from dragging down the
        // entire workbench because we are crashing.
        //
        throw new RuntimeException(UIText.Decorator_failedLazyLoading, e);
    } catch (CoreException e) {
        throw new RuntimeException(UIText.Decorator_failedLazyLoading, e);
    }
}

From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java

License:Open Source License

protected void decorateFile(IFile file, IDecoration decoration) {
    IBeansModel model = BeansCorePlugin.getModel();
    IBeansProject project = model.getProject(file.getProject());

    if (project instanceof ILazyInitializedModelElement
            && !((ILazyInitializedModelElement) project).isInitialized()) {
        return;/*from w  w w  .j  a v a  2s. c  o  m*/
    }

    IBeansConfig config = model.getConfig(file, true);
    if (config != null) {
        addErrorOverlay(decoration, getSeverity(config));
        decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
    }
}

From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java

License:Open Source License

protected void decorateFolder(IFolder folder, IDecoration decoration) {
    IBeansModel model = BeansCorePlugin.getModel();
    IBeansProject project = model.getProject(folder.getProject());

    if (project instanceof ILazyInitializedModelElement
            && !((ILazyInitializedModelElement) project).isInitialized()) {
        return;//from  w ww .  ja va  2s  .co  m
    }

    if (project != null) {
        String path = folder.getProjectRelativePath().toString() + '/';
        for (IBeansConfig config : project.getConfigs()) {
            if (config.getElementName().startsWith(path)) {
                decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                break;
            }
        }
    }
}

From source file:org.springframework.ide.eclipse.beans.ui.model.BeansModelLabelDecorator.java

License:Open Source License

protected void decorateJavaElement(IJavaElement element, IDecoration decoration) {
    int type = element.getElementType();
    if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT || type == IJavaElement.CLASS_FILE
            || type == IJavaElement.COMPILATION_UNIT) {
        IBeansModel model = BeansCorePlugin.getModel();
        IBeansProject project = model.getProject(element.getJavaProject().getProject());
        if (project instanceof ILazyInitializedModelElement
                && ((ILazyInitializedModelElement) project).isInitialized()) {
            try {
                if (type == IJavaElement.PACKAGE_FRAGMENT_ROOT) {

                    // Decorate JAR file
                    IResource resource = ((IPackageFragmentRoot) element).getResource();
                    if (resource instanceof IFile) {
                        for (IBeansConfig config : project.getConfigs()) {
                            if (config.getElementResource().equals(resource)) {
                                decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                                break;
                            }/*from w  w  w .j  a  v a  2s.c o m*/
                        }
                    }
                } else if (type == IJavaElement.CLASS_FILE) {

                    // Decorate Java class file
                    IType javaType = ((IClassFile) element).getType();
                    if (BeansModelUtils.isBeanClass(javaType)) {
                        decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                    }
                } else if (type == IJavaElement.COMPILATION_UNIT) {

                    // Decorate Java source file
                    for (IType javaType : ((ICompilationUnit) element).getTypes()) {
                        if (BeansModelUtils.isBeanClass(javaType)) {
                            decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                            break;
                        }
                    }
                }
            } catch (JavaModelException e) {
                // Ignore
            }
        }
    }
}

From source file:org.springframework.ide.eclipse.data.beans.ui.model.RepositoriesModelLabelDecorator.java

License:Open Source License

@Override
protected void decorateJavaElement(IJavaElement element, IDecoration decoration) {
    IJavaProject javaProject = element.getJavaProject();
    if (javaProject != null) {
        int type = element.getElementType();
        IProject project = javaProject.getProject();

        try {/* ww  w  .  j a v  a 2 s  . com*/

            if (type == IJavaElement.CLASS_FILE) {

                // Decorate Java class file
                IType javaType = ((IClassFile) element).getType();

                if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) {
                    decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                }

            } else if (type == IJavaElement.COMPILATION_UNIT) {

                // Decorate Java source file
                for (IType javaType : ((ICompilationUnit) element).getTypes()) {
                    if (javaType.isInterface() && SpringDataUtils.hasRepositoryBeanFor(project, javaType)) {
                        decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                        break;
                    }
                }
            }

        } catch (JavaModelException e) {
            // ignore
        }
    }
}

From source file:org.springframework.ide.eclipse.webflow.ui.model.WebflowModelLabelDecorator.java

License:Open Source License

protected void decorateFile(IFile file, IDecoration decoration) {
    if (WebflowModelUtils.isWebflowConfig(file)) {
        addErrorOverlay(decoration, getSeverity(file));
        decoration.addOverlay(WebflowUIImages.DESC_OVR_WEBFLOW);
    }//ww  w  .  j a v a  2s . c  o  m
}

From source file:org.springframework.ide.eclipse.webflow.ui.model.WebflowModelLabelDecorator.java

License:Open Source License

protected void decorateFolder(IFolder folder, IDecoration decoration) {
    IWebflowModel model = org.springframework.ide.eclipse.webflow.core.Activator.getModel();
    if (model.hasProject(folder.getProject())) {
        IWebflowProject project = model.getProject(folder.getProject());
        String path = folder.getProjectRelativePath().toString() + '/';
        for (IWebflowConfig config : project.getConfigs()) {
            if (config.getResource().getProjectRelativePath().toString().startsWith(path)) {
                decoration.addOverlay(WebflowUIImages.DESC_OVR_WEBFLOW);
                break;
            }/*  w ww.  jav a  2 s. c  o m*/
        }
    }
}

From source file:org.synyx.hades.eclipse.beans.ui.model.HadesModelLabelDecorator.java

License:Apache License

@Override
protected void decorateJavaElement(IJavaElement element, IDecoration decoration) {

    int type = element.getElementType();
    IProject project = element.getJavaProject().getProject();

    try {/* w ww  . j  a  v  a 2 s.  c o m*/

        if (type == IJavaElement.CLASS_FILE) {

            // Decorate Java class file
            IType javaType = ((IClassFile) element).getType();

            if (HadesUtils.hasDaoBeanFor(project, javaType)) {
                decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
            }

        } else if (type == IJavaElement.COMPILATION_UNIT) {

            // Decorate Java source file
            for (IType javaType : ((ICompilationUnit) element).getTypes()) {
                if (HadesUtils.hasDaoBeanFor(project, javaType)) {
                    decoration.addOverlay(BeansUIImages.DESC_OVR_SPRING);
                    break;
                }
            }
        }

    } catch (JavaModelException e) {
        // ignore
    }

    super.decorateJavaElement(element, decoration);
}