Skip to main content



      Home
Home » Eclipse Projects » Eclipse 4 » Opening new Part - getting current EPartService from static method
Opening new Part - getting current EPartService from static method [message #1797696] Mon, 05 November 2018 06:28 Go to next message
Eclipse UserFriend
I decided to rewrite my app to pure e4 from 3.x where I had static RCPHelper with method:

public static ViewPart openNew(String pViewId, String pNewId)
{
		try {
			return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().showView(pViewId, pViewId+pNewId, org.eclipse.ui.IWorkbenchPage.VIEW_ACTIVATE);
		} catch (PartInitException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
}


I tried with static BundleContext but EPartService is always NULL:
EPartService lService = (EPartService)Activator.context.getServiceReference(EPartService.class);
		MPart lPart = lService.showPart(pViewId, PartState.ACTIVATE);


Is it possible to implement something like that in e4 that would return MPart?
Re: Opening new Part - getting current EPartService from static method [message #1797707 is a reply to message #1797696] Mon, 05 November 2018 08:39 Go to previous messageGo to next message
Eclipse UserFriend
The Part Service is a window-level E4 service, not an OSGi service. E4 Services are scoped or bound tied to different points in the windowing hierarchy. The E4 services are resolved using an Eclipse Context, and the root context actually does do OSGi Service lookups too.

So you need to find your current window and do something like:
Window window = ...;
if(window.getContext() == null) {
   // if window has not been realized
}
EPartService partService = window.getContext().get(EPartService.class);
Re: Opening new Part - getting current EPartService from static method [message #1797871 is a reply to message #1797707] Wed, 07 November 2018 12:08 Go to previous messageGo to next message
Eclipse UserFriend
I have only one window, tried with something like this:
MApplication lApplication = E4Workbench.getServiceContext().get(MApplication.class);
MTrimmedWindow lWindow = (MTrimmedWindow) lApplication.getChildren().get(0);
if(lWindow.getContext() == null)
        System.err.println("NULL");


without success as getContext() returns always NULL

[Updated on: Wed, 07 November 2018 12:35] by Moderator

Re: Opening new Part - getting current EPartService from static method [message #1797872 is a reply to message #1797871] Wed, 07 November 2018 13:44 Go to previous message
Eclipse UserFriend
That usually means the window hasn't actually been rendered yet (isn't visible).
Previous Topic:Unable to launch RCP with @nodefault after upgrading to neon
Next Topic:Proejct files compatibility with previous versions?
Goto Forum:
  


Current Time: Sun Jul 20 20:22:39 EDT 2025

Powered by FUDForum. Page generated in 0.06208 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top