Accessing elements from different EMF (libraries)

Greetings,

I have developed a viewpoint that, on a click event on any Capella component (the_component), triggers an OpenAction(the_component) that is able to navigate in the EMF of the project thanks to the_component parameter, and sort all those elements into lists that I can use later on.
However, I am working with a Capella project that is referencing one library. Of course, those elements contained in the library are not parsed by my viewpoint as they belong to another EMF. After a week of struggling, my question is : how can I retrieve at least one component from the library so that I can parse it fully as the main project ?

Note that if I run the OpenAction by clicking on an element on a diagram that belongs to the library, the viewpoint is parsing correctly the EMF of the library, but not the EMF of the project.

I have tried to access the libraries from their graphical elements using https://wiki.eclipse.org/Capella/Tutorials/Extensibility/Edit.
Using the given code, I have been able to access all graphical elements in a diagram. Nonetheless, I have not found how to access a component from its representation, I guess its DDiagramElement. This solution would be the best for me as I would like to sort the elements later, according to the diagram they are displayed on.

I hope my problem is clear, thanks in advance for your help,
Have a great day,
Antonin

Hello,

I have been able to retrieve a TreeIterator of my library’s melodymodeller with :

URI URI1 = URI.createFileURI("C:/path/myLibrary.melodymodeller");  
        ResourceSet resourceSet = new ResourceSetImpl();
        Resource resource = resourceSet.getResource(URI1, true);
        TreeIterator<EObject> myTreeIterator = ((CapellamodellerResourceImpl) resource).getContents().get(0).eAllContents();

with of course after :

while(myTreeIterator.hasNext())
	{
	node = myTreeIterator.next();
	if (node instanceof LogicalFunction)
	       {
			LogicalFunction lf = (LogicalFunction) node;
			ListCapellaElement.add(lf);
                        ...
	       }
               ...
        }

This URI I am accessing could have been another project or a library, it doesn’t matter. So this problem is solved.

Nonetheless, if someone has an idea about how can I link a graphical element with the EObject it is describing (ie. accessing an EObject from its representation on a diagram), I am still interested.

Regards,
Antonin

Hi,

From the OpenAction(component)
If the model references some libraries, you can use something like

_component.eResource().getResourceSet().getResources()

to retrieve the list of all loaded resources, and among other, the melodymodellers files.
or

Session session = SessionManager.INSTANCE.getSession(_component)
 session.getSemanticResources()





if (resource.getUri().xxx == "Library.melodymodeller") 
xxx
}

For diagrams elements,

a diagram is composed by diagram elements, (diagram.getDiagramElements) which are referencing “semantic elements” such as the component.

for (DDiagramElement e: diagram.getDiagramElements()) {
  if (e instanceof DSemanticDecorator) {
     if (((DSemanticDecorator)e.getTarget()) instanceof Component) {
      //xxxx
     }
  }
}

DDiagramElement sub types can be DNode (not decomposable, ex port, function in architecture blank), DEdge, DNodeContainer (decomposable, ex components in Architecture Blank) or DNodeList (like classes in class diagram blank)

Hello,

First thank you for your answers,

It works well. I had been stuck while trying to reach the instance of the LogicalFunction from the instance of its DDiagramElement, but the method .getTarget() allowed me to achieve that.
Thanks again,

Regards,
Antonin

Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.