Java Code Examples for org.eclipse.emf.ecore.util.EcoreUtil#getObjectsByType()

The following examples show how to use org.eclipse.emf.ecore.util.EcoreUtil#getObjectsByType() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
@Override
public void process ( final OscarContext ctx, final EquinoxApplication application, final IProgressMonitor monitor )
{
    try
    {
        final Collection<Object> modules = EcoreUtil.getObjectsByType ( application.getModules (), MemoryManagerPackage.Literals.MEMORY_MANAGER_MODULE );

        if ( modules.isEmpty () )
        {
            return;
        }
        if ( modules.size () > 1 )
        {
            throw new IllegalStateException ( String.format ( "There must only be one module instance of type: %s", MemoryManagerModule.class.getName () ) );
        }

        process ( ctx, application, (MemoryManagerModule)modules.iterator ().next (), monitor );
    }
    finally
    {
        monitor.done ();
    }
}
 
Example 2
/**
 * Returns the {@link Diagram} that contains a given semantic element.
 */
public static Diagram getDiagramContaining(EObject element) {
	Assert.isNotNull(element);
	Resource eResource = element.eResource();
	Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
			NotationPackage.Literals.DIAGRAM);
	for (Diagram diagram : objects) {
		TreeIterator<EObject> eAllContents = diagram.eAllContents();
		while (eAllContents.hasNext()) {
			EObject next = eAllContents.next();
			if (next instanceof View) {
				if (EcoreUtil.equals(((View) next).getElement(), element)) {
					return ((View) next).getDiagram();
				}
			}
		}
	}
	return null;
}
 
Example 3
public static View findNotationView(EObject semanticElement) {
	Collection<Diagram> objects = EcoreUtil.getObjectsByType(semanticElement.eResource().getContents(),
			NotationPackage.Literals.DIAGRAM);
	for (Diagram diagram : objects) {
		TreeIterator<EObject> eAllContents = diagram.eAllContents();
		while (eAllContents.hasNext()) {
			EObject next = eAllContents.next();
			if (next instanceof View) {
				if (((View) next).getElement() == semanticElement) {
					return ((View) next);
				}
			}
		}
	}
	return null;
}
 
Example 4
protected Collection<ImportScope> getImportScopes(final Resource resource) {
	StatechartSpecification specification = (StatechartSpecification) EcoreUtil
			.getObjectByType(resource.getContents(), StextPackage.Literals.STATECHART_SPECIFICATION);
	if (specification != null) {
		return EcoreUtil.getObjectsByType(specification.getScopes(), StextPackage.Literals.IMPORT_SCOPE);
	} else {
		Statechart statechart = utils.getStatechart(resource);
		if (statechart == null) {
			return new LinkedHashSet<>();
		}
		return EcoreUtil.getObjectsByType(statechart.getScopes(), StextPackage.Literals.IMPORT_SCOPE);
	}
}
 
Example 5
/**
 * Returns the Subdiagram for a given {@link State} or {@link Statechart}
 * 
 */
public static Diagram getSubDiagram(CompositeElement element) {
	Assert.isNotNull(element);
	Resource eResource = element.eResource();
	Collection<Diagram> objects = EcoreUtil.getObjectsByType(eResource.getContents(),
			NotationPackage.Literals.DIAGRAM);
	for (Diagram diagram : objects) {
		if (EcoreUtil.equals(diagram.getElement(), element))
			return diagram;
	}
	return null;
}
 
Example 6
Source Project: textuml   File: PackageRenderer.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public boolean renderObject(Package package_, IndentedPrintWriter pw, IRenderingSession context) {
    renderPrologue(package_, pw, context);
    pw.println();

    List<ProfileApplication> profileApplications = package_.getProfileApplications();
    if (!profileApplications.isEmpty()) {
        RenderingUtils.renderAll(context, profileApplications);
        pw.println();
    }

    List<PackageImport> packageImports = package_.getPackageImports();
    if (!packageImports.isEmpty()) {
        RenderingUtils.renderAll(context, packageImports);
        pw.println();
    }

    List<ElementImport> elementImports = package_.getElementImports();
    if (!elementImports.isEmpty()) {
        RenderingUtils.renderAll(context, elementImports);
        pw.println();
    }

    final Collection<Classifier> subPackages = EcoreUtil.getObjectsByType(package_.getOwnedElements(),
            UMLPackage.Literals.PACKAGE);
    RenderingUtils.renderAll(context, subPackages);

    final Collection<Classifier> classifiers = EcoreUtil.getObjectsByType(package_.getOwnedElements(),
            UMLPackage.Literals.CLASSIFIER);
    RenderingUtils.renderAll(context, classifiers);

    renderEpilogue(package_, pw, context);
    return true;
}