Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store?
Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412156] Wed, 23 February 2005 18:18 Go to next message
Eclipse UserFriend
Originally posted by: michael.refactored-networks.com

My RCP application is going to have several preference pages, so I've
started with the first one, called BrowserPreferencePage. In its
constructor I do this:

public BrowserPreferencePage() {
super();
BrowserApplication app = BrowserApplication.getDefault();
IPreferenceStore store = app.getPreferenceStore();
setPreferenceStore(store);
initializeDefaults();
}

in order to set the PreferenceStore to the one for the main plugin that
the whole application is based on. But when I run this I get a
NullPointerException inside getPreferenceStore(). Inside
AbstractUIPlugin.getPreferenceStore() there is this:


public IPreferenceStore getPreferenceStore() {
// Create the preference store lazily.
if (preferenceStore == null) {
preferenceStore =
new ScopedPreferenceStore(new InstanceScope(),
getBundle().getSymbolicName());

}
return preferenceStore;
}

Apparently what's getting the null is the getBundle() because bundle
inside the Plugin is null.

Is there something I'm missing that needs to be done before I can
reference the PreferenceStore? Am I even doing this the right way for RCP?

Thanks!

-MM

(BTW, SWTDesigner is saving boat loads of time... nice package)
Re: Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412157 is a reply to message #412156] Wed, 23 February 2005 18:56 Go to previous messageGo to next message
Chris Laffra is currently offline Chris LaffraFriend
Messages: 253
Registered: July 2009
Senior Member
What constructor(s) did you specify for your BrowserApplication class?

--
Chris Laffra, http://eclipsefaq.org


"Michael Mealling" <michael@refactored-networks.com> wrote in message
news:pan.2005.02.23.18.18.44.946920@refactored-networks.com...
> My RCP application is going to have several preference pages, so I've
> started with the first one, called BrowserPreferencePage. In its
> constructor I do this:
>
> public BrowserPreferencePage() {
> super();
> BrowserApplication app = BrowserApplication.getDefault();
> IPreferenceStore store = app.getPreferenceStore();
> setPreferenceStore(store);
> initializeDefaults();
> }
>
> in order to set the PreferenceStore to the one for the main plugin that
> the whole application is based on. But when I run this I get a
> NullPointerException inside getPreferenceStore(). Inside
> AbstractUIPlugin.getPreferenceStore() there is this:
>
>
> public IPreferenceStore getPreferenceStore() {
> // Create the preference store lazily.
> if (preferenceStore == null) {
> preferenceStore =
> new ScopedPreferenceStore(new InstanceScope(),
> getBundle().getSymbolicName());
>
> }
> return preferenceStore;
> }
>
> Apparently what's getting the null is the getBundle() because bundle
> inside the Plugin is null.
>
> Is there something I'm missing that needs to be done before I can
> reference the PreferenceStore? Am I even doing this the right way for RCP?
>
> Thanks!
>
> -MM
>
> (BTW, SWTDesigner is saving boat loads of time... nice package)
Re: Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412160 is a reply to message #412157] Wed, 23 February 2005 19:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michael.refactored-networks.com

On Wed, 23 Feb 2005 13:56:57 -0500, Chris Laffra wrote:

> What constructor(s) did you specify for your BrowserApplication class?

Here's the entire class with the crud cut out for brevity:

package com.refactored_networks.epc.epcbrowser;

import bla....

public class BrowserApplication extends AbstractUIPlugin implements IPlatformRunnable {
public static final String INDEX_TABLE_USE_ONS_PREF_KEY = "com.refactored_networks.epc.epcnetwork.prefs.use_ons";

private static BrowserApplication plugin;

public BrowserApplication() {
if (plugin == null) {
plugin = this;
}
}

public Object run(Object args) {
WorkbenchAdvisor workbenchAdvisor = new RcpWorkbenchAdvisor();
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display,
workbenchAdvisor);
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
} else {
return IPlatformRunnable.EXIT_OK;
}
} finally {
display.dispose();
}
}
public static BrowserApplication getDefault() {
return plugin;
}
}
Re: Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412284 is a reply to message #412160] Wed, 23 February 2005 21:45 Go to previous messageGo to next message
Nitin Dahyabhai is currently offline Nitin DahyabhaiFriend
Messages: 4435
Registered: July 2009
Senior Member

Michael,
You've probably got two different instances of your class being
created--one created because it implements IPlatformRunnable,
another later as the plugin. The IPlatformRunnable instance is the
one set into your static field because of the ordering, but it's the
plugin instance that actually gets the bundle set into it. When you
call getDefault(), you're getting the IPlatformRunnable instance.

--
- Nitin


_
Nitin Dahyabhai
Eclipse Web Tools Platform
Re: Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412290 is a reply to message #412284] Wed, 23 February 2005 22:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michael.refactored-networks.com

On Wed, 23 Feb 2005 16:45:59 -0500, Nitin Dahyabhai wrote:

> Michael,
> You've probably got two different instances of your class being
> created--one created because it implements IPlatformRunnable,
> another later as the plugin. The IPlatformRunnable instance is the
> one set into your static field because of the ordering, but it's the
> plugin instance that actually gets the bundle set into it. When you
> call getDefault(), you're getting the IPlatformRunnable instance.


Yep. That's the conclusion we've come to on #eclipse. The question is how
to fix it. The suggestion on the channel is to separate the
IPlatformRunnable from the AbstractUIPlugin classes. But we have no idea
where each would then be referenced. Is it something like this in
plugin.xml:

