Example #1
0
 public static IMarker[] getProblemsFor(IResource resource) {
   try {
     if (resource != null && resource.exists()) {
       IMarker[] markers =
           resource.findMarkers(
               IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
       Set markerTypes =
           JavaModelManager.getJavaModelManager().compilationParticipants.managedMarkerTypes();
       if (markerTypes.isEmpty()) return markers;
       ArrayList markerList = new ArrayList(5);
       for (int i = 0, length = markers.length; i < length; i++) {
         markerList.add(markers[i]);
       }
       Iterator iterator = markerTypes.iterator();
       while (iterator.hasNext()) {
         markers = resource.findMarkers((String) iterator.next(), false, IResource.DEPTH_INFINITE);
         for (int i = 0, length = markers.length; i < length; i++) {
           markerList.add(markers[i]);
         }
       }
       IMarker[] result;
       markerList.toArray(result = new IMarker[markerList.size()]);
       return result;
     }
   } catch (CoreException e) {
     // assume there are no problems
   }
   return new IMarker[0];
 }
  /**
   * @param resource may be the file open in the editor or the workspace root (if it is an external
   *     file)
   * @param document is the document opened in the editor
   * @param externalFileEditorInput is not-null if this is an external file
   * @param info is the vertical ruler info (only used if this is not an external file)
   * @param onlyIncludeLastLineActivity if only the markers that are in the last mouse-click should
   *     be included
   * @return the markers that correspond to the markers from the current editor.
   */
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static List<Tuple<IMarker, IBreakpoint>> getMarkersAndBreakpointsFromEditorResource(
      IResource resource,
      IDocument document,
      IEditorInput externalFileEditorInput,
      int lastLineActivity,
      boolean onlyIncludeLastLineActivity,
      IAnnotationModel annotationModel) {
    List<Tuple<IMarker, IBreakpoint>> breakpoints = new ArrayList<Tuple<IMarker, IBreakpoint>>();

    try {
      List<IMarker> markers = new ArrayList<IMarker>();
      boolean isExternalFile = false;

      markers.addAll(
          Arrays.asList(
              resource.findMarkers(PyBreakpoint.PY_BREAK_MARKER, true, IResource.DEPTH_INFINITE)));
      markers.addAll(
          Arrays.asList(
              resource.findMarkers(
                  PyBreakpoint.PY_CONDITIONAL_BREAK_MARKER, true, IResource.DEPTH_INFINITE)));

      if (!(resource instanceof IFile)) {
        // it was created from an external file
        isExternalFile = true;
      }

      IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
      for (IMarker marker : markers) {
        if (marker == null) {
          continue;
        }
        IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker);
        if (breakpoint != null && breakpointManager.isRegistered(breakpoint)) {
          Position pos = PyMarkerUtils.getMarkerPosition(document, marker, annotationModel);

          if (!isExternalFile) {
            if (!onlyIncludeLastLineActivity) {
              breakpoints.add(new Tuple(marker, breakpoint));
            } else if (includesRulerLine(pos, document, lastLineActivity)) {
              breakpoints.add(new Tuple(marker, breakpoint));
            }
          } else {

            if (isInSameExternalEditor(marker, externalFileEditorInput)) {
              if (!onlyIncludeLastLineActivity) {
                breakpoints.add(new Tuple(marker, breakpoint));
              } else if (includesRulerLine(pos, document, lastLineActivity)) {
                breakpoints.add(new Tuple(marker, breakpoint));
              }
            }
          }
        }
      }
    } catch (CoreException x) {
      PydevDebugPlugin.log(IStatus.ERROR, "Unexpected getMarkers error (recovered properly)", x);
    }
    return breakpoints;
  }
 public static int getErrorTicksFromMarkers(
     final IResource res, final int depth, final ISourceReference sourceElement)
     throws CoreException {
   if (res == null || !res.isAccessible()) {
     return 0;
   }
   int severity = 0;
   if (sourceElement == null) {
     severity = res.findMaxProblemSeverity(IMarker.PROBLEM, true, depth);
   } else {
     final IMarker[] markers = res.findMarkers(IMarker.PROBLEM, true, depth);
     if (markers != null && markers.length > 0) {
       for (int i = 0; i < markers.length && severity != IMarker.SEVERITY_ERROR; i++) {
         final IMarker curr = markers[i];
         if (isMarkerInRange(curr, sourceElement)) {
           final int val = curr.getAttribute(IMarker.SEVERITY, -1);
           if (val == IMarker.SEVERITY_WARNING || val == IMarker.SEVERITY_ERROR) {
             severity = val;
           }
         }
       }
     }
   }
   if (severity == IMarker.SEVERITY_ERROR) {
     return ERRORTICK_ERROR;
   } else if (severity == IMarker.SEVERITY_WARNING) {
     return ERRORTICK_WARNING;
   }
   return 0;
 }
  /**
   * Returns the maximum problem marker severity for the given resource, and, if depth is
   * IResource.DEPTH_INFINITE, its children. The return value will be one of IMarker.SEVERITY_ERROR,
   * IMarker.SEVERITY_WARNING, IMarker.SEVERITY_INFO or 0, indicating that no problem markers exist
   * on the given resource.
   *
   * @param depth TODO
   */
  public static int getMaxProblemMarkerSeverity(IResource res, int depth) {
    if (res == null || !res.isAccessible()) return 0;

    boolean hasWarnings = false; // if resource has errors, will return error image immediately
    IMarker[] markers = null;

    try {
      markers = res.findMarkers(IMarker.PROBLEM, true, depth);
    } catch (CoreException e) {
      e.printStackTrace();
    }
    if (markers == null) return 0; // don't know - say no errors/warnings/infos

    for (int i = 0; i < markers.length; i++) {
      IMarker m = markers[i];
      int priority = m.getAttribute(IMarker.SEVERITY, -1);

      if (priority == IMarker.SEVERITY_WARNING) {
        hasWarnings = true;
      } else if (priority == IMarker.SEVERITY_ERROR) {
        return IMarker.SEVERITY_ERROR;
      }
    }
    return hasWarnings ? IMarker.SEVERITY_WARNING : 0;
  }
  public void decorate(Object element, IDecoration decoration) {
    if (!(element instanceof IResource)) return;
    IResource resource = (IResource) element;
    if (!resource.exists()) return;
    IProject project = resource.getProject();
    if (project == null) {
      Log.error(
          Messages.getString("ErrorDecorator.PROJECT_FOR")
              + resource.getName()
              + Messages.getString("ErrorDecorator.IS_NULL"),
          new Throwable()); //$NON-NLS-1$ //$NON-NLS-2$
      return;
    }
    try {
      if (!project.isOpen()) return;
      project.open(null);
      if (project.hasNature(LSLProjectNature.ID)) {
        LSLProjectNature nature = (LSLProjectNature) project.getNature(LSLProjectNature.ID);

        if (nature == null) return;

        IMarker[] m =
            resource.findMarkers("lslforge.problem", true, IResource.DEPTH_INFINITE); // $NON-NLS-1$

        if (m == null || m.length == 0) return;
      } else {
        return;
      }
    } catch (CoreException e) {
      Log.error("exception caught trying to determine project nature!", e); // $NON-NLS-1$
      return;
    }

    decoration.addOverlay(descriptor, IDecoration.BOTTOM_LEFT);
  }
