Class ProblemMarkerLabelDecorator

  • All Implemented Interfaces:
    org.eclipse.jface.viewers.IBaseLabelProvider, org.eclipse.jface.viewers.ILabelDecorator

    public class ProblemMarkerLabelDecorator
    extends ProblemLabelDecorator
    Decorates an element's image with error and warning overlays that represent the severity of markers attached to the element's corresponding resource. To see a problem decoration for a marker, the marker needs to be a sub-type of IMarker.PROBLEM.

    Note that this decorator does not listen to problem marker changes. Hence, a viewer using this decorator requires a separate listener for updating elements on problem changes.

    • Constructor Detail

      • ProblemMarkerLabelDecorator

        public ProblemMarkerLabelDecorator()
    • Method Detail

      • computeProblemSeverityFromMarkers

        protected ProblemLabelDecorator.Severity computeProblemSeverityFromMarkers​(java.lang.Object element,
                                                                                   org.eclipse.jface.viewers.IDecorationContext context)
                                                                            throws org.eclipse.core.runtime.CoreException
        Computes problem severity for the given element from markers attached to the element's corresponding resource. Takes into account the provided context.

        This implementation returns the maximum severity across problem markers attached to the element's corresponding resource and its descendants. If the given element could be adapted to an IElement through the content adapter and the adapter element is an ISourceConstruct, only markers that start strictly within the source construct's text range are considered. The corresponding resource is determined as follows:

        • If the given element is an IResource, the corresponding resource is the element itself.
        • Otherwise, if the given element could be adapted to an IElement through the content adapter, the corresponding resource is obtained via Elements.getResource(IElement).
        • Otherwise, the given element is adapted to an IResource via ResourceUtil.getResource(Object).
        Parameters:
        element - never null
        context - never null
        Returns:
        problem severity, or null if there is no problem
        Throws:
        org.eclipse.core.runtime.CoreException - if an exception occurs while accessing markers
      • getContentAdapter

        protected IContentAdapter getContentAdapter​(org.eclipse.jface.viewers.IDecorationContext context)
        Returns the content adapter that defines a mapping between elements of a Handly-based model and the viewer's content.

        This implementation requests the content adapter from the IContentAdapterProvider registered in the decoration context under the name IContentAdapterProvider.class.getName(). If no provider is available, a NullContentAdapter is returned.

        Parameters:
        context - never null
        Returns:
        an IContentAdapter (never null)
      • findMaxProblemSeverity

        protected static ProblemLabelDecorator.Severity findMaxProblemSeverity​(org.eclipse.core.resources.IResource resource,
                                                                               int depth,
                                                                               TextRange textRange)
                                                                        throws org.eclipse.core.runtime.CoreException
        Returns the maximum severity across problem markers attached to the given resource, and, optionally, to its descendants. If a text range is specified, only markers that start strictly within the given text range are considered. Returns null if there are no matching markers.
        Parameters:
        resource - not null
        depth - how far to recurse (see IResource.DEPTH_* constants)
        textRange - the text range to further constrain the marker set, or null. Makes sense only if the given resource is a text file
        Returns:
        the maximum problem severity, or null
        Throws:
        org.eclipse.core.runtime.CoreException - if an exception occurs while accessing markers