Add action to model

Hello,
Here is what I am trying to do:
In a PAB type diagram, I want to be able to display a context menu on a Behavior PC to call an export function. I would like this function to be accessible only on this type of component. The ultimate goal is to retrieve the selected model element to pass it to Acceleo for code generation.

Here is where I am:
I created a classic Eclipse plugin and I can display the context menu. However, this menu is displayed on any digraph element. I tried to create a filter with a class derived from PropertyTester by calling the following code:

@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
    EditPart editPart = (EditPart)receiver;
    System.out.println(receiver.getClass().getName()); // DNodeContainerEditPart

    View gmfElement = LayerUtil.getGmfElement(editPart);
    DSemanticDecorator siriusElement = LayerUtil.getSiriusElement(gmfElement);
    EObject target = siriusElement.getTarget();
    System.out.println(target.eClass().getInstanceClassName()); // org.polarsys.capella.core.data.cs.Part
    System.out.println(target.eClass().getName()); // Part

}

Everything seems to work well when I use the contextual menu from the project explorer but not from the diagram, in which case the problem is that in output I get an object of type Part which is not specific to a Behavior PC. However, when I select this object in the diagram, the property view displays “(Physical Component) Behavior …”; there must therefore be a way.

Finaly, I think that the real question is : how to retreive the PhysicaComponent(Impl) described by the PC Behaviour diagram.

Does anyone have a solution for me?

Thank you in advance …

Hi,
Yes you can use CapellaAdapterHelper;getBusinessObjects(receiver) from the plugin org.polarsys.capella.core.model.handler

Thank you for your answer. I think I was almost there because I end up to call the resolveSemanticObjects. I will try with resolveBusinessObjects as you suggest.

Yes, semantic object will return the capella element behind the diagram shape.
(which is the Part in architecture blank diagrams), the business one will be the component behind the technical element “Part”)

You can also retrieve the Type of the Part (part.getType) which will retrieve the component

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