Example #6
0
 private boolean hasModelMarkers(IResource resource) {
   try {
     return resource.findMarkers(MODEL_MARKER, false, IResource.DEPTH_ZERO).length > 0;
   } catch (CoreException e) {
     e.printStackTrace();
   }
   return true;
 }
Example #7
0
 public static IMarker[] getTasksFor(IResource resource) {
   try {
     if (resource != null && resource.exists())
       return resource.findMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE);
   } catch (CoreException e) {
     // assume there are no tasks
   }
   return new IMarker[0];
 }
Example #8
0
 private static IMarker[] getMarkersFor(final IResource resource, final String type) {
   try {
     if (resource != null && resource.exists()) {
       return resource.findMarkers(type, false, IResource.DEPTH_INFINITE);
     }
   } catch (final CoreException e) {
     // assume there are no tasks
   }
   return new IMarker[0];
 }
Example #9
0
  /**
   * Checks if CoWolf-Markers are specified for given IResource.
   *
   * @param res to check
   * @return if CoWolf-Markers are specified
   */
  private boolean doesCowolfMarkerExist(IResource res) {

    IMarker[] markers = null;
    try {
      markers = res.findMarkers(COWOLF_PROBLEM, false, IResource.DEPTH_ZERO);

      return markers.length > 0;

    } catch (CoreException e) {
      LOGGER.error("", e);
    }
    return false;
  }
