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

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

Introduction

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

Prototype

void setForegroundColor(Color color);

Source Link

Document

Set the foreground color for this decoration.

Usage

From source file:com.aptana.git.ui.internal.GitLightweightDecorator.java

License:Open Source License

private void decorateFile(IDecoration decoration, final IResource resource) {
    IFile file = (IFile) resource;/*w  ww  .  ja v a 2 s  . c  o  m*/
    GitRepository repo = getRepo(resource);
    if (repo == null)
        return;

    ChangedFile changed = repo.getChangedFileForResource(file);
    if (changed == null) {
        return;
    }

    ImageDescriptor overlay = null;
    // Unstaged trumps staged when decorating. One file may have both staged and unstaged changes.
    if (changed.hasUnstagedChanges()) {
        decoration.setForegroundColor(GitColors.redFG());
        decoration.setBackgroundColor(GitColors.redBG());
        if (changed.getStatus() == ChangedFile.Status.NEW) {
            overlay = untrackedImage();
        } else if (changed.getStatus() == ChangedFile.Status.UNMERGED) {
            overlay = conflictImage();
        }
    } else if (changed.hasStagedChanges()) {
        decoration.setForegroundColor(GitColors.greenFG());
        decoration.setBackgroundColor(GitColors.greenBG());
        if (changed.getStatus() == ChangedFile.Status.DELETED) {
            overlay = stagedRemovedImage();
        } else if (changed.getStatus() == ChangedFile.Status.NEW) {
            overlay = stagedAddedImage();
        }
    }
    decoration.addPrefix(DIRTY_PREFIX);
    if (overlay != null)
        decoration.addOverlay(overlay);
}

From source file:com.vectrace.MercurialEclipse.team.ResourceDecorator.java

License:Open Source License

private void setForeground(IDecoration d, String id) {
    d.setForegroundColor(theme.getColorRegistry().get(id));
}

From source file:eu.modelwriter.marker.model.decorators.EcoreModelDecorator.java

License:Open Source License

@Override
public void decorate(Object resource, IDecoration decoration) {

    if (resource instanceof ENamedElement) {
        ENamedElement namedElement = (ENamedElement) resource;
        Resource eResource = namedElement.eResource();
        if (eResource == null)
            return;
        URI eUri = eResource.getURI();
        IResource iResource = null;//ww  w.  ja  v  a  2s . c o  m
        if (eUri.isPlatformResource()) {
            String platformString = eUri.toPlatformString(true);
            iResource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
        }
        if (iResource == null)
            return;

        AbstractUIPlugin plugin = MarkerActivator.getDefault();
        ImageRegistry imageRegistry = plugin.getImageRegistry();
        IMarker marker = null;
        URI uri = EcoreUtil.getURI(namedElement);
        marker = MarkerFactory.findMarkersByUri(iResource, uri.toString());

        if (marker != null) {
            try {
                if (marker.getType().equals(MarkerFactory.MARKER_MARKING)) {
                    decoration.addOverlay(
                            ImageDescriptor
                                    .createFromImage(imageRegistry.get(MarkerActivator.Images.IMAGE_BLACK_ID)),
                            IDecoration.BOTTOM_RIGHT);
                    decoration.setForegroundColor(color_blue);
                } else {
                    decoration.addOverlay(
                            ImageDescriptor
                                    .createFromImage(imageRegistry.get(MarkerActivator.Images.IMAGE_RED_ID)),
                            IDecoration.BOTTOM_RIGHT);
                    decoration.setForegroundColor(color_maroon);
                }
            } catch (CoreException e) {
                e.printStackTrace();
            }
            // EClass or EDataType
            if (namedElement instanceof EClassifier) {
                System.out.println("Classifier: " + namedElement.getName());
                EClassifier eC = (EClassifier) namedElement;
                System.out.println(eC.getEPackage().getNsURI());
                System.out.println(eC.getClassifierID());
            }
            if (namedElement instanceof EStructuralFeature) {
                System.out.println("Structural Feature: " + namedElement.getName());
                EStructuralFeature eS = (EStructuralFeature) namedElement;
                System.out.println(eS.getEContainingClass().getName());
                System.out.println(eS.getFeatureID());
            }
        }
    } else if (resource instanceof EObject) {
        EObject element = (EObject) resource;
        URI eUri = EcoreUtil.getURI(element);

        Resource eResource = element.eResource();
        if (eResource == null)
            return;
        IResource iResource = null;
        if (eUri.isPlatformResource()) {
            String platformString = eUri.toPlatformString(true);
            iResource = ResourcesPlugin.getWorkspace().getRoot().findMember(platformString);
        }
        if (iResource == null)
            return;

        AbstractUIPlugin plugin = MarkerActivator.getDefault();
        ImageRegistry imageRegistry = plugin.getImageRegistry();
        try {
            IMarker marker = MarkerFactory.findMarkersByUri(iResource, eUri.toString());
            if (marker != null) {
                if (marker.getType().equals(MarkerFactory.MARKER_MARKING)) {
                    decoration.addOverlay(
                            ImageDescriptor
                                    .createFromImage(imageRegistry.get(MarkerActivator.Images.IMAGE_BLACK_ID)),
                            IDecoration.BOTTOM_RIGHT);
                    decoration.setForegroundColor(color_blue);
                } else {
                    decoration.addOverlay(
                            ImageDescriptor
                                    .createFromImage(imageRegistry.get(MarkerActivator.Images.IMAGE_RED_ID)),
                            IDecoration.BOTTOM_RIGHT);
                    decoration.setForegroundColor(color_maroon);
                }
            }
        } catch (CoreException e) {
            e.printStackTrace();
        }
    }
}

