@Override
  public void run() {
    Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

    RegisteredPackageDialog registeredPackageDialog = new RegisteredPackageDialog(shell);
    registeredPackageDialog.open();
    Object[] results = registeredPackageDialog.getResult();
    // if user cancel the selection of meta models, results = null
    if (results != null) {
      ResourceSet resourceSet = this.domain.getResourceSet();
      for (Object result : results) {
        URI uri = URI.createURI(result.toString());
        Resource r = resourceSet.getResource(uri, true);
        if (!resourceSet.getResources().contains(r)) {
          Registry packageRegistry = resourceSet.getPackageRegistry();
          for (EObject eObject : r.getContents()) {
            if (eObject instanceof EPackage) {
              EPackage ePackage = (EPackage) eObject;
              packageRegistry.put(ePackage.getNsURI(), ePackage);
            }
          }
          resourceSet.getResources().add(r);
        }
      }
    }
  }
  @Test
  public void testUnregisterMultipleUsage() throws IOException {
    // register
    EcoreHelper.registerEcore(aEcorePath);
    EcoreHelper.registerEcore(bEcorePath);
    EcoreHelper.registerEcore(cEcorePath);
    assertTrue("Package A not in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertTrue("Package B not in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertTrue("Package C not in the registry!", packageRegistry.containsKey("c.nsuri"));

    // unregister C references B
    EcoreHelper.unregisterEcore(cEcorePath);
    assertTrue("Package A not in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertTrue("Package B not in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertFalse("Package C is already in the registry!", packageRegistry.containsKey("c.nsuri"));

    // unregister B references A
    EcoreHelper.unregisterEcore(bEcorePath);
    assertTrue("Package A not in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertFalse("Package B is already in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertFalse("Package C is already in the registry!", packageRegistry.containsKey("c.nsuri"));

    // unregister A
    EcoreHelper.unregisterEcore(aEcorePath);
    assertFalse("Package A is already in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertFalse("Package B is already in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertFalse("Package C is already in the registry!", packageRegistry.containsKey("c.nsuri"));
  }
  /**
   * Returns all EPackages on the root level that are currently registered in the registry.
   *
   * @return a Set of all root EPackages
   * @see Registry
   */
  public static Set<EPackage> getAllRootEPackages() {
    // were the root packages computed before?
    if (rootModelPackages != null) {
      return rootModelPackages;
    }
    rootModelPackages = new LinkedHashSet<EPackage>();
    Registry registry = EPackage.Registry.INSTANCE;

    for (Entry<String, Object> entry : registry.entrySet()) {
      EPackage ePackage = registry.getEPackage(entry.getKey());
      // is the current EPackage a root package?
      if (ePackage.getESuperPackage() == null) {
        rootModelPackages.add(ePackage);
      }
    }
    return rootModelPackages;
  }
 /**
  * Iterates over all registered EPackages in order to retrieve all available EClasses, excluding
  * abstract classes and interfaces, and returns them as a Set.
  *
  * @return a set of all EClasses that are contained in registered EPackages
  * @see Registry
  */
 public static List<EClass> getAllEClasses() {
   // were all EClasses computed before?
   if (allEClasses != null) {
     return allEClasses;
   }
   allEClasses = new LinkedList<EClass>();
   Registry registry = EPackage.Registry.INSTANCE;
   // for all registered EPackages
   for (Entry<String, Object> entry : registry.entrySet()) {
     EPackage ePackage = registry.getEPackage(entry.getKey());
     for (EClass eClass : getAllEClasses(ePackage)) {
       // no abstracts or interfaces
       if (canHaveInstance(eClass)) {
         allEClasses.add(eClass);
       }
     }
   }
   return allEClasses;
 }
Esempio n. 5
0
 public void testExternalFormOfEReference() throws Exception {
   Registry registry = EPackage.Registry.INSTANCE;
   Set<String> uris = Sets.newHashSet(registry.keySet());
   for (String string : uris) {
     EPackage ePackage = registry.getEPackage(string);
     TreeIterator<Object> iterator = EcoreUtil.getAllProperContents(ePackage, true);
     while (iterator.hasNext()) {
       Object next = iterator.next();
       if (next instanceof EReference) {
         EReference ref = (EReference) next;
         String externalForm = EcoreUtil2.toExternalForm(ref);
         assertEquals(
             ref.toString() + " - " + externalForm,
             ref,
             EcoreUtil2.getEReferenceFromExternalForm(registry, externalForm));
       }
     }
   }
 }
  @Test
  public void testRegisterUnregister() throws IOException {

    // check initial state
    assertFalse("Package A is already in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertFalse("Package B is already in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertFalse("Package C is already in the registry!", packageRegistry.containsKey("c.nsuri"));

    // register C references B references A
    EcoreHelper.registerEcore(cEcorePath);
    assertTrue("Package A not in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertTrue("Package B not in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertTrue("Package C not in the registry!", packageRegistry.containsKey("c.nsuri"));

    EcoreHelper.unregisterEcore(cEcorePath);
    assertFalse("Package A is already in the registry!", packageRegistry.containsKey("a.nsuri"));
    assertFalse("Package B is already in the registry!", packageRegistry.containsKey("b.nsuri"));
    assertFalse("Package C is already in the registry!", packageRegistry.containsKey("c.nsuri"));
  }