Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Capella/Tutorials/Extensibility/Edit
Contents
Access to Session/ExecutionManager/EditingDomain
When we open an aird (doucle click on it),
A Session
is created containing a TransactionalEditingDomain
which contains a ResourceSet
containing all Resource
(s) loaded, containing all EObjects. It is editable through a ExecutionManager
.
- EObject is the EMF element (Function, Component, graphical element, etc)
- Resource is the EMF representation of the XML files (aird, melodymodeller) containing all EObject
- ResourceSet is the list of all Resources loaded (melodymodeller, aird, odesign, etc)
- TransactionalEditingDomain allows to access element/model/diagrams in a Thread-safe environnement. All modifications in Capella are done within it.
- ExecutionManager is the API main access to be able to edit an element.
- Session is the API main access to Diagrams
==
Session
Session SessionManager DialectManager API Queries
Session session = SessionManager.INSTANCE.getSession(EObject object); Session session = SessionManager.INSTANCE.getExistingSession(EcoreUtil2.getURI(airdFile));
TransactionalEditingDomain
TransactionHelper TransactionUtil EObjectExt TransactionalEditingDomain
TransactionalEditingDomain domain = TransactionHelper.getEditingDomain(element) //from org.polarsys.capella.common.helpers TransactionalEditingDomain domain = TransactionHelper.getEditingDomain(resource) TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
ExecutionManager
ExecutionManager TransactionHelper AbstractReadWriteCommand
ExecutionManager manager = TransactionHelper.getExecutionManager(element) ExecutionManager manager = TransactionHelper.getExecutionManager(resource)
Create a new TransactionalEditingDomain for Capella models:
ExecutionManager manager = ExecutionManagerRegistry.getInstance().addNewManager(); TransactionalEditingDomain domain = manager.getEditingDomain();
IFile/Resource
EcoreUtil2.getFile(Resource) EcoreUtil2.getURI(file)
element.eResource()
Helpers
Many helpers exist in Capella, they are mainly located inside following plugins and have *Ext
name
- org.polarsys.capella.core.data.helpers - org.polarsys.capella.core.model.helpers
For instance
FunctionExt, FunctionalExchangeExt, ComponentExt...
All capella elements have derived methods allowing direct access to other interesting elements. For instance, for an actor, actor.getAllocatedFunctions() retrieve the list of the allocated functions). These methods are computed in :
org.polarsys.capella.core.data.helpers org.polarsys.capella.core.data.helpers.*.delegates.**Helper
It can be interesting to see how these methods are computed to understand how a reference between two element is stocked in the model.
Access all diagrams
IFile airdFile = ... Session session = SessionManager.INSTANCE.getExistingSession(EcoreUtil2.getURI(airdFile)); for (DRepresentationDescriptor descriptor : DialectManager.INSTANCE.getAllRepresentationDescriptors(session)) { descriptor.getRepresentation(); //will return the diagram descriptor.getTarget()); //will return the element owning the diagram (for instance, the PhysicalComponent in a PAB diagram) }
Access all graphical elements in a diagram
DDiagram diagram = (DDiagram)descriptor.getRepresentation(); //warning! directCast but there may have also DTable, DTree.. for (DDiagramElement element: diagram.getDiagramElements()) { //for all main elements in diagram System.out.println(element); //here we have the graphical element if (element instanceof DEdge) { DEdge edge = (DEdge)element; edge.getSourceNode() edge.getTargetNode() edge.getStyle() } else if (element instanceof DNodeContainer, DNode, DNodeList) { ((DNodeContainer/DNode/DNodeList)element).getOwnedBorderedNodes() ((DNodeContainer/DNode/DNodeList)element).getStyle() Node a = SiriusGMFHelper.getGmfNode(element); //here we have the GMF graphical element System.out.println("located: "+a.getLayoutConstraint()); //display the location of the element } }
Edit an element
All editions in Capella is made through an TransactionalEditingDomain that guarantee a Thread-safe environnement. Any modification on model, diagram must be done through a command, like :
EObject element = ... ExecutionManager manager = TransactionHelper.getExecutionManager(element).execute(new AbstractReadWriteCommand() { @Override public void run() { if (element instanceof PhysicalComponent) { PhysicalComponent pc = (PhysicalComponent)element; pc.setName("toto"); } } });
Create an element
To create an element, you need to know its type (for instance by looking at the properties view) and know from which metamodel it comes from. [1]
By using Open Type wizard (Ctrl+Shift+T) and writing the type, you will find it. PhysicalFunction, you will see org.polarsys.capella.xxx.pa.PhysicalFunction.
Using PaFactory, you will have access to PaFactory.eINSTANCE.createPhysicalFunction
EObject element = ... //an element from physical layer ExecutionManager manager = TransactionHelper.getExecutionManager(element).execute(new AbstractReadWriteCommand() { @Override public void run() { BlockArchitecture physicalArchitecture = BlockArchitectureExt.getRootBlockArchitexture(element); PhysicalFunction pf = (PhysicalFunction)BlockArchitectureExt.getRootFunction(physicalArchitecture); PhysicalFunction myNewFunc = PaFactory.eINSTANCE.createPhysicalFunction("new function"); pf.getOwnedPhysicalFunctions().add(myNewFunc); } });
EMF API (Generic access)
EObject EClass EStructuralFeature Resource ResourceSet
EObject object = ...
element.eResource()
object.eContents()
//returns all direct children of the element
object.eAllContents()
//returns all children recursively
object.eClass()
//returns the Metaclass of the given element
object.eClass().getAllReferences()
//returns the Metaclass references of the given element
object.eClass().getAllAttributes()
//returns the Metaclass references of the given element
object.eGet(object.eClass().getEStructuralFeature("name"))
// returns the name of the element
BUT, if you know the metaclass, it's faster to use getName()
method.
((PhysicalFunction)object.getName())
for instance
object.eSet(object.eClass().getEStructuralFeature("name"), "newName")
//set the name of the element
((EList)object.eGet(object.eClass().getEStructuralFeature("ownedElements"))).add(element)
//add element to object.ownedElements