Selection of an element from an external application

Hello,

We have a requirement to select model element from external Windows application.
So, here is the scenario:

  1. We have an external Windows application where I can import/capture model elements from Capella
  2. 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:

  1. Starts socket server when it is loaded
  2. 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?

Thank you in advance for your feedback.

1 Like

Hi,

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.

greetings

Hello,

I am able to convert ID into EObject with XMLResourceImpl

Here is the code:

            		EObject elementToSelect = null;	            		
            		ResourceSet rs = new ResourceSetImpl();
            		XMLResourceImpl resource = (XMLResourceImpl) rs.getResource(URI.createFileURI(projectPathFull), true);         	            		
            		Map<EObject,String> eObjectToIDMap = resource.getEObjectToIDMap();
            		
            		for (Map.Entry<EObject, String> entry : eObjectToIDMap.entrySet()) {
            		    if (entry.getValue().equals("47008f89-080b-41b5-9459-26f86ebc2243")) {
            		    	elementToSelect = entry.getKey();
            		    	break;
            		    }
            		}

But I am not able select that element node inside Project Explorer with below code:

            		IViewPart view = activePage.showView("org.eclipse.ui.navigator.ProjectExplorer", null, IWorkbenchPage.VIEW_ACTIVATE);;
            		view.getSite().getSelectionProvider().setSelection( new StructuredSelection( elementToSelect ) );

OR

            		IWorkbenchPart activePart = getActivePart();
            		if (activePart != null && activePart instanceof CapellaCommonNavigator) {
            		         ((CapellaCommonNavigator) activePart).selectReveal(new StructuredSelection(elementToSelect));
            		 } 

Could you please tell me what I am missing here?

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

2 Likes

Thank you very much @FDorner.
Now, It is working like a charm :slightly_smiling_face:

1 Like
Copyright © Eclipse Capella, the Eclipse Capella logo, Eclipse and the Eclipse logo are Trademarks of The Eclipse Foundation.