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, int quadrant);

Source Link

Document

Adds an overlay to the element's image.

Usage

From source file:org.eclipse.emf.ecp.validation.connector.ValidationFailedDecorator.java

License:Open Source License

/**
 * {@inheritDoc}//  w  ww  . j  ava2  s.c o m
 */
@Override
public void decorate(final Object element, IDecoration decoration) {
    if (!(element instanceof EObject) && !(element instanceof ECPProject)) {
        return;
    }

    Integer severity = null;

    if (element instanceof EObject) {

        final ECPProject project = ECPUtil.getECPProjectManager().getProject(element);

        if (project != null && project.isOpen()) {
            severity = Activator.getDefault().getValidationService(project).getDiagnostic(element)
                    .getSeverity();
        }
    } else if (element instanceof ECPProject && ((ECPProject) element).isOpen()) {
        if (ECPUtil.getECPProjectManager().getProject(((ECPProject) element).getName()) == null) {
            return;
        }
        severity = Activator.getDefault().getValidationService((ECPProject) element).getRootDiagnostic()
                .getSeverity();
    }

    if (severity == null) {
        return;
    }

    switch (severity.intValue()) {
    case Diagnostic.ERROR:
        decoration.addOverlay(Activator.getImageDescriptor("icons/error_decorate.png"), //$NON-NLS-1$
                IDecoration.BOTTOM_RIGHT);
        break;
    case Diagnostic.WARNING:
        decoration.addOverlay(Activator.getImageDescriptor("icons/warning_decorate.png"), //$NON-NLS-1$
                IDecoration.BOTTOM_RIGHT);
        break;
    case Diagnostic.OK:
        decoration.addOverlay(null);
        break;
    default:
        break;
    }

}

From source file:org.eclipse.emf.emfstore.client.ui.decorators.ChildrenDecorator.java

License:Open Source License

/**
 * {@inheritDoc}/* w  w w . j  a v  a 2s. c o m*/
 * 
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
 *      org.eclipse.jface.viewers.IDecoration)
 */
public void decorate(Object element, IDecoration decoration) {
    URL url = FileLocator.find(Platform.getBundle("org.eclipse.emf.ecp.common"), new Path("icons/shortcut.png"),
            null);
    ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(url);
    decoration.addOverlay(imageDescriptor, IDecoration.BOTTOM_RIGHT);

}

From source file:org.eclipse.emf.emfstore.client.ui.decorators.ModelElementDirtyDecorator.java

License:Open Source License

/**
 * {@inheritDoc}/*  w  w w.  ja  va  2  s . com*/
 * 
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang .Object,
 *      org.eclipse.jface.viewers.IDecoration)
 * @param element element
 * @param decoration decoration
 */
public void decorate(Object element, IDecoration decoration) {
    URL url = null;
    boolean dirty = false;
    if (element instanceof EObject) {
        EObject modelElement = (EObject) element;
        Project project = ModelUtil.getProject(modelElement);
        if (project == null) {
            return;
        }
        ProjectSpace projectSpace = WorkspaceManager.getProjectSpace(modelElement);
        if (projectSpace == null) {
            return;
        }
        ModelElementId modelElementId = project.getModelElementId(modelElement);
        if (modelElementId == null) {
            return;
        }
        if (projectSpace.getModifiedModelElementsCache().isModelElementDirty(modelElementId)) {
            dirty = true;
        }
    }
    if (dirty) {
        if (descriptor == null) {
            url = FileLocator.find(Platform.getBundle("org.eclipse.emf.ecp.common"), new Path(DIRTY_ICON_PATH),
                    null);
            descriptor = ImageDescriptor.createFromURL(url);
        }
        decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
    }
}

From source file:org.eclipse.emf.emfstore.client.ui.decorators.ProjectSpaceDirtyDecorator.java

License:Open Source License

/**
 * {@inheritDoc}//from  w  ww.j a  va2s. co m
 * 
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang .Object,
 *      org.eclipse.jface.viewers.IDecoration)
 * @param element element
 * @param decoration decoration
 */
public void decorate(Object element, IDecoration decoration) {
    /**
     * Checks that the element is an IResource with the 'Read-only' attribute and adds the decorator based on the
     * specified image description and the integer representation of the placement option.
     */

    if (element instanceof ProjectSpace) {
        ProjectSpace ps = (ProjectSpace) element;
        if (ps.isDirty()) {
            URL url = FileLocator.find(Platform.getBundle("org.eclipse.emf.ecp.common"), new Path(dirtyPath),
                    null);
            descriptor = ImageDescriptor.createFromURL(url);
            decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
        }
    }
}

