Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Eclipse Luna Problem with @Inject(Eclipse Luna Problem with @Inject)
Eclipse Luna Problem with @Inject [message #1472084] Thu, 13 November 2014 15:35 Go to next message
ludovic drouineau is currently offline ludovic drouineauFriend
Messages: 4
Registered: November 2014
Junior Member
Hello
I have created a new Eclipse 4 Application Project in Luna with a SamplePart:
The SamplePart has a samplePartActivated method with annotation Inject

@Inject
private void samplePartActivated(
@UIEventTopic(UIEvents.UILifeCycle.ACTIVATE) MPart activePart) {
if (activePart != null) {
System.out.println("Activation !!!!");
}
}

With Luna I have this exception:
org.eclipse.e4.core.di.InjectionException: Unable to process "SamplePart#samplePartActivated()": no actual value was found for the argument "MPart[@org.eclipse.e4.ui.di.UIEventTopic(value=org/eclipse/e4/ui/LifeCycle/activate)]".

The same code was working on juno.

Can anyone please help me?
Re: Eclipse Luna Problem with @Inject [message #1472205 is a reply to message #1472084] Thu, 13 November 2014 17:43 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

You need to:
a) use @Optional on the methpd or
b) use @Optional on the parameter

Tom

On 13.11.14 17:03, ludovic drouineau wrote:
> Hello
> I have created a new Eclipse 4 Application Project in Luna with a
> SamplePart:
> The SamplePart has a samplePartActivated method with annotation Inject
>
> @Inject
> private void samplePartActivated(
> @UIEventTopic(UIEvents.UILifeCycle.ACTIVATE) MPart
> activePart) {
> if (activePart != null) {
> System.out.println("Activation !!!!");
> }
> }
>
> With Luna I have this exception:
> org.eclipse.e4.core.di.InjectionException: Unable to process
> "SamplePart#samplePartActivated()": no actual value was found for the
> argument
> "MPart[@org.eclipse.e4.ui.di.UIEventTopic(value=org/eclipse/e4/ui/LifeCycle/activate)]".
>
>
> The same code was working on juno.
>
> Can anyone please help me?
Re: Eclipse Luna Problem with @Inject [message #1472944 is a reply to message #1472205] Fri, 14 November 2014 08:00 Go to previous messageGo to next message
ludovic drouineau is currently offline ludovic drouineauFriend
Messages: 4
Registered: November 2014
Junior Member
Hi
I've done this and I don't have the exception but the parameter is always null:

@Inject
@Optional
private void samplePartActivated(
@UIEventTopic
(UIEvents.UILifeCycle.ACTIVATE) MPart activePart) {
if (activePart != null) {
System.out.println("Activation!");
}
else System.out.println("activePart is null!");
}

(In Juno, parameter was not null)

Ludo
Re: Eclipse Luna Problem with @Inject [message #1477971 is a reply to message #1472944] Tue, 18 November 2014 09:07 Go to previous messageGo to next message
ludovic drouineau is currently offline ludovic drouineauFriend
Messages: 4
Registered: November 2014
Junior Member
Hi,
Should I avoid using
@UIEventTopic
(UIEvents.UILifeCycle.ACTIVATE) MPart activePart ?
Re: Eclipse Luna Problem with @Inject [message #1478096 is a reply to message #1477971] Tue, 18 November 2014 11:32 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Not 100% sure, but should the parameter type be org.osgi.service.event.Event instead of MPart when listening to the event.

I guess what you want to do is

@Inject
@Optional
public void receiveActivePart(@Named(IServiceConstants.ACTIVE_PART) MPart activePart) {
  if (activePart != null) {
  System.out.println("Active part changed "
    + activePart.getLabel());
  }
}


As explained here: http://www.vogella.com/tutorials/EclipseRCP/article.html#dependencyinjection_activeconstants
Re: Eclipse Luna Problem with @Inject [message #1478184 is a reply to message #1478096] Tue, 18 November 2014 13:08 Go to previous message
ludovic drouineau is currently offline ludovic drouineauFriend
Messages: 4
Registered: November 2014
Junior Member
Perfect! It works.
Thanks
Previous Topic:EMenuService - get UI representation of menu
Next Topic:Luna 4.4 unable to connect to marketplace behind firewall
Goto Forum:
  


Current Time: Fri Apr 19 09:37:17 GMT 2024

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

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

Back to the top