Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 11:28 Go to next message
Bartosz Szczypien is currently offline Bartosz SzczypienFriend
Messages: 11
Registered: January 2017
Junior Member
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 13:39 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 865
Registered: January 2012
Senior Member

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);


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Opening new Part - getting current EPartService from static method [message #1797871 is a reply to message #1797707] Wed, 07 November 2018 17:08 Go to previous messageGo to next message
Bartosz Szczypien is currently offline Bartosz SzczypienFriend
Messages: 11
Registered: January 2017
Junior Member
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 17:35]

Report message to a moderator

Re: Opening new Part - getting current EPartService from static method [message #1797872 is a reply to message #1797871] Wed, 07 November 2018 18:44 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 865
Registered: January 2012
Senior Member

That usually means the window hasn't actually been rendered yet (isn't visible).

Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Unable to launch RCP with @nodefault after upgrading to neon
Next Topic:Proejct files compatibility with previous versions?
Goto Forum:
  


Current Time: Sat Dec 14 15:17:01 GMT 2019

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

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

Back to the top