We have a requirement to select model element from external Windows application.
So, here is the scenario:
We have an external Windows application where I can import/capture model elements from Capella
Now, when I double click on that model element in my application, it should select the same model element inside Capella Project Explorer tree view
We have written a Capella plugin which:
Starts socket server when it is loaded
Listens request from our external Windows application. This is where we want to send element select request from our application.
It would be good to select the element using either its ID or some kind of URI.
Could you please help with this?
I am trying below code:
EObject elementToSelect = null;
public IWorkbenchPart getActivePart() {
final IWorkbench workbench = PlatformUI.getWorkbench();
final IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
if (activeWindow != null) {
final IWorkbenchPage activePage = activeWindow.getActivePage();
if (activePage != null) {
return activePage.getActivePart();
}
}
return null;
}
IWorkbenchPart activePart = getActivePart();
if (activePart != null && activePart instanceof IPackagesViewPart) {
((IPackagesViewPart) activePart).selectAndReveal(elementToSelect);
}
What I am missing here is elementToSelect .
As a input, I have only string ID of an element like in the form: “61c2baab-5479-440b-9e3b-887ab22bddf9” [as mentioned in .capella file]
From this, I need to form elementToSelect so that it can be revealed in the tree [along with tree expansion]
Could you please help me to get elementToSelect of type EObject from mere ID of an element? Is it even possible?
If not possible, is there any other way I can use to get this EObject?
may be this can help you a little bit:
In Sirius / aql interpreter you can get the element corresponding to an ID by
aql:self.eAllContents()->select(elt | elt.id = ‘61c2baab-5479-440b-9e3b-887ab22bddf9’)
With this you can find e.g. a function etc. in your architecture.
With your example code new ResourceImpl()… you are essentially loading the whole model again, and the EObject you get out of it isn’t shown in the explorer, which is why nothing is selected… You must search the already loaded objects instead of not loading it again.
What you can do instead woudl be along:
for each session in SessionManager.INSTANCE.getAllSessions()
for each resource in session.getTransactionalEditingDomain().getResourceSet()
if that resource.uri is a .capella/.melodymodeller file (check URI)
search that resource for element with id
and select