Пример #1
0
  protected void handleResourceLoaded(Resource resource) {
    final ModelSet modelSet = (ModelSet) resource.getResourceSet();

    StereotypeRepairService.startedRepairing(modelSet);
    boolean presented = false;

    try {
      ZombieStereotypesDescriptor zombies = getZombieStereotypes(resource);

      if ((zombies != null) && (presenter != null)) {
        presenter.addZombies(zombies);
        presenter.onPendingDone(
            new Runnable() {

              public void run() {
                StereotypeRepairService.finishedRepairing(modelSet);
              }
            });
      }

      presented = (presenter != null) && presenter.isPending();
    } finally {
      if (!presented) {
        StereotypeRepairService.finishedRepairing(modelSet);
      }
    }
  }
Пример #2
0
  public void dispose(ModelSet modelsManager) {
    if (presenter != null) {
      presenter.dispose();
      presenter = null;
    }

    if (localLabelProvider) {
      try {
        labelProviderService.disposeService();
      } catch (ServiceException e) {
        Activator.log.error(e);
      } finally {
        labelProviderService = null;
        localLabelProvider = false;
      }
    }

    adapter.unadapt(modelsManager);
  }
Пример #3
0
  protected ZombieStereotypesDescriptor getZombieStereotypes(Resource resource, Package root) {
    ZombieStereotypesDescriptor result = null;

    Collection<ProfileApplication> profileApplications = Lists.newArrayList();
    for (TreeIterator<EObject> iter =
            EcoreUtil.getAllProperContents(Collections.singleton(root), false);
        iter.hasNext(); ) {
      EObject next = iter.next();
      if (next instanceof ProfileApplication) {
        profileApplications.add((ProfileApplication) next);
        iter.prune();
      } else if (!(next instanceof Package) && !(next instanceof Component)) {
        // No sense looking for packages except in the things that can contain packages
        iter.prune();
      }
    }

    Set<EPackage> appliedDefinitions = getAppliedDefinitions(profileApplications);

    Function<? super EPackage, Profile> profileSupplier = dynamicProfileSupplier;
    if (profileSupplier == null) {
      profileSupplier = presenter.getDynamicProfileSupplier();
    }

    ZombieStereotypesDescriptor zombies =
        new ZombieStereotypesDescriptor(
            resource, root, appliedDefinitions, profileSupplier, getLabelProvider());

    for (EObject next : resource.getContents()) {
      if (!(next instanceof Element)) {
        zombies.analyze(next);
      }
    }

    if (zombies.hasZombies()) {
      result = zombies;
    }

    return result;
  }
Пример #4
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;
  }