From source file:org.eclipse.emf.emfstore.client.ui.views.emfstorebrowser.provider.ESBrowserLabelDecorator.java

License:Open Source License

/**
 * {@inheritDoc} Decorates the label of a {@link ServerInfo} object
 * according to its login state./*from   w  w w.ja  v a  2  s. c o  m*/
 */
public void decorate(Object element, IDecoration decoration) {

    if (element instanceof ServerInfo) {
        ServerInfo server = (ServerInfo) element;

        if (server.getLastUsersession() != null && server.getLastUsersession().isLoggedIn()) {
            decoration.addOverlay(Activator.getImageDescriptor("icons/bullet_green.png"),
                    IDecoration.BOTTOM_RIGHT);
        } else {
            decoration.addOverlay(Activator.getImageDescriptor("icons/bullet_delete.png"),
                    IDecoration.BOTTOM_RIGHT);
        }
    }
}

From source file:org.eclipse.emf.emfstore.internal.client.ui.decorators.ModelElementDirtyDecorator.java

License:Open Source License

/**
 * //from ww  w .  j av a  2s  .c o m
 * {@inheritDoc}
 * 
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang.Object,
 *      org.eclipse.jface.viewers.IDecoration)
 */
public void decorate(Object element, IDecoration decoration) {
    URL url = null;
    boolean dirty = false;
    if (element instanceof EObject) {
        EObject modelElement = (EObject) element;
        Project project = ModelUtil.getProject(modelElement);
        if (project == null) {
            return;
        }
        ProjectSpace projectSpace = ESWorkspaceProviderImpl.getProjectSpace(modelElement);
        if (projectSpace == null) {
            return;
        }
        ModelElementId modelElementId = project.getModelElementId(modelElement);
        if (modelElementId == null) {
            return;
        }
    }
    if (dirty) {
        if (descriptor == null) {
            url = FileLocator.find(Platform.getBundle("org.eclipse.emf.ecp.common"), new Path(DIRTY_ICON_PATH),
                    null);
            descriptor = ImageDescriptor.createFromURL(url);
        }
        decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
    }
}

From source file:org.eclipse.jubula.client.teststyle.gui.decoration.DecoratorHandler.java

License:Open Source License

/**
 * Checks in the ProblemCont if the INodePO contains Elements which must be
 * decorated for violating a Checkstyle rule.
 * /*  w ww.  j a  v a 2 s.c  o m*/
 * {@inheritDoc}
 */
public void decorate(Object element, IDecoration decoration) {
    if (element == null || !TeststyleHandler.getInstance().isEnabled()) {
        return; // Cancel the method, an null element can't be decorated.
    }

    Severity severity = getWorstSeverity(getViolatingBaseChecks(element));

    if (element instanceof INodePO && severity != null) {
        INodePO node = (INodePO) element;
        IProblem worstProblem = ProblemFactory.getWorstProblem(node.getProblems());
        if (worstProblem != null && severity.ordinal() * 2 <= worstProblem.getStatus().getSeverity()) {
            severity = null;
        }
    }

    if (severity != null) {
        switch (severity) {
        case WARNING:
            decoration.addOverlay(IconConstants.WARNING_IMAGE_DESCRIPTOR, IDecoration.BOTTOM_RIGHT);
            break;
        case ERROR:
            decoration.addOverlay(IconConstants.ERROR_IMAGE_DESCRIPTOR, IDecoration.BOTTOM_RIGHT);
            break;
        default:
            break;
        }
    }
    for (BaseCheck chk : getViolatingBaseChecks(element)) {
        decoration.addPrefix(chk.getPrefix(element));
        decoration.addSuffix(chk.getSuffix(element));
    }
    BaseContext cont = BaseContext.getFor(element.getClass());
    for (DecoratingCheck chk : CheckCont.getDecChecksFor(cont)) {
        if (chk.isActive(cont) && chk.decorate(element)) {
            // FIXME mbs decorating icons
            decoration.addPrefix(chk.getPrefix(element));
            decoration.addSuffix(chk.getSuffix(element));
        }
    }
}

From source file:org.eclipse.jubula.client.ui.provider.labelprovider.decorators.ResultDecorator.java

License:Open Source License

