Monday, September 15, 2014

How to get Eclipse EModelService from workbench ?


WorkbenchWindow activeWorkbenchWindow = (WorkbenchWindow) PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (activeWorkbenchWindow != null) {
MWindow window = activeWorkbenchWindow.getModel();
if (window != null) {
EModelService modelService = window.getContext().get(EModelService.class);

//your calls
}
}

2 comments:

  1. Just learned that there is an easier way:

    IEclipseContext context = (IEclipseContext) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(IEclipseContext.class);

    ReplyDelete
  2. (an then EModelService modelService = context.get(EModelService.class);)

    ReplyDelete