Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Preference Values(Retrieving default values from Preference store upon plugin startup)
Preference Values [message #500117] Wed, 25 November 2009 03:50 Go to next message
No real name is currently offline No real nameFriend
Messages: 2
Registered: November 2009
Junior Member
I have a plugin with its own preferences page implemented.

I need to get some default values (example: 30) from the preference page upon starting the plugin however the value read in is 0. The correct value (30) can only be read in after the user 'visits' the preference page.

Is there any way for me the retrieve the defaults upon startup & without requiring the user to visit preference page.

Thank you.
Re: Preference Values [message #500150 is a reply to message #500117] Wed, 25 November 2009 08:33 Go to previous messageGo to next message
Michael Golovanov is currently offline Michael GolovanovFriend
Messages: 37
Registered: October 2009
Member
Do you use PreferenceIinitializer for setup default preference values?
Re: Preference Values [message #500178 is a reply to message #500150] Wed, 25 November 2009 09:32 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 2
Registered: November 2009
Junior Member
Thanks for replying.

Yes I did. It seems like the default values will only be initialized after the user 'visited' the preference page. I can read in the default values only after I visit the preference page.

Thanks again.
Re: Preference Values [message #500416 is a reply to message #500178] Thu, 26 November 2009 02:32 Go to previous messageGo to next message
J. Michael Dean, M.D. is currently offline J. Michael Dean, M.D.Friend
Messages: 218
Registered: July 2009
Senior Member
Have you set this up properly in the manifest? On the extensions tab, you
should have a preferencePages extension, and a preferences extension. On
the latter, you should be pointing at the initializer. This should set the
default values without the user going anywhere.


On 11/25/09 2:32 AM, in article heitin$9q0$1@build.eclipse.org,
"reality_11@hotmail.com" <reality_11@hotmail.com> wrote:

> Thanks for replying.
>
> Yes I did. It seems like the default values will only be initialized after the
> user 'visited' the preference page. I can read in the default values only
> after I visit the preference page.
>
> Thanks again.
Re: Preference Values [message #500470 is a reply to message #500117] Thu, 26 November 2009 09:53 Go to previous messageGo to next message
Michael Golovanov is currently offline Michael GolovanovFriend
Messages: 37
Registered: October 2009
Member
Ok, lets see troubles check list

1. Check prefs initialization extension point exists in plugin.xml

<extension
         point="org.eclipse.core.runtime.preferences">

  <initializer
       class="xxx. ProfilesPreferenceInitializer">
  </initializer>
</extension>


2. Check class xxx. ProfilesPreferenceInitializer

public class ProfilesPreferenceInitializer extends AbstractPreferenceInitializer {

	public ProfilesPreferenceInitializer() {
		super();
	}

	@Override
	public void initializeDefaultPreferences() {
		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
		store.setDefault(<pref mnemonic name>, <default pref value>);
	}

}


3. Check bundle Activator in bundle MANIFEST.MF present and "Activate this plugin when one of its classes loaded" is checked.

4. Check Activator class declaration
public class Activator extends AbstractUIPlugin


5. Check read default pref value code

Activator activator = Activator.getDefault();
String value = activator.getPreferenceStore().getString(<pref mnemonic name>);


If this does not help can you send me your code?
Re: Preference Values [message #661566 is a reply to message #500117] Fri, 25 March 2011 11:45 Go to previous messageGo to next message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
It seems like I have the exact same problem. I made my way through the checklist above and everything seems to be fine according to it.
But initializeDefaultPreferences() is only called when the PreferencePage is being opened. (checked by setting a breakpoint)

Is initializeDefaultPreferences() being called at this moment only and not while the plugin loads, by design? (it's not the constructor, so that would make sense for my limited knowledge) If so, how can I evaluate a value stored in the preferences store during loading of the plugin? (and execute some code accordingly)

[Updated on: Fri, 25 March 2011 11:46]

Report message to a moderator

Re: Preference Values [message #661838 is a reply to message #661566] Mon, 28 March 2011 08:01 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 25.03.2011 12:45, Martin wrote:
> It seems like I have the exact same problem. I made my way through
> the checklist above and everything seems to be fine according to it.
> But initializeDefaultPreferences() is only called when the
> PreferencePage is being opened. (checked by setting a breakpoint)
>
> Is initializeDefaultPreferences() being called at this moment only and
> not while the plugin loads, by design? (it's not the constructor, so
> that would make sense for my limited knowledge) If so, how can I
> evaluate a value stored in the preferences store during loading of the
> plugin?
The method should be called as soon as some code accesses the store of
your bundle (and not when it's loaded). If that's not the case then
please file a bug against Equinox Compendium.

Dani
Re: Preference Values [message #661865 is a reply to message #661838] Mon, 28 March 2011 10:52 Go to previous messageGo to next message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
Dani Megert wrote on Mon, 28 March 2011 10:01

The method should be called as soon as some code accesses the store of
your bundle (and not when it's loaded). If that's not the case then
please file a bug against Equinox Compendium.


Hm, maybe I'm trying to perform my stuff at the wrong place then. I just changed that and tried to get the PreferenceStore via
IPreferenceStore store = getPreferenceStore();
in the Activator() of the Plugin. But this now gives me a NullPointerException. Is it inappropriate to do this in the Activator (if so, where should it be done to perform something on loading of the plugin which uses the PreferenceStore?) or does the PreferenceStore need to be accessed in another way than mentioned above when doing it in the Activator?
kind regards

Martin
Re: Preference Values [message #661883 is a reply to message #661865] Mon, 28 March 2011 12:04 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 28.03.2011 12:52, Martin wrote:
> Dani Megert wrote on Mon, 28 March 2011 10:01
>> The method should be called as soon as some code accesses the store
>> of your bundle (and not when it's loaded). If that's not the case
>> then please file a bug against Equinox Compendium.
>
>
> Hm, maybe I'm trying to perform my stuff at the wrong place then. I
> just changed that and tried to get the PreferenceStore via
> IPreferenceStore store = getPreferenceStore();
> in the Activator() of the Plugin. But this now gives me a
> NullPointerException.
I don't see how getPreferenceStore() would cause an NPE.

Dani
> Is it inappropriate to do this in the Activator (if so, where should
> it be done to perform something on loading of the plugin which uses
> the PreferenceStore?) or does the PreferenceStore need to be accessed
> in another way than mentioned above when doing it in the Activator?
> kind regards
>
> Martin
>
Re: Preference Values [message #662020 is a reply to message #661883] Mon, 28 March 2011 22:24 Go to previous messageGo to next message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
Dani Megert wrote on Mon, 28 March 2011 14:04

I don't see how getPreferenceStore() would cause an NPE.

Well yes, it's quite confusing because it checks for being null and creates a new store in that case (which it shouldn't btw. I'm not wanting to create a new store, I want to use my existing data. Or would that be the case if it creates a new one at this point?)
Anyway here's a debug-session which shows the NPE: http://vimeo.com/21603141 (HD in fullscreeen-mode makes the fonts readable)
I'm pressing F5-F6-F6 when "miracle" steps appear in the video, sry, should have used the mouse maybe to make it more clear.
I'm completely lost on what goes wrong there. ;-(
regards

Martin


> Is it inappropriate to do this in the Activator (if so, where should
> it be done to perform something on loading of the plugin which uses
> the PreferenceStore?) or does the PreferenceStore need to be accessed
> in another way than mentioned above when doing it in the Activator?
> kind regards
>
> Martin

[Updated on: Mon, 28 March 2011 22:25]

Report message to a moderator

Re: Preference Values [message #662075 is a reply to message #662020] Tue, 29 March 2011 07:34 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 29.03.2011 00:24, Martin wrote:
> Dani Megert wrote on Mon, 28 March 2011 14:04
>> I don't see how getPreferenceStore() would cause an NPE.
>
> Well yes, it's quite confusing because it checks for being null and
> creates a new store in that case (which it shouldn't btw. I'm not
> wanting to create a new store, I want to use my existing data. Or
> would that be the case if it creates a new one at this point?) Anyway
> here's a debug-session which shows the NPE: http://vimeo.com/21603141
> I'm pressing F5-F6-F6 when "miracle" steps appear in the video, sry,
> should have used the mouse maybe to make it more clear.
> I'm completely lost on what goes wrong there. ;-(
Sorry, that was my bad - I didn't notice that you do it in the
constructor. You can basically do it anywhere in the activator but not
in the constructor because there 'start' wasn't called yet and hence the
bundle (i.e. getBundle()) is still 'null'.

Dani
> regards
>
> Martin
>
>
>> Is it inappropriate to do this in the Activator (if so, where should
>> it be done to perform something on loading of the plugin which uses
>> the PreferenceStore?) or does the PreferenceStore need to be accessed
>> in another way than mentioned above when doing it in the Activator?
>> kind regards
>>
>> Martin
Re: Preference Values [message #665660 is a reply to message #662075] Fri, 15 April 2011 12:19 Go to previous message
Martin F.Friend
Messages: 12
Registered: January 2011
Junior Member
Dani Megert wrote on Tue, 29 March 2011 09:34

> Sorry, that was my bad - I didn't notice that you do it in the
> constructor. You can basically do it anywhere in the activator but not
> in the constructor because there 'start' wasn't called yet and hence the
> bundle (i.e. getBundle()) is still 'null'.


Okay thanks, taking it out of the constructor fixes this NP-issue but leaves the problem that nothing is being performed during/after load of Eclipse and my plugin. I have to open the preference page to make it perform the wanted steps (reading the pref and performing calling a function according to it) but I'm searching for a way so it does that without opening the preferences page. (as mentioned below)

>> Is it inappropriate to do this in the Activator (if so, where should
>> it be done to perform something on loading of the plugin which uses
>> the PreferenceStore?) or does the PreferenceStore need to be accessed
>> in another way than mentioned above when doing it in the Activator?
>> kind regards
>>
>> Martin

[Updated on: Thu, 16 June 2011 15:03]

Report message to a moderator

Previous Topic:Using Javadoc in eclipse
Next Topic:m2eclispe questions
Goto Forum:
  


Current Time: Thu Apr 25 17:48:52 GMT 2024

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

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

Back to the top