Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » change Context for @Inject
change Context for @Inject [message #1691030] Wed, 01 April 2015 16:43 Go to next message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Hi all,
in my LifecycleManager I've created a new IPreferenceStore object. This
I've put into current context:

context.set(IPreferenceStore.class, defaultValuesNode);

(context was previously injected into LifecycleManager with @Inject
private IEclipseContext context;).

Now if I inject the IPreferenceStore in a MPart:

@Inject
@Preference(value="/instance/com.acme.work")
private IPreferenceStore preferences;

the preferences field is null (even if I omit the value attribute). On
the other hand, if I call

EclipseContextFactory.getServiceContext(Activator.getContext()).get(IPreferenceStore.class);

all preferences are available, which means that I've chosen the wrong
context (Activator delivers the bundle context for "com.acme.work"). But
how can I say which context for injection is to use?

TIA,
Ralf.
Re: change Context for @Inject [message #1691046 is a reply to message #1691030] Wed, 01 April 2015 19:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
What gave you the impression that we are querying the IPreferenceStore
when you use @Preference?

Your code will query
IPreferenceService.getString("your.bundle.id","/instance/com.acme.work",null)!

If you want to replace preferences storeage you need to replace the
IPreferencesService at the OSGi-Level.

Tom

On 01.04.15 18:43, Ralf Heydenreich wrote:
> Hi all,
> in my LifecycleManager I've created a new IPreferenceStore object. This
> I've put into current context:
>
> context.set(IPreferenceStore.class, defaultValuesNode);
>
> (context was previously injected into LifecycleManager with @Inject
> private IEclipseContext context;).
>
> Now if I inject the IPreferenceStore in a MPart:
>
> @Inject
> @Preference(value="/instance/com.acme.work")
> private IPreferenceStore preferences;
>
> the preferences field is null (even if I omit the value attribute). On
> the other hand, if I call
>
> EclipseContextFactory.getServiceContext(Activator.getContext()).get(IPreferenceStore.class);
>
> all preferences are available, which means that I've chosen the wrong
> context (Activator delivers the bundle context for "com.acme.work"). But
> how can I say which context for injection is to use?
>
> TIA,
> Ralf.
>
Re: change Context for @Inject [message #1691059 is a reply to message #1691046] Wed, 01 April 2015 23:55 Go to previous message
Ralf Heydenreich is currently offline Ralf HeydenreichFriend
Messages: 235
Registered: July 2009
Senior Member
Am 01.04.2015 um 21:53 schrieb Tom Schindl:
> What gave you the impression that we are querying the IPreferenceStore
> when you use @Preference?
>
> Your code will query
> IPreferenceService.getString("your.bundle.id","/instance/com.acme.work",null)!
>
> If you want to replace preferences storeage you need to replace the
> IPreferencesService at the OSGi-Level.
>
> Tom
>


Ok, I forget to mention that I've used the
com.opcoach.e4.preferences.ScopedPreferenceStore from
https://github.com/opcoach/e4Preferences.
Previous Topic:Eclipse Event System
Next Topic:Usage EMF models in E4 RCP
Goto Forum:
  


Current Time: Fri Apr 19 04:34:28 GMT 2024

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

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

Back to the top