Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Problem with initialization of preferences
Problem with initialization of preferences [message #735789] Wed, 12 October 2011 17:32 Go to next message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
Hi,
I need to access preferences in my validator (language compliance
settings), and I have configured as described below.

The main problem is that an implementation of
IPreferenceStoreInitializer does not get a call to initialize until too
late.

How can I ensure that the preference store is initialized before trying
to access it?

This is how I do it now:

In the UI module, bind the preference helper (that answers things like
"what is the compliance level".

public void configureDefaultPreferences(Binder binder) {
binder.bind(IPreferenceStoreInitializer.class).annotatedWith(Names.named("PPPreferencesHelper"))
.to(PPPreferencesHelper.class);
}

In the UI module, I then do this:
public com.google.inject.Provider<IValidationAdvisor>
provideValidationAdvisor() {
return PreferenceBasedValidationAdvisorProvider.create();
}

Which in turn does:

@Inject
private PPPreferencesHelper preferences;
public static <T extends IValidationAdvisor>
PreferenceBasedValidationAdvisorProvider<T> create() {
return new PreferenceBasedValidationAdvisorProvider<T>();
}

@Override
public IValidationAdvisor get() {
return
ValidationAdvisor.create(preferences.getValidationComplianceLevel());
}

The ValidationAdvisor.create just looks at the enum returned by
getValidationComplianceLevel and returns a new instance of an
implementation of IValidationAdvisor.

By the time, the provider gets a call to get(), the PPPreferenceHelper
has not yet received a call to intialize.

In my standalone implementation, the compliance level is set via a
parameter to the module, but in the UI, I need the compliance level to
be set from preferences.

Regards
- henrik
Re: Problem with initialization of preferences [message #735815 is a reply to message #735789] Wed, 12 October 2011 19:26 Go to previous message
Henrik Lindberg is currently offline Henrik LindbergFriend
Messages: 2509
Registered: July 2009
Senior Member
I can answer this myself.

The JavaValidator seems to be bound eagerly by something that is
Singleton and thus, anything injected into the validator gets created at
this point.
It did not help to inject a provider and then get an instance from the
provider in the JavaValidator's constructor (for the same reason).

What worked was to get the instance at the next stage when the validator
is used.

- henrik

On 10/12/11 7:32 PM, Henrik Lindberg wrote:
> Hi,
> I need to access preferences in my validator (language compliance
> settings), and I have configured as described below.
>
> The main problem is that an implementation of
> IPreferenceStoreInitializer does not get a call to initialize until too
> late.
>
> How can I ensure that the preference store is initialized before trying
> to access it?
>
> This is how I do it now:
>
> In the UI module, bind the preference helper (that answers things like
> "what is the compliance level".
>
> public void configureDefaultPreferences(Binder binder) {
> binder.bind(IPreferenceStoreInitializer.class).annotatedWith(Names.named("PPPreferencesHelper"))
> .to(PPPreferencesHelper.class);
> }
>
> In the UI module, I then do this:
> public com.google.inject.Provider<IValidationAdvisor>
> provideValidationAdvisor() {
> return PreferenceBasedValidationAdvisorProvider.create();
> }
>
> Which in turn does:
>
> @Inject
> private PPPreferencesHelper preferences;
> public static <T extends IValidationAdvisor>
> PreferenceBasedValidationAdvisorProvider<T> create() {
> return new PreferenceBasedValidationAdvisorProvider<T>();
> }
>
> @Override
> public IValidationAdvisor get() {
> return
> ValidationAdvisor.create(preferences.getValidationComplianceLevel());
> }
>
> The ValidationAdvisor.create just looks at the enum returned by
> getValidationComplianceLevel and returns a new instance of an
> implementation of IValidationAdvisor.
>
> By the time, the provider gets a call to get(), the PPPreferenceHelper
> has not yet received a call to intialize.
>
> In my standalone implementation, the compliance level is set via a
> parameter to the module, but in the UI, I need the compliance level to
> be set from preferences.
>
> Regards
> - henrik
Previous Topic:Xtext 2: passing arguments to ANTLR
Next Topic:Implicit imports based on type
Goto Forum:
  


Current Time: Fri Apr 26 11:33:03 GMT 2024

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

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

Back to the top