Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » E4 DI: problem with reinjecting values from different contexts
E4 DI: problem with reinjecting values from different contexts [message #1712441] Sat, 24 October 2015 21:47 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hi

I use this class to test:
public class TestPojo {
	@Inject
	public void getText(@Optional @Named("LoggingMessage") String text ){
		System.out.println("PojoMessage: "+text);
	}
}


Now i create the E4 sample application with the Lifecycle class.

In the sample view, i have injected the IEclipseContext as "context" and I add a double click listener to the table:
		tableViewer.addDoubleClickListener( e -> {
			IStructuredSelection sel = (IStructuredSelection) e.getSelection();
			String firstElement = (String) sel.getFirstElement();
			IEclipseContext c = context;
			for( int i = 0; c != null; c = c.getParent(), i++ ){
				System.out.printf("set ctx: %d %s\n", i, c);
				context.set("LoggingMessage", firstElement);
			}
		});


Now if i create a TestPojo with from within the sample view with its context:
pojo = ContextInjectionFactory.make( TestPojo.class, context );


I get the output each time I double click onto table items.

Now the problem, if i create the TestPojo in the E4LifeCycle#postContextCreate(IEclipseContext workbenchContext) with that workbenchContext, it only get injected once with null, not later with the text.

I see this output:
set ctx: 0 PartImplContext
PartMessage: Sample item 2
set ctx: 1 PerspectiveImplContext
set ctx: 2 TrimmedWindowImplContext
set ctx: 3 WorkbenchContext
set ctx: 4 OSGi context for bundle: org.eclipse.e4.ui.workbench

After set ctx: 3 ... I would expect the output of PojoMessage...

Is my understanding wrong?

Frank


Re: E4 DI: problem with reinjecting values from different contexts [message #1712479 is a reply to message #1712441] Sun, 25 October 2015 19:40 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
You need to declare your context value "Logging" as modifyable to make the re-injection work. This can be done via the context.
Re: E4 DI: problem with reinjecting values from different contexts [message #1712482 is a reply to message #1712479] Sun, 25 October 2015 21:25 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Thanks for the answer. But for me it does not yet work.

I tried to call this:
workbenchContext.declareModifiable("LoggingMessage");

Still no update.
How come, it works for the PartImplContext without this.
Re: E4 DI: problem with reinjecting values from different contexts [message #1712502 is a reply to message #1712482] Mon, 26 October 2015 08:17 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
Have you tried to call context.modify() instead of context.set()?

IIRC there is only a listener registered that triggers re-injection in case of modifyable. Setting a value should only trigger your listener (which is your annotated method) once.
Re: E4 DI: problem with reinjecting values from different contexts [message #1712547 is a reply to message #1712502] Mon, 26 October 2015 10:46 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
The modify did it. Thanks!

I found this related article
http://tomsondev.bestsolution.at/2013/11/21/what-ieclipsecontextdeclaremodifiable-is-good-for/


Re: E4 DI: problem with reinjecting values from different contexts [message #1712549 is a reply to message #1712502] Mon, 26 October 2015 10:48 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
The modify works. Thanks!

i found this related article:
http://tomsondev.bestsolution.at/2013/11/21/what-ieclipsecontextdeclaremodifiable-is-good-for/
Re: E4 DI: problem with reinjecting values from different contexts [message #1712550 is a reply to message #1712502] Mon, 26 October 2015 10:49 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
The modify works. Thanks!

i found this related article:
http://tomsondev.bestsolution.at/2013/11/21/what-ieclipsecontextdeclaremodifiable-is-good-for/
Re: E4 DI: problem with reinjecting values from different contexts [message #1712561 is a reply to message #1712502] Mon, 26 October 2015 12:38 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
On 26.10.15 01:17, Dirk Fauth wrote:
> Have you tried to call context.modify() instead of context.set()?
>
> IIRC there is only a listener registered that triggers re-injection in
> case of modifyable. Setting a value should only trigger your listener
> (which is your annotated method) once.

No this is not right.

Tom
Re: E4 DI: problem with reinjecting values from different contexts [message #1712562 is a reply to message #1712502] Mon, 26 October 2015 12:43 Go to previous messageGo to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 17
Registered: December 2012
Junior Member
The modify works. Thanks!

i found this relevant article:
http://tomsondev.bestsolution.at/2013/11/21/what-ieclipsecontextdeclaremodifiable-is-good-for/

Re: E4 DI: problem with reinjecting values from different contexts [message #1712615 is a reply to message #1712562] Mon, 26 October 2015 18:48 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2902
Registered: July 2012
Senior Member
@Tom

Thanks for the correction. I read the linked post and hope to have understood everything now correctly.
Previous Topic:Can we run SWTBot Test with Eclipse Luna having compatibility with eclipse 3.x code
Next Topic:Cannot Access Plugins in Eclipse 4.3.2
Goto Forum:
  


Current Time: Tue Apr 16 13:45:51 GMT 2024

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

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

Back to the top