From source file:eu.modelwriter.marker.model.decorators.FileDecorator.java

License:Open Source License

@Override
public void decorate(Object resource, IDecoration decoration) {
    int markers = MarkerFactory.findMarkers((IResource) resource).size();
    if (markers > 0) {
        decoration.addOverlay(ImageDescriptor.createFromFile(FileDecorator.class, ICON), IDecoration.TOP_RIGHT);
        decoration.setForegroundColor(color);
    } else {/* w  w w. j  av  a  2  s  .  co  m*/
        decoration.addOverlay(null);
        decoration.setForegroundColor(new Color(null, 0, 0, 0, 0));
    }
}

From source file:nl.hostnet.deadfiles.decorators.DeadFileDecorator.java

License:Open Source License

/**
 * Perform the decoration of an element. Eclipse will call this function on the registered element
 * types. {@inheritDoc}/*from  w  w w  . j av  a 2  s .  com*/
 * 
 * @see org.eclipse.jface.viewers.ILightweightLabelDecorator#decorate(java.lang .Object,
 *      org.eclipse.jface.viewers.IDecoration)
 */
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.
     */

    IResource resource = (IResource) element;
    if (foreground) {
        decoration.setForegroundColor(getColor(resource));
    } else if (background) {
        decoration.setBackgroundColor(getColor(resource));
    }
}

From source file:org.eclipse.cdt.internal.ui.viewsupport.ExcludedFileDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    if (element instanceof IFile || element instanceof IFolder) {
        IResource resource = (IResource) element;
        ICProjectDescriptionManager mngr = CoreModel.getDefault().getProjectDescriptionManager();
        ICProjectDescription desc = mngr.getProjectDescription(resource.getProject(),
                ICProjectDescriptionManager.GET_IF_LOADDED);
        if (desc == null)
            return;
        ICConfigurationDescription conf = desc.getDefaultSettingConfiguration();
        ICSourceEntry[] entries = conf.getSourceEntries();
        boolean isUnderSourceRoot = false;
        IPath fullPath = resource.getFullPath();
        for (ICSourceEntry icSourceEntry : entries) {
            if (icSourceEntry.getFullPath().isPrefixOf(fullPath)) {
                isUnderSourceRoot = true;
                break;
            }/*from   w  w  w. java2  s. co  m*/
        }
        // Only bother to mark items that would be included otherwise
        if (isUnderSourceRoot && CDataUtil.isExcluded(fullPath, entries)) {
            decoration.addOverlay(CPluginImages.DESC_OVR_INACTIVE);
            decoration.setForegroundColor(
                    JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));
        }
    }
}

From source file:org.eclipse.cdt.internal.ui.viewsupport.IncludeFolderDecorator.java

License:Open Source License

@Override
public void decorate(Object element, IDecoration decoration) {
    boolean isAccesible = true;

    if (element instanceof IncludeReferenceProxy) {
        IIncludeReference reference = ((IncludeReferenceProxy) element).getReference();
        IPath path = reference.getPath();
        IContainer container = ResourcesPlugin.getWorkspace().getRoot().getContainerForLocation(path);
        if (container != null) {
            isAccesible = container.isAccessible();
        } else {/*from   w w w  .java 2 s  .c  om*/
            isAccesible = path.toFile().exists();
        }
    } else if (element instanceof IIncludeReference) {
        IPath path = ((IIncludeReference) element).getPath();
        isAccesible = path.toFile().exists();
    }

    if (!isAccesible) {
        decoration.addOverlay(CDTSharedImages.getImageDescriptor(CDTSharedImages.IMG_OVR_WARNING));
        // JFacePreferences.QUALIFIER_COLOR colors label in gray
        decoration.setForegroundColor(JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR));
    }
}

