/**
   * Create a decoration based on a figure
   *
   * @param decoratorTarget the decorator target
   * @param figure the figure
   * @param position the position
   * @param percentageFromSource the percentage from source
   * @param margin the margin
   * @param isVolatile the is volatile
   * @return the decoration
   */
  public final IDecoration createDecorationFigure(
      IDecoratorTarget decoratorTarget,
      IFigure figure,
      int percentageFromSource,
      int margin,
      boolean isVolatile) {

    final View view = (View) decoratorTarget.getAdapter(View.class);
    org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null;
    if (view == null || view.eResource() == null || figure == null) {
      return decoration;
    }
    EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
    if (editPart == null || editPart.getViewer() == null) {
      return decoration;
    }
    if (editPart instanceof GraphicalEditPart) {
      if (view instanceof Edge) {
        decoration =
            decoratorTarget.addConnectionDecoration(figure, percentageFromSource, isVolatile);
      } else {
        IFigure parentFig = ((GraphicalEditPart) editPart).getFigure();
        margin = MapModeUtil.getMapMode(parentFig).DPtoLP(margin);

        // Locator locator = new MultiIconTopRightLocator(parentFig, margin);

        // decoration = decoratorTarget.addDecoration(figure, locator, isVolatile);
        decoration =
            decoratorTarget.addShapeDecoration(
                figure, IDecoratorTarget.Direction.NORTH_EAST, margin, isVolatile);
      }
    }
    return decoration;
  }
 /** @generated */
 public static List getEvent_2008IncomingLinks(View view) {
   hub.top.adaptiveSystem.Event modelElement = (hub.top.adaptiveSystem.Event) view.getElement();
   Map crossReferences =
       EcoreUtil.CrossReferencer.find(view.eResource().getResourceSet().getResources());
   List result = new LinkedList();
   result.addAll(getIncomingTypeModelFacetLinks_ArcToEvent_3002(modelElement, crossReferences));
   return result;
 }
 /** {@inheritDoc} */
 public List getAffectedFiles() {
   if (viewer != null) {
     EditPart editpart = viewer.getRootEditPart().getContents();
     if (editpart instanceof IGraphicalEditPart) {
       View view = (View) ((IGraphicalEditPart) editpart).getModel();
       if (view != null) {
         IFile f = WorkspaceSynchronizer.getFile(view.eResource());
         return f != null ? Collections.singletonList(f) : Collections.EMPTY_LIST;
       }
     }
   }
   return super.getAffectedFiles();
 }
  /**
   * Create a decoration based on an image
   *
   * @param decoratorTarget the decorator target
   * @param image the image
   * @param position the position
   * @param percentageFromSource the percentage from source, only evaluated for edge decorations
   * @param margin the margin in pixels from the target position. @See
   *     org.eclipse.gmf.runtime.diagram.ui.services.decorator.addShapeDecoration: The margin is the
   *     space, in himetric units, between the shape's edge and the decoration. A positive margin
   *     will place the figure outside the shape, a negative margin will place the decoration inside
   *     the shape.
   * @param isVolatile the is volatile
   * @return the decoration
   */
  public final IDecoration createDecorationImage(
      IDecoratorTarget decoratorTarget,
      Image image,
      int percentageFromSource,
      int margin,
      boolean isVolatile) {
    final View view = (View) decoratorTarget.getAdapter(View.class);
    org.eclipse.gmf.runtime.diagram.ui.services.decorator.IDecoration decoration = null;
    if (view == null || view.eResource() == null || image == null) {
      return decoration;
    }
    EditPart editPart = (EditPart) decoratorTarget.getAdapter(EditPart.class);
    if (editPart == null || editPart.getViewer() == null) {
      return decoration;
    }
    if (view instanceof Edge) {

      decoration = decoratorTarget.addConnectionDecoration(image, percentageFromSource, isVolatile);

    } else {

      IPrimaryEditPart primaryEditPart = getPrimaryEditPart(editPart);

      if (primaryEditPart != null && primaryEditPart instanceof GraphicalEditPart) {
        IFigure parentFig = ((GraphicalEditPart) primaryEditPart).getFigure();

        // only support figures with handle bounds
        Locator locator = new MultiIconTopRightLocator(parentFig, margin);

        // Direction NORTH_EAST will be ignored, since we impose
        // "our" locator below
        decoration =
            decoratorTarget.addShapeDecoration(
                image, IDecoratorTarget.Direction.NORTH_EAST, margin, isVolatile);
        if (decoration instanceof Decoration) {
          ((Decoration) decoration).setLocator(locator);
        }
      }
    }
    return decoration;
  }
    /** @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);
        }
      }
    }
    /** @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);
      }
    }