Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » ApplyPreferences causes Default Preferences to disappear
ApplyPreferences causes Default Preferences to disappear [message #912934] Fri, 14 September 2012 12:34 Go to next message
Stefan Nöbauer is currently offline Stefan NöbauerFriend
Messages: 20
Registered: January 2012
Junior Member
Hi,

I implemented a feature for multiple user preferences. The export of the UserPreferences is working ok. with

 IPreferencesService service = Platform.getPreferencesService();

 File exportFile = File.createTempFile(USER_PREFERENCE_FILE_PREFIX,
           USER_PREFERENCE_FILE_SUFFIX, toFolder);

 os = new FileOutputStream(exportFile);

 service.exportPreferences(service.getRootNode(), os, null);


I also initialize my DefaultValues with the PreferenceInitializer framework.

But when I try to load the stored Preferences, all my default values are gone.

I load them with following code:

       IPreferencesService service = Platform.getPreferencesService();
        IExportedPreferences prefs;

        try {
            prefs = service.readPreferences(new FileInputStream(new File(
                    selectedFile)));

            service.applyPreferences(prefs, getTransfers());
        } catch (FileNotFoundException e) {
            ExceptionDialog.show(e, shell);
        } catch (CoreException e) {
            ExceptionDialog.show(e, shell);
        }

        return null;
    }

    private static IPreferenceFilter[] getTransfers() {
        IPreferenceFilter[] transfers = new IPreferenceFilter[1];

        // For export all create a preference filter that can export
        // all nodes of the Instance and Configuration scopes
        transfers[0] = new IPreferenceFilter() {

            @Override
            public String[] getScopes() {
                return new String[] { InstanceScope.SCOPE,
                        ConfigurationScope.SCOPE };
            }

            @Override
            @SuppressWarnings("rawtypes")
            public Map getMapping(String scope) {
                return null;
            }
        };

        return transfers;
    }



I`m using Eclipse 3.6 as RCP

Is there a bug or am I doing something wrong here?


Re: ApplyPreferences causes Default Preferences to disappear [message #912975 is a reply to message #912934] Fri, 14 September 2012 14:11 Go to previous messageGo to next message
Stefan Nöbauer is currently offline Stefan NöbauerFriend
Messages: 20
Registered: January 2012
Junior Member
Hi ... I`m sorry .. I have no Idea what I have done wrong but the problem I described above does not appear anymore.

But I run into another one.

The Problem is that the Preference Export only exports Preferences that differ from the default value.

So it is not possible to reset changed Preferences to the default by loading a stored PreferenceFile.

Does anyone know a way to solve this.

e.g.
- export every single preference
- reset the entire workbench to the default values
- ...
Re: ApplyPreferences causes Default Preferences to disappear [message #915958 is a reply to message #912975] Tue, 18 September 2012 09:46 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 14.09.2012 16:11, Stefan Nöbauer wrote:
> Hi ... I`m sorry .. I have no Idea what I have done wrong but the
> problem I described above does not appear anymore.
>
> But I run into another one.
>
> The Problem is that the Preference Export only exports Preferences
> that differ from the default value.
See https://bugs.eclipse.org/246754

Dani
>
> So it is not possible to reset changed Preferences to the default by
> loading a stored PreferenceFile.
>
> Does anyone know a way to solve this.
> e.g. - export every single preference - reset the entire workbench to
> the default values
> - ...
Re: ApplyPreferences causes Default Preferences to disappear [message #917922 is a reply to message #915958] Thu, 20 September 2012 15:11 Go to previous message
Stefan Nöbauer is currently offline Stefan NöbauerFriend
Messages: 20
Registered: January 2012
Junior Member
Thanks for the link.

In the meantime I implemented a workaround:

1. I exported all default values into a file
2. I removed all preferences with empty values
3. I changed the scope into /instance/
4. I imported these preferencefile

After that all preferences are set back to default.
Previous Topic:disposing the Perspective
Next Topic:InjectionException: java.lang.NoClassDefFoundError: XmlSchemaCollection
Goto Forum:
  


Current Time: Tue Apr 23 08:09:36 GMT 2024

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

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

Back to the top