From source file:org.eclipse.mylyn.internal.context.ui.InterestDecoratorLightweight.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    if (ContextCore.getContextManager() != null && !ContextCore.getContextManager().isContextActive()) {
        return;//from w  ww .j a va 2 s  .com
    }

    AbstractContextStructureBridge bridge = null;
    try {
        if (ContextCorePlugin.getDefault() == null) {
            return;
        }
        bridge = ContextCore.getStructureBridge(element);
    } catch (ConcurrentModificationException cme) {
        // ignored, because we can add structure bridges during decoration
    }
    try {
        // NOTE: awkward coupling and special rule to deal with tasks, see bug 212639
        if (!"org.eclipse.mylyn.internal.tasks.core.TaskTask".equals(element.getClass().getName())) { //$NON-NLS-1$
            IInteractionElement node = null;
            if (element instanceof InteractionContextRelation) {
                decoration.setForegroundColor(ColorMap.RELATIONSHIP);
            } else if (element instanceof IInteractionElement) {
                node = (IInteractionElement) element;
            } else {
                if (bridge != null && bridge.getContentType() != null) {
                    node = ContextCore.getContextManager().getElement(bridge.getHandleIdentifier(element));
                }
            }
            if (node != null) {
                decoration.setForegroundColor(ContextUi.getForeground(node));
                if (bridge != null && bridge.canBeLandmark(node.getHandleIdentifier())
                        && node.getInterest().isLandmark() && !node.getInterest().isPropagated()
                        && !node.getInterest().isPredicted()) {
                    decoration.setFont(CommonFonts.BOLD);
                }
            }
        }
    } catch (Exception e) {
        StatusHandler.log(new Status(IStatus.ERROR, ContextUiPlugin.ID_PLUGIN, "Decoration failed", e)); //$NON-NLS-1$
    }
}

From source file:org.eclipse.mylyn.internal.sandbox.dev.InterestDebuggingDecorator.java

License:Open Source License

public void decorate(Object element, IDecoration decoration) {
    AbstractContextStructureBridge bridge = null;
    try {/*from  w  w w  .ja  v a2  s .  co m*/
        if (ContextCorePlugin.getDefault() == null) {
            return;
        }
        bridge = ContextCore.getStructureBridge(element);
    } catch (ConcurrentModificationException cme) {
        // ignored, because we can add structure bridges during decoration
    }
    try {
        IInteractionElement node = null;
        if (element instanceof InteractionContextRelation) {
            decoration.setForegroundColor(ColorMap.RELATIONSHIP);
        } else if (element instanceof IInteractionElement) {
            node = (IInteractionElement) element;
        } else {
            if (bridge != null && bridge.getContentType() != null) {
                node = ContextCore.getContextManager().getElement(bridge.getHandleIdentifier(element));
            }
        }
        if (node != null) {
            decoration.addSuffix(" {" + node.getInterest().getValue() + " ["
                    + node.getInterest().getEncodedValue() + "] " + "}");
        }
    } catch (Exception e) {
        StatusHandler.log(new Status(IStatus.WARNING, MylynDevPlugin.ID_PLUGIN, "Decoration failed", e));
    }
}

From source file:org.eclipse.team.internal.ccvs.ui.CVSDecoration.java

License:Open Source License

public void apply(IDecoration decoration) {
    compute();/*from   w ww .  ja  va  2 s  .c  om*/
    // apply changes
    String suffix = getSuffix();
    if (suffix != null)
        decoration.addSuffix(suffix);
    String prefix = getPrefix();
    if (prefix != null)
        decoration.addPrefix(prefix);
    ImageDescriptor overlay = getOverlay();
    if (overlay != null)
        decoration.addOverlay(overlay);
    Color bc = getBackgroundColor();
    if (bc != null)
        decoration.setBackgroundColor(bc);
    Color fc = getForegroundColor();
    if (fc != null)
        decoration.setForegroundColor(fc);
    Font f = getFont();
    if (f != null)
        decoration.setFont(f);
}