Skip to main content

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.

Jump to: navigation, search

Difference between revisions of "Capella/Tutorials/Extensibility/Edit"

m (Access to Session/ExecutionManager/EditingDomain)
 
m (Replaced content with "This page has been moved to https://github.com/eclipse/capella/wiki/Tutorials")
 
Line 1: Line 1:
 
+
This page has been moved to https://github.com/eclipse/capella/wiki/Tutorials
=Access to Session/ExecutionManager/EditingDomain=
+
When we open an aird (doucle click on it),
+
 
+
A <code>Session</code> is created containing a <code>TransactionalEditingDomain</code> which contains a <code>ResourceSet</code> containing all <code>Resource</code>(s) loaded, containing all EObjects. It is editable through a <code>ExecutionManager</code> .
+
 
+
- 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==
+
[http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/Session.java Session]
+
[http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/session/SessionManager.java SessionManager]
+
[http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/dialect/DialectManager.java DialectManager]
+
[http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius/src/org/eclipse/sirius/business/api/query API Queries]
+
 
+
[http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.diagram/src-gen/org/eclipse/sirius/diagram Diagram M2]
+
[https://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.diagram/src-core/org/eclipse/sirius/diagram/business/api/query Diagram Queries]
+
 
+
<pre>
+
Session session = SessionManager.INSTANCE.getSession(EObject object);
+
Session session = SessionManager.INSTANCE.getExistingSession(EcoreUtil2.getURI(airdFile));
+
</pre>
+
 
+
==TransactionalEditingDomain ==
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.helpers/src/org/polarsys/capella/common/helpers/TransactionHelper.java TransactionHelper]
+
[http://git.eclipse.org/c/emf-transaction/org.eclipse.emf.transaction.git/tree/org.eclipse.emf.transaction/src/org/eclipse/emf/transaction/util/TransactionUtil.java TransactionUtil]
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.helpers/src/org/polarsys/capella/common/helpers/EObjectExt.java EObjectExt]
+
[https://git.eclipse.org/c/emf-transaction/org.eclipse.emf.transaction.git/tree/org.eclipse.emf.transaction/src/org/eclipse/emf/transaction/TransactionalEditingDomain.java TransactionalEditingDomain]
+
 
+
<pre>
+
TransactionalEditingDomain domain = TransactionHelper.getEditingDomain(element) //from org.polarsys.capella.common.helpers
+
TransactionalEditingDomain domain = TransactionHelper.getEditingDomain(resource)
+
TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
+
</pre>
+
 
+
==ExecutionManager ==
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.ef/src/org/polarsys/capella/common/ef/ExecutionManager.java ExecutionManager]
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.helpers/src/org/polarsys/capella/common/helpers/TransactionHelper.java TransactionHelper]
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common.ef/src/org/polarsys/capella/common/ef/command/AbstractReadWriteCommand.java AbstractReadWriteCommand]
+
 
+
 
+
<pre>
+
ExecutionManager manager = TransactionHelper.getExecutionManager(element)
+
ExecutionManager manager = TransactionHelper.getExecutionManager(resource)
+
</pre>
+
 
+
 
+
Create a new TransactionalEditingDomain for Capella models:
+
<pre>
+
ExecutionManager manager = ExecutionManagerRegistry.getInstance().addNewManager();
+
TransactionalEditingDomain domain = manager.getEditingDomain();
+
</pre>
+
 
+
==IFile/Resource==
+
[https://git.polarsys.org/c/capella/capella.git/tree/common/plugins/org.polarsys.capella.common/src/org/polarsys/capella/common/helpers/EcoreUtil2.java EcoreUtil2]
+
 
+
<pre>
+
EcoreUtil2.getFile(Resource)
+
EcoreUtil2.getURI(file)
+
</pre>
+
 
+
<pre>
+
element.eResource()
+
</pre>
+
 
+
= Helpers =
+
Many helpers exist in Capella, they are mainly located inside following plugins and have <code>*Ext</code> name
+
 
+
- [https://git.polarsys.org/c/capella/capella.git/tree/core/plugins/org.polarsys.capella.core.data.helpers org.polarsys.capella.core.data.helpers]
+
- [https://git.polarsys.org/c/capella/capella.git/tree/core/plugins/org.polarsys.capella.core.model.helpers org.polarsys.capella.core.model.helpers]
+
 
+
 
+
For instance
+
<pre>
+
FunctionExt, FunctionalExchangeExt, ComponentExt...
+
</pre>
+
 
+
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 :
+
<pre>
+
org.polarsys.capella.core.data.helpers
+
org.polarsys.capella.core.data.helpers.*.delegates.**Helper
+
</pre>
+
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=
+
<pre>
+
 
+
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)
+
}
+
 
+
</pre>
+
 
+
=Access all graphical elements in a diagram=
+
<pre>
+
 
+
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
+
  }
+
 
+
}
+
</pre>
+
 
+
=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 :
+
 
+
<pre>
+
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");
+
    }
+
  }
+
});
+
</pre>
+
 
+
=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.
+
[https://wiki.polarsys.org/Capella/Tutorials/Extensibility/Metamodel]
+
 
+
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 '''Pa'''Factory, you will have access to '''Pa'''Factory.eINSTANCE.create'''PhysicalFunction'''
+
 
+
<pre>
+
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);
+
 
+
  }
+
});
+
</pre>
+
 
+
= EMF API (Generic access) =
+
[https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EObject.java EObject]
+
[https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EClass.java EClass]
+
[https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/EStructuralFeature.java EStructuralFeature]
+
[https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/Resource.java Resource]
+
[https://git.eclipse.org/c/emf/org.eclipse.emf.git/tree/plugins/org.eclipse.emf.ecore/src/org/eclipse/emf/ecore/resource/ResourceSet.java ResourceSet]
+
 
+
 
+
 
+
EObject object = ...
+
 
+
<pre>
+
element.eResource()
+
</pre>
+
 
+
<code>object.eContents()</code> //returns all direct children of the element
+
 
+
<code>object.eAllContents()</code> //returns all children recursively
+
 
+
<code>object.eClass()</code> //returns the Metaclass of the given element
+
 
+
<code>object.eClass().getAllReferences()</code> //returns the Metaclass references of the given element
+
 
+
<code>object.eClass().getAllAttributes()</code> //returns the Metaclass references of the given element
+
 
+
<code>object.eGet(object.eClass().getEStructuralFeature("name"))</code> // returns the name of the element
+
 
+
BUT, if you know the metaclass, it's faster to use <code>getName()</code> method.
+
<code>((PhysicalFunction)object.getName())</code> for instance
+
 
+
<code>object.eSet(object.eClass().getEStructuralFeature("name"), "newName")</code> //set the name of the element
+
 
+
<code>((EList)object.eGet(object.eClass().getEStructuralFeature("ownedElements"))).add(element)</code> //add element to object.ownedElements
+

Latest revision as of 05:09, 29 October 2021

This page has been moved to https://github.com/eclipse/capella/wiki/Tutorials

Back to the top