<?eclipse version="3.0"?>
<plugin
....
class="path-to-class-that-implements-AbstractUIPlugin">
<extension
id="BrowserApplication"
point="org.eclipse.core.runtime.applications">
<application>
<run
class="com.refactored_networks.epc.epcbrowser.BrowserApplication ">
</run>
</application>
</extension>
</plugin>

or am I completely missing the entire way I'm supposed to be doing
preferences in RCP applications? I have my preference pages implemented. I
just have no idea how to connect them up to my applications
preferencestore (or even if we're still supposed to be using
preferencestores).

-MM
Re: Is AbstractUIPlugin.getPreferenceStore() the right way to get an RCP apps preference store? [message #412300 is a reply to message #412290] Wed, 23 February 2005 23:16 Go to previous message
Eclipse UserFriend
Originally posted by: michael.refactored-networks.com

Yep. That actually worked. For anyone reading this thread here's what I
ended up doing. In plugin.xml I now have this:

<plugin
id="com.refactored_networks.epc.epcbrowser"
name="%pluginName"
version="0.0.0"
class="com.refactored_networks.epc.epcbrowser.MainBrowserPlugin "
provider-name="%providerName">

.... various things....
<extension
id="BrowserApplication"
point="org.eclipse.core.runtime.applications">
<application>
<run
class="com.refactored_networks.epc.epcbrowser.BrowserApplication ">
</run>
</application>
</extension>

Then I removed just about everything from BrowserApplication except for
the run(). it now looks like this:
public class BrowserApplication implements IPlatformRunnable {

public Object run(Object args) {
WorkbenchAdvisor workbenchAdvisor = new RcpWorkbenchAdvisor();
Display display = PlatformUI.createDisplay();
try {
int returnCode = PlatformUI.createAndRunWorkbench(display,
workbenchAdvisor);
if (returnCode == PlatformUI.RETURN_RESTART) {
return IPlatformRunnable.EXIT_RESTART;
} else {
return IPlatformRunnable.EXIT_OK;
}
} finally {
display.dispose();
}
}
}

Now, the new MainBrowserPlugin class has all of this in it:

public class MainBrowserPlugin extends AbstractUIPlugin {
public static final String A_PREF_KEY =
"com.refactored_networks.epc.epcnetwork.prefs.apref";

private static MainBrowserPlugin plugin;

public MainBrowserPlugin() {
super();
if (plugin == null) {
plugin = this;
}
}

public static MainBrowserPlugin getDefault() {
if(plugin == null) {
System.out.println("plugin is null!!!!!!");
}
return plugin;
}
}

Now, with all of that done. Inside my various preference pages I can do
this:

public BrowserPreferencePage() {
super();
setPreferenceStore(MainBrowserPlugin.getDefault().getPrefere nceStore());
initializeDefaults();
}

Which sets the preference store for that preference page, allowing me to
use the preference field stuff to handle all of the widgets and getting
and saving of the preferences. Here's an example that uses a radio group:
final RadioGroupFieldEditor radioGroupFieldEditor = new RadioGroupFieldEditor("",
"Source of Index values", 1, new String[][] {new String[] {"Use ONS",
MainBrowserPlugin.INDEX_TABLE_USE_ONS_PREF_KEY}, new String[] {"Use XML",
MainBrowserPlugin.INDEX_TABLE_USE_XML_PREF_KEY}}, composite);
final Label label = radioGroupFieldEditor.getLabelControl(composite);
addField(radioGroupFieldEditor);

Neat!

Now to figure out how to setup change listeners so my Views can tell when
the user has changed something in the preferences.

-MM

On Wed, 23 Feb 2005 17:18:10 -0500, Michael Mealling wrote:
> On Wed, 23 Feb 2005 16:45:59 -0500, Nitin Dahyabhai wrote:
>
>> Michael,
>> You've probably got two different instances of your class being
>> created--one created because it implements IPlatformRunnable,
>> another later as the plugin. The IPlatformRunnable instance is the
>> one set into your static field because of the ordering, but it's the
>> plugin instance that actually gets the bundle set into it. When you
>> call getDefault(), you're getting the IPlatformRunnable instance.
>
>
> Yep. That's the conclusion we've come to on #eclipse. The question is how
> to fix it. The suggestion on the channel is to separate the
> IPlatformRunnable from the AbstractUIPlugin classes. But we have no idea
> where each would then be referenced. Is it something like this in
> plugin.xml:
>
> <?eclipse version="3.0"?>
> <plugin
> ...
> class="path-to-class-that-implements-AbstractUIPlugin">
> <extension
> id="BrowserApplication"
> point="org.eclipse.core.runtime.applications">
> <application>
> <run
> class="com.refactored_networks.epc.epcbrowser.BrowserApplication ">
> </run>
> </application>
> </extension>
> </plugin>
>
> or am I completely missing the entire way I'm supposed to be doing
> preferences in RCP applications? I have my preference pages implemented. I
> just have no idea how to connect them up to my applications
> preferencestore (or even if we're still supposed to be using
> preferencestores).
>
> -MM
Previous Topic:How to force loading of contributed AdapterFactory
Next Topic:progress
Goto Forum:
  


Current Time: Thu Apr 25 11:21:11 GMT 2024

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

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

Back to the top