Example #10
0
  @Override
  public void deleteMarkers(IResource resource, String type, String attrName, String attrValue)
      throws CoreException {
    if (resource == null || !resource.exists()) {
      return;
    }

    IMarker[] markers = resource.findMarkers(type, false /*includeSubtypes*/, IResource.DEPTH_ZERO);
    for (IMarker marker : markers) {
      if (eq(attrValue, marker.getAttribute(attrName))) {
        marker.delete();
      }
    }
  }
  private static IMarker[] getValidationTasks(IResource resource, int severity, int depth) {
    IMarker[] tempMarkers = null;
    int validCount = 0;
    IMarker[] allMarkers = null;
    try {
      allMarkers = resource.findMarkers(VALIDATION_MARKER, true, depth);
    } catch (CoreException e) {
      if (Tracing.isLogging()) ValidationPlugin.getPlugin().handleException(e);
      return NO_MARKERS;
    }

    // Now filter in the markers, based on severity type.
    if (allMarkers.length != 0) {
      tempMarkers = new IMarker[allMarkers.length];
      for (IMarker marker : allMarkers) {
        Integer filterSeverity = null;
        try {
          filterSeverity = (Integer) marker.getAttribute(VALIDATION_MARKER_SEVERITY);
        } catch (CoreException e) {
          // Someone may have deleted the marker on us. All we can do is skip it.
          continue;
        }
        if (filterSeverity == null) {
          // odd...marker wasn't created correctly. How could this happen?
          // Default to the current severity and add it to the list.
          try {
            // 226541 - I was seeing markers with valid severities being reset, so I added this
            // additional test.
            if (marker.getAttribute(IMarker.SEVERITY, -1) == -1)
              marker.setAttribute(IMarker.SEVERITY, getSeverity(severity));
          } catch (Exception e) {
            ValidationPlugin.getPlugin().handleException(e);
            continue;
          }
        } else if ((severity & filterSeverity.intValue()) == 0) {
          continue;
        }
        tempMarkers[validCount++] = marker;
      }
    }

    if (validCount == 0) {
      return NO_MARKERS;
    }

    IMarker[] validMarkers = new IMarker[validCount];
    System.arraycopy(tempMarkers, 0, validMarkers, 0, validCount);
    return validMarkers;
  }
