How to access the model explorer programmatically in eclipse?

217 Views Asked by At

How can I access the elements of the Sirius Model Explorer in Eclipse? Actually, I have a NatTable in another view and this NatTable has objects of the model in its cells. What I want to achieve is whenever I click on the cell of the nattable I can get the object associated to it. But how to pass it to the model explorer so the selection in NatTable gets synched with NatTable? What I have in mind is get the selected object from NatTable and programmatically parse it to the model explorer. Is it possible?

There is something here for Package Explorer but how to make it work for model explorer?

Code Sample:

final IWorkbenchPart activePart = getActivePart();
if (activePart != null && activePart instanceof IPackagesViewPart) {
    ((IPackagesViewPart) activePart).selectAndReveal(newElement);
}

Supporting Code:

private 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;
}
1

There are 1 best solutions below

4
On

Probably the Sirius Model Explorer is hooked to the Eclipse Selection Service (see https://www.eclipse.org/articles/Article-WorkbenchSelections/article.html) - in which case you simply need for your NatTable view to be some sort of ISelectionProvider.