Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » LifeCycle and EPartService Injection Problem
LifeCycle and EPartService Injection Problem [message #1185799] Thu, 14 November 2013 09:17 Go to next message
Johannes Spreemann is currently offline Johannes SpreemannFriend
Messages: 19
Registered: August 2013
Location: Germany/Netherlands
Junior Member
Good morning, good day or good night,

I have a small problem with the activation of a part. My part is in a tab in the background. It is necessary to create the part before its first activation. I tried to instantiate it manually within my LifeCycleManager, but the EPartService isn't injected at all. Not in the postContextCreate (The method is not called when the EPartService is added as a parameter) or as a "global" injection (InjectionException).

Case #1:
@PostContextCreate
void postContextCreate(final IEventBroker eventBroker, final EPartService partService) {

		eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE,
				new EventHandler() {
					@Override
					public void handleEvent(Event event) {
						partService.showPart(
								"myapp.part.statistics",
								PartState.CREATE);

						eventBroker.unsubscribe(this);
					}
				});

	}

Case #2:

@Inject
EPartService partService; // InjectionException

void postContextCreate(final IEventBroker eventBroker) {
...
partService.showPart(...);
...}


Any ideas why the injection doesn't work?



Re: LifeCycle and EPartService Injection Problem [message #1185813 is a reply to message #1185799] Thu, 14 November 2013 09:30 Go to previous messageGo to next message
Eclipse UserFriend
It's probably in the window context and the default injection is looking for it in the app context. I'd put an addon which on it's post construct has the MApplication injected, grabs its first MWindow and does MWindow#getContext()#get(EPartService.class) and then does the stuff you want it to.
Re: LifeCycle and EPartService Injection Problem [message #1185824 is a reply to message #1185813] Thu, 14 November 2013 09:39 Go to previous messageGo to next message
Johannes Spreemann is currently offline Johannes SpreemannFriend
Messages: 19
Registered: August 2013
Location: Germany/Netherlands
Junior Member
Thank you very much. Your idea works!

I Injected the IEclipseContext in the postContextCreate and retrieved the EPartService from the context.
Re: LifeCycle and EPartService Injection Problem [message #1386554 is a reply to message #1185824] Wed, 18 June 2014 09:01 Go to previous messageGo to next message
Luis Fernando Robledano-Esteban is currently offline Luis Fernando Robledano-EstebanFriend
Messages: 32
Registered: February 2013
Member
Hi guys, I´m actually having the same problem but even worst:
Still partservice is null after getting it from the context.
@PostContextCreate
void postContextCreate( EPartService epartservice, IEclipseContext ieclipsecontext ) {
if( epartservice ==null ){ // it is in fact alwasy null so it is confirmed what Johannes said
  epartservice = ieclipsecontext.get(EPartService.class);
 // OR SAME Result with: epartservice = (EPartService) ieclipsecontext.get(EPartService.class.getName());
}
// epartservice is still null

Any help here please?



ArkosX
Re: LifeCycle and EPartService Injection Problem [message #1386565 is a reply to message #1386554] Wed, 18 June 2014 09:25 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
There can never by a part service at this point! The EPartService is
only available when the workbench is fully initialized.

Tom

On 18.06.14 11:01, Luis Fernando Robledano-Esteban wrote:
> Hi guys, I´m actually having the same problem but even worst:
> Still partservice is null after getting it from the context.
>
> @PostContextCreate
> void postContextCreate( EPartService epartservice, IEclipseContext
> ieclipsecontext ) {
> if( epartservice ==null ){ // it is in fact alwasy null so it is
> confirmed what Johannes said
> epartservice = ieclipsecontext.get(EPartService.class);
> // OR SAME Result with: epartservice = (EPartService)
> ieclipsecontext.get(EPartService.class.getName());
> }
> // epartservice is still null
>
> Any help here please?
>
>
Re: LifeCycle and EPartService Injection Problem [message #1386618 is a reply to message #1386565] Wed, 18 June 2014 17:52 Go to previous message
Luis Fernando Robledano-Esteban is currently offline Luis Fernando Robledano-EstebanFriend
Messages: 32
Registered: February 2013
Member
Hi Thomas, thanks for the answer.

Well, I actually have the problem in other classes as well (those which are not parts). I just checked in the LyfeCycle manager class because was easier to test.
In the previous comments it was not said that it cannot be done
Johannes Spreemann wrote on Thu, 14 November 2013 10:39
Thank you very much. Your idea works!
I Injected the IEclipseContext in the postContextCreate and retrieved the EPartService from the context.

Besides, @PostContextCreate, doesnt it mean that everything is created already?

The curious thing is that it was working few days ago.

It seems it is randomly when is not a Part class (which are referred in the e4xmi file andtherefore I guess Eclipse Workbench knows of).

Therefore let me rephrase the question: How can I get a Part from a class which is not a Part it self?

This doesn't work:

class A{
@Inject EPartService _partservice;

  void method(){
    ...
    MPart mpart = _epartservice.findPart("aa.bb.cc.mypart");
    _epartservice.showPart(mpart, PartState.ACTIVATE); // _epartservice is null
    ...

  }//- method
}//- class A


Thanks again


ArkosX
Previous Topic:Using EMenuService between Kepler and Luna
Next Topic:Eclipse 4 RCP applications - Creating a Feature Product including all of its plugin dependencies
Goto Forum:
  


Current Time: Fri Apr 19 01:26:04 GMT 2024

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

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

Back to the top