Example #12
0
 protected void collectBrakePoint(IResource resource) throws CoreException {
   fBreakpoints = new BucketMap<IResource, IBreakpoint>(6);
   fBreakpointAttributes = new HashMap<IBreakpoint, Map<String, Object>>(6);
   final IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
   IMarker[] markers =
       resource.findMarkers(IBreakpoint.LINE_BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
   for (IMarker marker : markers) {
     IResource markerResource = marker.getResource();
     IBreakpoint breakpoint = breakpointManager.getBreakpoint(marker);
     if (breakpoint != null) {
       fBreakpoints.add(markerResource, breakpoint);
       fBreakpointAttributes.put(breakpoint, breakpoint.getMarker().getAttributes());
     }
   }
 }
  private void printFilesProblems(ICompilationUnit unit, StringBuilder sb)
      throws JavaModelException, CoreException {
    IResource javaSourceFile = unit.getUnderlyingResource();
    IMarker[] markers =
        javaSourceFile.findMarkers(
            IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true, IResource.DEPTH_INFINITE);
    if (markers != null && markers.length > 0) {
      Document doc = new Document(unit.getSource());

      sb.append("<COMPILE_PROBLEMS>");
      for (IMarker marker : markers) {
        printProblemXML(marker, doc, sb);
      }
      sb.append("</COMPILE_PROBLEMS>");
    }
  }
 // Removes all markers from the source resources
 private final void resetMarkers() {
   for (Resource srcResource : sourceResources) {
     if (srcResource != null) {
       IResource res = getIResource(srcResource);
       try {
         IMarker[] markers = res.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE);
         for (int j = 0; j < markers.length; j++) {
           if (markers[j].getAttribute(PreferenceConstants.OCARINA_MARKER) != null) {
             markers[j].delete();
           }
         }
       } catch (CoreException e) {
         throw new RuntimeException(e);
       }
     }
   }
 }
  private boolean hasBookmark(Object object) {
    IMarker[] bookmarks = null;
    IResource resource = null;
    try {
      if (object instanceof EObject) {
        bookmarks =
            ResourcesPlugin.getWorkspace()
                .getRoot()
                .findMarkers(DataToolsUIConstants.SUPER_BOOKMARK, true, IResource.DEPTH_INFINITE);
      } else if (object instanceof IAdaptable
          && (resource = (IResource) ((IAdaptable) object).getAdapter(IResource.class)) != null) {
        bookmarks =
            resource.isAccessible()
                ? resource.findMarkers(
                    DataToolsUIConstants.SUPER_BOOKMARK, true, IResource.DEPTH_INFINITE)
                : null;
      }
    } catch (CoreException e) {
      e.printStackTrace();
    }

    if (bookmarks == null) {
      return false;
    }

    IMarker foundMarker = null;
    String elementID = getElementId(resource != null ? resource : object);
    String attribute;

    for (Iterator i = Arrays.asList(bookmarks).iterator(); i.hasNext(); ) {
      IMarker marker = (IMarker) i.next();
      attribute = (String) marker.getAttribute(ELEMENT_ID, BLANK_ID);
      if (!attribute.equals(BLANK_ID) && attribute.equals(elementID)) {
        foundMarker = marker;
        break;
      }
    }

    if (foundMarker != null) {
      return true;
    }

    return false;
  }
 public static IMarker[] getOwnedMarkers(IResource r, int kind) {
   ArrayList<IMarker> l = null;
   try {
     if (r != null && r.isAccessible()) {
       IMarker[] ms = r.findMarkers(null, false, 1);
       for (IMarker m : ms) {
         if (KB_BUILDER_PROBLEM_MARKER_TYPE.equals(m.getType())
             && m.isSubtypeOf(IMarker.PROBLEM)
             && (kind == m.getAttribute(ATTR_KIND, 1))) {
           if (l == null) {
             l = new ArrayList<IMarker>();
           }
           l.add(m);
         }
       }
     }
   } catch (CoreException e) {
     WebKbPlugin.getDefault().logError(e);
   }
   return (l == null) ? null : l.toArray(new IMarker[0]);
 }
