Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Sirius » Get selected item value in capella diagram
Get selected item value in capella diagram [message #1817009] Wed, 13 November 2019 18:02 Go to next message
Emmanuel SEMO is currently offline Emmanuel SEMOFriend
Messages: 7
Registered: October 2019
Junior Member
Hello everybody,

I need your help on a point, I currently have an Exchange Scenario in Capella with a sequence diagram. I would like to know if it is possible to retrieve the element selected in the diagram with a class in JAVA ? And does it need a service for this?

Thanks and regards,

Emmanuel
Re: Get selected item value in capella diagram [message #1817025 is a reply to message #1817009] Thu, 14 November 2019 09:26 Go to previous messageGo to next message
Maxime Porhel is currently offline Maxime PorhelFriend
Messages: 476
Registered: July 2009
Location: Nantes, France
Senior Member
Hi Emmanuel,

It mainly depends from where you Java code will be called.

The more generic way would be to use the selection service of the platform, it would be accurate if this code is intended to be used in a View, a command, an action which do not already provide you the selection or a custom extraction of it:
ISelection currentSelection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof StructuredSelection) {
    StructuredSelection s = (StructuredSelection) currentSelection;
    if (s.getFirstElement() instanceof org.eclipse.sirius.diagram.ui.edit.api.part.IDiagramElementEditPart) {
         IDiagramElementEditPart part = (IDiagramElementEditPart) s.getFirstElement();
         EObject capellaObject = part.resolveTargetSemanticElement();     
       
        ...
    } 
}

Note that you could improve this snippet to get the active editor and its selection or do additional checks.

If you look for the selection from another entry point in Sirius (like from a service or in an expression or a tool defined in the VSM), we might need more info to help you to find the more effective way to get the selection in the current Sequence editor.
Regards,


Maxime Porhel - Obeo

Need training or professional services for Sirius?
http://www.obeodesigner.com/sirius

Join the Sirius community at SiriusCon. Register for free: Nov. 9th Paris
http://www.siriuscon.org/

[Updated on: Thu, 14 November 2019 09:30]

Report message to a moderator

Re: Get selected item value in capella diagram [message #1817029 is a reply to message #1817025] Thu, 14 November 2019 09:51 Go to previous message
Emmanuel SEMO is currently offline Emmanuel SEMOFriend
Messages: 7
Registered: October 2019
Junior Member
Hi Maxime,

First of all thank you for your answer. To explain my case a little bit I have a view which is creating a new tab just after the properties tab. And I want to retrieve the selected element in the method "createPartControl" of the view.
I'm currently trying to test your code to see if it is returning the correct object.

I hope the explanations are better.

Edit : the code seems nice but I would like to know how can you retrieve the element "Name" from the Eobject capellaObject ?

Thanks and regards,

Emmanuel

[Updated on: Thu, 14 November 2019 09:59]

Report message to a moderator

Previous Topic:Label alignment 'center' not working for svg workspace image style
Next Topic:How to control size of drawing canvas
Goto Forum:
  


Current Time: Wed Feb 19 10:02:05 GMT 2020

Powered by FUDForum. Page generated in 0.03142 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top