|
Re: Get selected item value in capella diagram [message #1817025 is a reply to message #1817009] |
Thu, 14 November 2019 09:26 |
|
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
[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 |
Emmanuel SEMO 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
|
|
|
Powered by
FUDForum. Page generated in 0.03281 seconds