Example #17
0
 private IMarker findMarker(
     IResource resource,
     String type,
     String message,
     int lineNumber,
     int severity,
     boolean isTransient)
     throws CoreException {
   IMarker[] markers = resource.findMarkers(type, false /*includeSubtypes*/, IResource.DEPTH_ZERO);
   if (markers == null || markers.length == 0) {
     return null;
   }
   for (IMarker marker : markers) {
     if (eq(message, marker.getAttribute(IMarker.MESSAGE))
         && eq(lineNumber, marker.getAttribute(IMarker.LINE_NUMBER))
         && eq(severity, marker.getAttribute(IMarker.SEVERITY))
         && eq(isTransient, marker.getAttribute(IMarker.TRANSIENT))) {
       return marker;
     }
   }
   return null;
 }
 // TODO The following code used to use the given ISourceReference to determine which markers
 // lay within the source range of the given entity. We don't yet have ISourceEntity's for
 // anything smaller than a compilation unit, so that functionality will have to wait for an
 // API enhancement.
 private int getErrorTicksFromMarkers(
     IResource res, int depth /*, ISourceReference sourceElement*/) throws CoreException {
   if (res == null || !res.isAccessible()) {
     return 0;
   }
   int info = 0;
   IMarker[] markers = res.findMarkers(IMarker.PROBLEM, true, depth);
   if (markers != null) {
     for (int i = 0; i < markers.length && (info != ERRORTICK_ERROR); i++) {
       IMarker curr = markers[i];
       //              if (sourceElement == null || isMarkerInRange(curr, sourceElement)) {
       int priority = curr.getAttribute(IMarker.SEVERITY, -1);
       if (priority == IMarker.SEVERITY_WARNING) {
         info = ERRORTICK_WARNING;
       } else if (priority == IMarker.SEVERITY_ERROR) {
         info = ERRORTICK_ERROR;
       }
       //              }
     }
   }
   return info;
 }
  /**
   * Returns a list of markers that exist at the current ruler location.
   *
   * @return a list of markers that exist at the current ruler location
   */
  protected List getMarkers() {

    List breakpoints = new ArrayList();

    IResource resource = getResource();
    IDocument document = getDocument();
    AbstractMarkerAnnotationModel model = getAnnotationModel();

    if (model != null) {
      try {

        IMarker[] markers = null;
        if (resource instanceof IFile)
          markers =
              resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
        else {
          IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
          markers = root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE);
        }

        if (markers != null) {
          IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager();
          for (int i = 0; i < markers.length; i++) {
            IBreakpoint breakpoint = breakpointManager.getBreakpoint(markers[i]);
            if (breakpoint != null
                && breakpointManager.isRegistered(breakpoint)
                && includesRulerLine(model.getMarkerPosition(markers[i]), document))
              breakpoints.add(markers[i]);
          }
        }
      } catch (CoreException x) {
        JDIDebugUIPlugin.log(x.getStatus());
      }
    }
    return breakpoints;
  }
    /** @generated */
    public void refresh() {
      removeDecoration();
      View view = (View) getDecoratorTarget().getAdapter(View.class);
      if (view == null || view.eResource() == null) {
        return;
      }
      EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class);
      if (editPart == null || editPart.getViewer() == null) {
        return;
      }

      // query for all the validation markers of the current resource
      String elementId = ViewUtil.getIdStr(view);
      if (elementId == null) {
        return;
      }
      int severity = IMarker.SEVERITY_INFO;
      IMarker foundMarker = null;
      IResource resource = WorkspaceSynchronizer.getFile(view.eResource());
      if (resource == null || !resource.exists()) {
        return;
      }
      IMarker[] markers = null;
      try {
        markers = resource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
      } catch (CoreException e) {
        GSN1DiagramEditorPlugin.getInstance()
            .logError("Validation markers refresh failure", e); // $NON-NLS-1$
      }
      if (markers == null || markers.length == 0) {
        return;
      }
      Label toolTip = null;
      for (int i = 0; i < markers.length; i++) {
        IMarker marker = markers[i];
        String attribute =
            marker.getAttribute(
                org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); // $NON-NLS-1$
        if (attribute.equals(elementId)) {
          int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
          Image nextImage = getImage(nextSeverity);
          if (foundMarker == null) {
            foundMarker = marker;
            toolTip =
                new Label(
                    marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$
                    nextImage);
          } else {
            if (toolTip.getChildren().isEmpty()) {
              Label comositeLabel = new Label();
              FlowLayout fl = new FlowLayout(false);
              fl.setMinorSpacing(0);
              comositeLabel.setLayoutManager(fl);
              comositeLabel.add(toolTip);
              toolTip = comositeLabel;
            }
            toolTip.add(
                new Label(
                    marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$
                    nextImage));
          }
          severity = (nextSeverity > severity) ? nextSeverity : severity;
        }
      }
      if (foundMarker == null) {
        return;
      }

      // add decoration
      if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
        if (view instanceof Edge) {
          setDecoration(getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true));
        } else {
          int margin = -1;
          if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
            margin =
                MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure())
                    .DPtoLP(margin);
          }
          setDecoration(
              getDecoratorTarget()
                  .addShapeDecoration(
                      getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true));
        }
        getDecoration().setToolTip(toolTip);
      }
    }
  public void testMarkers() throws Exception {
    String filename = "src/tjp/GetInfo.aj"; // $NON-NLS-1$
    IResource file = project.findMember(filename);
    if (file == null) fail("Required file not found: " + filename); // $NON-NLS-1$

    IMarker[] allMarkers = file.findMarkers(IMarker.MARKER, true, IResource.DEPTH_INFINITE);
    for (int x = 0; x < allMarkers.length; x++) {
      IMarker marker = allMarkers[x];
      System.out.println(
          marker.getType() + " : " + allMarkers[0].getAttribute(IMarker.MESSAGE)); // $NON-NLS-1$
    }
    for (int i = 0; i < markerTypes.length; i++) {
      IMarker[] markers = file.findMarkers(markerTypes[i], true, IResource.DEPTH_INFINITE);

      // create lists of messages and lines we need to search for
      List tofindMsg = new ArrayList();
      List tofindLine = new ArrayList();
      for (int j = 0; j < results[i].length; j++) {
        if (results[i][j].length == 2) {
          String msg = (String) results[i][j][0];
          tofindMsg.add(msg.intern());
          tofindLine.add(results[i][j][1]);
        }
      }

      for (int j = 0; j < markers.length; j++) {
        IMarker m = markers[j];
        int line = m.getAttribute(IMarker.LINE_NUMBER, -1);
        String msg = m.getAttribute(IMarker.MESSAGE, "").intern(); // $NON-NLS-1$
        //				System.out.println("Keys: " + m.getAttributes().keySet());
        //				System.out.println("Values: " + m.getAttributes().values());

        // System.out.println("msg=" + msg + " line=" + line);
        if (tofindMsg.contains(msg)) {
          // search for matching message and line number
          //  - could be >1 lines with the same message
          //  - we cannot rely on the order of markers
          boolean found = false;
          int foundIndex = 0;
          for (int k = 0; !found && (k < tofindMsg.size()); k++) {
            String msg1 = (String) tofindMsg.get(k);
            if (msg1 == msg) {
              Integer expLine = (Integer) tofindLine.get(k);
              if (expLine.intValue() == line) {
                found = true;
                foundIndex = k;
              }
            }
          }
          if (!found) {
            fail(
                "Expected marker message found, but found at wrong line number: " //$NON-NLS-1$
                    + line
                    + " Message="
                    + msg); //$NON-NLS-1$
          }
          // successfully found message and line so remove from lists
          tofindMsg.remove(foundIndex);
          tofindLine.remove(foundIndex);
        } else {
          fail(
              "Found unexpected marker of type "
                  + markerTypes[i] // $NON-NLS-1$
                  + " with message: "
                  + msg); //$NON-NLS-1$
        }
      }
      // check that we found everything we were looking for
      if (tofindMsg.size() > 0) {
        String missing = ""; // $NON-NLS-1$
        for (int j = 0; j < tofindMsg.size(); j++) {
          missing += System.getProperty("line.separator"); // $NON-NLS-1$
          missing += (String) tofindMsg.get(j);
        }
        fail(
            "Did not find all expected markers of type " //$NON-NLS-1$
                + markerTypes[i]
                + ". Missing: "
                + missing); //$NON-NLS-1$
      }
    }
  }
    /** @not-generated */
    @Override
    public void refresh() {
      removeDecoration();
      View view = (View) getDecoratorTarget().getAdapter(View.class);
      Resource viewResource = null;
      if (view != null) {
        viewResource = view.eResource();
      }
      if (viewResource == null) {
        return;
      }
      EditPart editPart = (EditPart) getDecoratorTarget().getAdapter(EditPart.class);
      if (editPart == null || editPart.getParent() == null || editPart.getViewer() == null) {
        return;
      }

      // query for all the validation markers of the current resource
      String elementId = SiriusGMFHelper.getViewId(view);
      if (elementId == null) {
        return;
      }

      // Directly retrieve the main Session resource
      // (session.getSessionResource()) as we know we put the marker on
      // it.
      Session currentSession = null;
      ResourceSet currentRs = viewResource.getResourceSet();
      for (Session session : SessionManager.INSTANCE.getSessions()) {
        if (currentRs == session.getTransactionalEditingDomain().getResourceSet()) {
          currentSession = session;
          break;
        }
      }
      Resource markedResource = currentSession == null ? null : currentSession.getSessionResource();
      IResource resource = WorkspaceSynchronizer.getFile(markedResource);

      if (resource == null || !resource.exists()) {
        return;
      }
      IMarker[] markers = null;
      try {
        markers = resource.findMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE);
      } catch (CoreException e) {
        DiagramPlugin.getDefault()
            .logError(Messages.StatusDecorator_validationMarkersFailureMsg, e);
      }
      if (markers == null || markers.length == 0) {
        return;
      }

      int severity = IMarker.SEVERITY_INFO;
      IMarker foundMarker = null;
      Label toolTip = null;
      for (int i = 0; i < markers.length; i++) {
        IMarker marker = markers[i];
        String attribute =
            marker.getAttribute(
                org.eclipse.gmf.runtime.common.ui.resources.IMarker.ELEMENT_ID, ""); // $NON-NLS-1$
        if (attribute.equals(elementId)) {
          int nextSeverity = marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
          Image nextImage = getImage(nextSeverity);
          if (foundMarker == null) {
            foundMarker = marker;
            toolTip =
                new Label(
                    marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$
                    nextImage);
          } else {
            if (toolTip.getChildren().isEmpty()) {
              Label comositeLabel = new Label();
              FlowLayout fl = new FlowLayout(false);
              fl.setMinorSpacing(0);
              comositeLabel.setLayoutManager(fl);
              comositeLabel.add(toolTip);
              toolTip = comositeLabel;
            }
            toolTip.add(
                new Label(
                    marker.getAttribute(IMarker.MESSAGE, ""), // $NON-NLS-1$
                    nextImage));
          }
          severity = (nextSeverity > severity) ? nextSeverity : severity;
        }
      }
      if (foundMarker == null) {
        return;
      }

      // add decoration
      if (editPart instanceof org.eclipse.gef.GraphicalEditPart) {
        IDecoration decoration = null;

        if (view instanceof Diagram) {
          // There is not yet defined decorator for a diagram
        } else if (view instanceof Edge) {
          decoration = getDecoratorTarget().addConnectionDecoration(getImage(severity), 50, true);
        } else {
          int margin = -1;
          margin =
              MapModeUtil.getMapMode(((org.eclipse.gef.GraphicalEditPart) editPart).getFigure())
                  .DPtoLP(margin);
          decoration =
              getDecoratorTarget()
                  .addShapeDecoration(
                      getImage(severity), IDecoratorTarget.Direction.NORTH_EAST, margin, true);
        }

        if (decoration != null) {
          setDecoration(decoration);

          // getDecaration() returns a {@link Decoration} instead of a
          // {@link IDecoration}
          getDecoration().setToolTip(toolTip);
        }
      }
    }