Package org.eclipse.handly.ui.viewer

# Class ProblemMarkerLabelDecorator

java.lang.Object
org.eclipse.jface.viewers.LabelDecorator
org.eclipse.handly.ui.viewer.ProblemLabelDecorator
org.eclipse.handly.ui.viewer.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.

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class org.eclipse.handly.ui.viewer.ProblemLabelDecorator

  `ProblemLabelDecorator.Severity`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ProblemMarkerLabelDecorator()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected ProblemLabelDecorator.Severity`
  `computeProblemSeverity(Object element, org.eclipse.jface.viewers.IDecorationContext context)`
  Computes problem severity for the given element taking into account the provided context.
  `protected ProblemLabelDecorator.Severity`
  `computeProblemSeverityFromMarkers(Object element, org.eclipse.jface.viewers.IDecorationContext context)`
  Computes problem severity for the given element from markers attached to the element's corresponding resource.
  `protected static ProblemLabelDecorator.Severity`
  `findMaxProblemSeverity(org.eclipse.core.resources.IResource resource, int depth, TextRange textRange)`
  Returns the maximum severity across problem markers attached to the given resource, and, optionally, to its descendants.
  `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.

  ### Methods inherited from class org.eclipse.handly.ui.viewer.ProblemLabelDecorator

  `addListener, decorateImage, decorateImage, decorateText, decorateText, dispose, isLabelProperty, prepareDecoration, removeListener`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ProblemMarkerLabelDecorator

    public ProblemMarkerLabelDecorator()

- ## Method Details

  - ### computeProblemSeverity

    protected ProblemLabelDecorator.Severity computeProblemSeverity(Object element, org.eclipse.jface.viewers.IDecorationContext context)
    Computes problem severity for the given element taking into account the provided context.

    This implementation delegates to `computeProblemSeverityFromMarkers(Object, IDecorationContext)`, suppressing and logging a `CoreException` if necessary.

    Specified by:
      `computeProblemSeverity` in class `ProblemLabelDecorator`
    Parameters:
      `element` - never `null`
      `context` - never `null`
    Returns:
      problem severity, or `null` if there is no problem

  - ### computeProblemSeverityFromMarkers

    protected ProblemLabelDecorator.Severity computeProblemSeverityFromMarkers(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