Skip to main content



      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 13:02 Go to next message
Eclipse UserFriend
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 04:26 Go to previous messageGo to next message
Eclipse UserFriend
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,

[Updated on: Thu, 14 November 2019 04:30] by Moderator

Re: Get selected item value in capella diagram [message #1817029 is a reply to message #1817025] Thu, 14 November 2019 04:51 Go to previous message
Eclipse UserFriend
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 04:59] by 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 Jul 02 06:55:42 EDT 2025

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

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

Back to the top