Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » [E4] Preference annotation and the e4 dependency injection architecture
[E4] Preference annotation and the e4 dependency injection architecture [message #577173] Tue, 08 June 2010 07:55 Go to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

I have two very different questions :

1- despite several attempts, I didn't succeed in making the @Preference annotation work and I can't find a complete example to understand how to use it, and the wiki is not helping (http://wiki.eclipse.org/E4/EAS/Preferences). I know how you are supposed to use it thanks to this example : http://tomsondev.bestsolution.at/2010/05/17/a-week-at-e4-sha re-me-please/

But I didn't succeed in storing a value in the preference store and then getting it back thanks to the annotation even if I'm convinced that it's very easy and I'm just missing something. So do you have a simple example for storing a data in the preference store and then getting it back with @Preference ?


2- I have a question on the behavior of your dependency injection architecture. I have created a class, representing a view, similar to this :

public class Test {
@Inject
public Test(Composite parent) { /* do nothing */ }

@Inject
public void doSomething(@Optional @Named("selection") IFile file) { /* do nothing */}
}

When my class is loaded both the constructor and the method are called due to the @Inject annotation. Latter while using my application if I select an IFile my "doSomething" method is called, it works as expected.

So I was wondering, how the dependency injection system knows that it has to call my method.

I know that, for the event system, the event broker is using the event admin system from Equinox, and I know thanks to the" OSGI and Equinox" book (page 257) that OSGI register the listener of an event in its service registry, thanks to this message ( http://www.eclipse.org/forums/index.php?t=msg&th=167787& amp;start=0&) I know that it can happen only with the @Inject annotation on the method that need to be called.

So my theory is that when my object is created, the dependency injection engine sees the @Inject annotation and "tells" OSGI to register my method as "a service that need to be called when the selection changes". And when the selection changes, the platform tells OSGI "if you have a service that need to be called, do it". Am I right ? Is that the same for @Execute or @CanExecute ? If not, how does the dependency injection engine know how to call my method ?

--
Stephane Begaudeau @ Obeo
Re: [E4] Preference annotation and the e4 dependency injection architecture [message #577227 is a reply to message #577173] Tue, 08 June 2010 11:04 Go to previous message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 08.06.10 09:55, schrieb Stephane Begaudeau:
> I have two very different questions :
>
> 1- despite several attempts, I didn't succeed in making the @Preference
> annotation work and I can't find a complete example to understand how to
> use it, and the wiki is not helping
> (http://wiki.eclipse.org/E4/EAS/Preferences). I know how you are
> supposed to use it thanks to this example :
> http://tomsondev.bestsolution.at/2010/05/17/a-week-at-e4-sha re-me-please/
>

If it is not working as advertised this is a bug and needs to be fixed.
I'll try to add it to one of my demos to see whether it works or not.

> But I didn't succeed in storing a value in the preference store and then
> getting it back thanks to the annotation even if I'm convinced that it's
> very easy and I'm just missing something. So do you have a simple
> example for storing a data in the preference store and then getting it
> back with @Preference ?
>
>
> 2- I have a question on the behavior of your dependency injection
> architecture. I have created a class, representing a view, similar to
> this :
>
> public class Test {
> @Inject
> public Test(Composite parent) { /* do nothing */ }
>
> @Inject
> public void doSomething(@Optional @Named("selection") IFile file) { /*
> do nothing */}
> }
>
> When my class is loaded both the constructor and the method are called
> due to the @Inject annotation. Latter while using my application if I
> select an IFile my "doSomething" method is called, it works as expected.
> So I was wondering, how the dependency injection system knows that it
> has to call my method.
>
> I know that, for the event system, the event broker is using the event
> admin system from Equinox, and I know thanks to the" OSGI and Equinox"
> book (page 257) that OSGI register the listener of an event in its
> service registry, thanks to this message
> ( http://www.eclipse.org/forums/index.php?t=msg&th=167787& amp;start=0&) I
> know that it can happen only with the @Inject annotation on the method
> that need to be called.
>
> So my theory is that when my object is created, the dependency injection
> engine sees the @Inject annotation and "tells" OSGI to register my
> method as "a service that need to be called when the selection changes".
> And when the selection changes, the platform tells OSGI "if you have a
> service that need to be called, do it". Am I right ? Is that the same
> for @Execute or @CanExecute ? If not, how does the dependency injection
> engine know how to call my method ?
>

No the DI-Container remembers in a locale context (IEclipseContext) -
you can compare it to a Hierarchical-HashMap - which values it has
injected into your instance and whenever this value changes it reinjects
the value.

@Execute and @CanExecute are a bit different because that's not really
injection what's happening there.

The command-framework does something similar. When the instance is
created it looks for @CanExecute and calls it with parameters in the
context and remember which values it used because they could lead to an
activation state change - now whenever one of the keys (the fully
qualified classname, the value in @Named()) changes it recalls this method.

The execute-method is only triggered by the Command-Framework wants to
execute the command and then determines the values that need to be
passed in.

Tom
Previous Topic:Dynamic Part
Next Topic:CSS styling with e4
Goto Forum:
  


Current Time: Tue Apr 23 09:33:02 GMT 2024

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

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

Back to the top