protected Resource getNotationResource(ModelSet modelSet, EObject owner, EObject element) {
    if (element
        == null) { // If the element is null, the root element of the main model will be used.
      // Return the main notation resource
      return NotationUtils.getNotationResource(modelSet);
    }
    URI uriWithoutExtension = element.eResource().getURI().trimFileExtension();

    URI notationURI =
        uriWithoutExtension.appendFileExtension(NotationModel.NOTATION_FILE_EXTENSION);
    Resource notationResource = modelSet.getResource(notationURI, false);

    // The resource doesn't exist. Maybe we're trying to create a
    // diagram on a pure-UML library. Try to create a new resource
    if (notationResource == null) {
      notationResource = modelSet.createResource(notationURI);
      if (notationResource == null) {
        modelSet.getResources().remove(notationResource);
        return null;
      }

      EditingDomain editingDomain = EMFHelper.resolveEditingDomain(element);

      if (EMFHelper.isReadOnly(notationResource, editingDomain)) {
        // Check whether the resource can be made writable
        IReadOnlyHandler2 roHandler = ReadOnlyManager.getReadOnlyHandler(editingDomain);
        if (roHandler
            .canMakeWritable(ReadOnlyAxis.anyAxis(), new URI[] {notationResource.getURI()})
            .or(false)) {
          return notationResource; // The read-only manager will eventually ask for a user
          // confirmation
        } else {
          modelSet.getResources().remove(notationResource);
          return null; // The resource can't be made writable; don't go further
        }
      }
    }

    return notationResource;
  }
Пример #2
0
  public IStatus repair(ModelSet modelSet) {
    IStatus result = Status.OK_STATUS;

    if (presenter != null) {
      for (Resource next : ImmutableList.copyOf(modelSet.getResources())) {
        if (next.isLoaded()) {
          handleResourceLoaded(next);
        }
      }

      // Wait for the presenter to have shown its dialog and finished
      try {
        presenter.awaitPending(false);

        // Did we fix all of the zombies?
        for (Resource next : ImmutableList.copyOf(modelSet.getResources())) {
          if (next.isLoaded() && (getZombieStereotypes(next) != null)) {
            result =
                new Status(
                    IStatus.WARNING,
                    Activator.PLUGIN_ID,
                    "Stereotype repair did not successfully repair all stereotype application problems.");
            break;
          }
        }
      } catch (InterruptedException e) {
        result =
            new Status(
                IStatus.ERROR,
                Activator.PLUGIN_ID,
                "Stereotype repair was interrupted while waiting for user input.",
                e);
      }
    }

    return result;
  }