/** {@inheritDoc} */
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof TestResultNode) {
        TestResultNode resultNode = ((TestResultNode) element);
        if (resultNode.getNode() instanceof ICommentPO) {
            return;
        }//from   w w  w  .j av a  2  s.c  o m

        int status = resultNode.getStatus();
        ImageDescriptor image2use = null;
        IDecorationContext context = decoration.getDecorationContext();
        if (context instanceof DecorationContext) {
            ((DecorationContext) context).putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);
        }
        switch (status) {
        case TestResultNode.NOT_YET_TESTED:
            break;
        case TestResultNode.NO_VERIFY:
            image2use = IconConstants.STEP_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.TESTING:
            image2use = IconConstants.STEP_TESTING_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.SUCCESS:
            image2use = IconConstants.STEP_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.ERROR:
        case TestResultNode.CONDITION_FAILED:
        case TestResultNode.INFINITE_LOOP:
            image2use = IconConstants.STEP_NOT_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.ERROR_IN_CHILD:
            image2use = IconConstants.STEP_NOT_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.NOT_TESTED:
            image2use = IconConstants.STEP_FAILED_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.RETRYING:
            image2use = IconConstants.STEP_RETRY_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.SUCCESS_RETRY:
            image2use = IconConstants.STEP_RETRY_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.ABORT:
            image2use = IconConstants.STEP_NOT_OK_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.SKIPPED:
            image2use = IconConstants.STEP_SKIPPED_IMAGE_DESCRIPTOR;
            break;
        case TestResultNode.SUCCESS_ONLY_SKIPPED:
            image2use = IconConstants.STEP_SUCCESS_SKIPPED_IMAGE_DESCRIPTOR;
            break;
        default:
            break;
        }
        decoration.addOverlay(image2use, IDecoration.REPLACE);
    }
}

From source file:org.eclipse.mylyn.internal.tasks.ui.TaskLabelDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {

    ImageDescriptor priorityOverlay = getPriorityImageDescriptor(element);
    if (priorityOverlay != null) {
        decoration.addOverlay(priorityOverlay, IDecoration.BOTTOM_LEFT);
    }//from ww  w.  ja v  a2 s  .c  o  m

    if (element instanceof ITask) {
        ITask task = (ITask) element;
        if (!task.isCompleted() && (TasksUiPlugin.getTaskActivityManager().isDueToday(task)
                || TasksUiPlugin.getTaskActivityManager().isOverdue(task))) {
            decoration.addOverlay(CommonImages.OVERLAY_DATE_OVERDUE, IDecoration.TOP_RIGHT);
        } else if (!task.isCompleted() && task.getDueDate() != null) {
            decoration.addOverlay(CommonImages.OVERLAY_DATE_DUE, IDecoration.TOP_RIGHT);
        }
        if (hasNotes(task)) {
            decoration.addOverlay(TasksUiImages.NOTES, IDecoration.BOTTOM_RIGHT);
        }
    } else if (element instanceof ITaskRepositoryElement) {
        ITaskRepositoryElement repositoryElement = (ITaskRepositoryElement) element;
        String repositoryUrl = repositoryElement.getRepositoryUrl();
        TaskRepository taskRepository = TasksUi.getRepositoryManager()
                .getRepository(repositoryElement.getConnectorKind(), repositoryUrl);
        if (taskRepository != null) {
            decoration.addSuffix("   [" + taskRepository.getRepositoryLabel() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
        }
    } else if (element instanceof TaskRepository) {
        ImageDescriptor overlay = TasksUiPlugin.getDefault()
                .getOverlayIcon(((TaskRepository) element).getConnectorKind());
        if (overlay != null) {
            decoration.addOverlay(overlay, IDecoration.BOTTOM_RIGHT);
        }
    }
}

From source file:org.eclipse.php.internal.ui.navigator.PHPNavigatorLabelDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof IFolder) {
        IDecorationContext context = decoration.getDecorationContext();
        if (context instanceof DecorationContext) {
            ((DecorationContext) context).putProperty(IDecoration.ENABLE_REPLACE, Boolean.TRUE);
        }/*  w  w w.java  2  s .  c om*/
        IFolder folder = (IFolder) element;
        IScriptProject project = DLTKCore.create(folder.getProject());
        try {
            if (PHPToolkitUtil.isPhpProject(folder.getProject()) && project.isOnBuildpath(folder)) {
                if (lfm.isInLibraryFolder(folder)) {
                    decoration.addOverlay(PHPPluginImages.DESC_OBJS_PHP_LIBFOLDER, IDecoration.REPLACE);
                } else {
                    decoration.addOverlay(DLTKPluginImages.DESC_OBJS_PACKFRAG_ROOT, IDecoration.REPLACE);
                }
            }
        } catch (CoreException e) {
            Logger.logException(e);
        }
    }
}