Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Eclipse 4 RCP getting parts via EPartService
Eclipse 4 RCP getting parts via EPartService [message #989891] Sun, 09 December 2012 10:27 Go to next message
Eclipse UserFriend
Greetings,
I have another problem with my RCP Project. I am trying to hide/show some parts, and I tried to find those parts by calling EPartService.findPart("partID").

package fzi.activemq.rcp.launcher.Composites.lowerleft;

import javax.inject.Inject;

import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.workbench.UIEvents.Part;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;

import fzi.activemq.rcp.launcher.Composites.MainComposite;

public class SelectComposite2 extends Composite {

	@Inject private EPartService service;
	
	Button aMQButton;
	Button dBButton;
	
	public SelectComposite2(Composite parent, int style){
		super(parent, style);
				
		
		MPart part = service.findPart("fzi.activemq.rcp.launcher.part.2");
		part.setVisible(true);
...





When findPart gets called, I get this NullPointerException:


java.lang.NullPointerException
	at fzi.activemq.rcp.launcher.ui.parts.LowerLeft.configurationSelected(LowerLeft.java:40)
	at fzi.activemq.rcp.launcher.Composites.upperleft.SelectComposite$1.widgetSelected(SelectComposite.java:45)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1029)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:923)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:86)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.start(E4Application.java:150)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1438)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1414)


Would be great if u could help me out.
thx,
Daniel
Re: Eclipse 4 RCP getting parts via EPartService [message #989931 is a reply to message #989891] Mon, 10 December 2012 02:05 Go to previous messageGo to next message
Eclipse UserFriend
The problem is
@Inject private EPartService service;
is not injected .

Why..? Because you are creating object of your SelectComposite2 class so its your responsibility to inject all necessary injection to your class. Like following.
SelectComposite2 cim = new SelectComposite2();
ContextInjectionFactory.inject(cim,iEclipseContext);


Where iEclipseContext is IEclipseContext variable. IEclipseContext automatically inject when eclipse framework will create your object . Like in case of handler.
But if you are creating your object then its your responsibility to inject it.

[Updated on: Mon, 10 December 2012 02:06] by Moderator

Re: Eclipse 4 RCP getting parts via EPartService [message #990002 is a reply to message #989931] Mon, 10 December 2012 07:23 Go to previous messageGo to next message
Eclipse UserFriend
Thx for your reply. Is it possible to use injection similar in Listeners as in Handlers (it didnt work when I tried it but I wouldnt be that surprised if I messed that up..)?
Otherwise, how can i get my hands on an instance of IEclipseContext? Rly tried to figure that out myselve, but no matter how many sites I browse, it seems that this is only used with injection...

[Updated on: Mon, 10 December 2012 10:02] by Moderator

Re: Eclipse 4 RCP getting parts via EPartService [message #990374 is a reply to message #990002] Wed, 12 December 2012 03:35 Go to previous messageGo to next message
Eclipse UserFriend
No. In case of listeners you have to do it your self. take a look of following code . you can get your EPartService like following in your class.

Bundle bundle = FrameworkUtil.getBundle(EPartService.class);
BundleContext bundleContext = bundle.getBundleContext();
IEclipseContext eclipseCtx =
EclipseContextFactory.getServiceContext(bundleContext);
EPartService  partService  = (EPartService) eclipseCtx.get(EPartService.class.getName());

[Updated on: Wed, 12 December 2012 03:36] by Moderator

Re: Eclipse 4 RCP getting parts via EPartService [message #990437 is a reply to message #990374] Wed, 12 December 2012 08:55 Go to previous messageGo to next message
Eclipse UserFriend
Thank u so much, everything is working fine now!
Re: Eclipse 4 RCP getting parts via EPartService [message #990552 is a reply to message #990437] Thu, 13 December 2012 00:45 Go to previous messageGo to next message
Eclipse UserFriend
Your Welcome Smile
Re: Eclipse 4 RCP getting parts via EPartService [message #990955 is a reply to message #990552] Sat, 15 December 2012 06:39 Go to previous messageGo to next message
Eclipse UserFriend
Just to elaborate on Sumit's answer -- you need to obtain a context from somewhere. Sumit's code uses the top-level OSGi context, which works in this case as the EPartService is effectively a singleton registered as an OSGi service. But you'll find that this won't work for other services as they will be registered at other points in the context tree. Generally you should do lookups from the closest context that you can find, and many of the UI classes carry a context (see the subclasses of MContext). In Eclipse 3.x compat layer, you can obtain the IEC for a part using:

getSite().getService(IEclipseContext.class);


Brian.
Re: Eclipse 4 RCP getting parts via EPartService [message #991020 is a reply to message #989891] Mon, 17 December 2012 00:17 Go to previous message
Eclipse UserFriend
Thanks Brian to make it more clear.
Previous Topic:Disable text search
Next Topic:Error launching Eclipse Application from Vogella Tutorial
Goto Forum:
  


Current Time: Sat Jul 05 10:06:53 EDT 2025

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

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

Back to the top