Rohit
1
Hello,
I need to retrieve the name of the selected element
I have a below code, Please help me to find out it is urgent
ISelection currentSelection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
if (currentSelection != null && !currentSelection.isEmpty() && currentSelection instanceof StructuredSelection) {
StructuredSelection s = (StructuredSelection) currentSelection;
EObject element = (EObject) s.getFirstElement();
}
better late than never
You can do
if (element instanceof AbstractNamedElement) {
return ((AbstractNamedElement)element.getName())
}
or
EObjectLabelProviderHelper.getText(element)
You need to add dependencies to capella metamodel / basic helpers as described in this tutorial to have access to such api.
See Create-Addons#how-to-create-an-basic-addon-adding-a-menu
Rohit
3
Hello,
Thanks for your answer.
I find the name by using:
element.eGet(element.eClass().getEStructuralFeature(“name”)).toString();
but your answer is more correct, My approach is to complex.
Rohit
4
Hello,
If the selected element is a type of **System User Requirement **
how to know that and how to retrieve the Requirement Id of that element
please find attached image for reference.
Thanks and Regards,
Rohit