Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Migrate Preferences to pure e4 application
Migrate Preferences to pure e4 application [message #1239097] Mon, 03 February 2014 11:02 Go to next message
Divya garg is currently offline Divya gargFriend
Messages: 8
Registered: November 2013
Junior Member
Hello All,

I am migrating my application to pure e4 application. For migration of preferences I referred the vogella article.

In eclipse 3.x, AbstractUIPlugin getPreferenceStore() has related APIs which takes care of your preference settings. You just need to set your key-value pairs using getPreferenceStore().setValue() and also the default settings using getPreferenceStore().setToDefault(), getPreferenceStore().setDefault().
Here if the set value is same to the default value then the key-value pair does not get stored in the preference file. And also if set value is not available then it returns the default value on its own. These things are automatically taken care by preference store.

In eclipse 4.3 I am migrating all this to pure e4 application. I created Preferences with a custom name and also put key-value pairs to it. Up till now everything worked fine. But then as in eclipse 3.x there is a separate mechanism for handling default values of your preferences. Can we have similar mechanism who optimizes preference store and handles default values as well?

Can anyone please help me out with this?
Any suggestions?

Thanks & Regards
Divya

Re: Migrate Preferences to pure e4 application [message #1239526 is a reply to message #1239097] Tue, 04 February 2014 11:28 Go to previous messageGo to next message
Mateusz Malinowski is currently offline Mateusz MalinowskiFriend
Messages: 36
Registered: March 2013
Location: Bristol
Member
Hi!

Unfortunately I have never used RCP 3, but in e4 I initialise default preferences in addon, where I call:

@Inject
public PrefsAddon(@Preference(nodePath = "/default/" + Activator.PLUGIN_ID)
        IEclipsePreferences preferences) throws BackingStoreException 
{
    preferences.put(..., ...);
        
    preferences.flush();
}


Then whenever I click "set default" in preference page, or I want to get this preference from my PLUGIN_ID node, which is not set there, the default value is returned. As I said, I'm not entirely sure whether this is what you are looking for, but maybe it will help you somehow.

[Updated on: Thu, 06 February 2014 08:58]

Report message to a moderator

Re: Migrate Preferences to pure e4 application [message #1239827 is a reply to message #1239526] Wed, 05 February 2014 06:20 Go to previous messageGo to next message
Divya garg is currently offline Divya gargFriend
Messages: 8
Registered: November 2013
Junior Member
Hello,

Yes I am looking for something like this only. Thank you so much for your response.

In your example you have initialized default preferences for the plugin and putting some value to it.
For this plugin there needs to be preferences which get stored in the runtime within the Instance scope of the plugin. which would be something like
@Inject
public ThreedROVAddon(@Preference(nodePath = Activator.PLUGIN_ID)
IEclipsePreferences preferences) throws BackingStoreException
{
preferences.put(..., ...);

preferences.flush();
}

now you have two instance of preferences one with Default scope say pref1 and one with Instant scope say pref2. So the key-value you put in pref2 only will get stored in the *.pref file in the workspace and pref1 will remain in cache which has all the default values of keys stored.
Now if you try to get values from pref2 which is not actually set then it should be returned from its default scope. but this is not happening actually.

I don't know If I am doing it in a right way.
Can you please look and halp me out.

Thanks
Divya
Re: Migrate Preferences to pure e4 application [message #1240347 is a reply to message #1239827] Thu, 06 February 2014 09:15 Go to previous messageGo to next message
Mateusz Malinowski is currently offline Mateusz MalinowskiFriend
Messages: 36
Registered: March 2013
Location: Bristol
Member
Divya,

Sorry, I was thinking about Preference Pages. When you restore to default, it will take values from pref1.

I believe, that because when you inject IEclipsePreferences, whenever you want to get value from them, you need to specify default value in case the one that you want to obtain doesn't exist. What you can try to do, is to create your own Preference class as singleton, which will provide functions to get and set values. It that class you can have something like:
public String get(String key)
{
    return pref2.get(key, pref1.get(key, ""));
}

You would have to initiate this class at your application's start-up and inject both scopes of preferences.
Other way would be to create this class and put it into you application's context, so you can inject it whenever you want. But that would be possible only for view component of your application.

But these are just my thoughts, so perhaps someone more experienced would provide you a better solution Smile
Re: Migrate Preferences to pure e4 application [message #1240426 is a reply to message #1240347] Thu, 06 February 2014 12:26 Go to previous messageGo to next message
Divya garg is currently offline Divya gargFriend
Messages: 8
Registered: November 2013
Junior Member
Thanks Mateusz for your valuable comments.

The example you shown is exactly what I am doing. So this confirms me that I am doing it in a right way.
As in 3.x this handling of default values is all handled by eclipse internally so that's why I was thinking about the same mechanism in 4.x also.

It actually has other optimizations also like if you have set some value as Default and then if you try to set the same value in the Instant scope then it should not be written there as it is already there in Default scope and the entry should be removed from the Instant scope. So now I have to take care of this also through my code.

This all solves my problem.
Thank you so much for your answers.

Regards
Divya
Re: Migrate Preferences to pure e4 application [message #1257439 is a reply to message #1240426] Wed, 26 February 2014 12:28 Go to previous message
Olivier Prouvost is currently offline Olivier ProuvostFriend
Messages: 15
Registered: August 2011
Location: TOULOUSE
Junior Member

Hi,

To manage default values of your preferences, you can use an IPreferenceStore or call directly the getXXX methods on IEclipsePreferences with the default value. But your problem is not solved with preference pages... How do you manage and display your pages ?

There are several problems in the preference code in E3 to use it in a pure E4 application :


  1. The ScopedPreferenceStore is managed by org.eclipse.ui (-> forbidden to use it in pure E4)
  2. The preferencePage extension point expects an IWorkbenchPreferencePage (also defined in E3) instead of a preferencePage
  3. E4 do not provide any code to compute a PreferenceManager (used by PreferenceDialog), because no extension is available.

So I separated those three problems in a specific plugin which provides :

  • an e4PreferencePages extension point, expecting the same values as old E3 extension point, but the preference page class must extends FieldEditorPreferencePage
  • an automatic binding with the ScopedPreferenceStore when the page is created (could be upgraded to other scopes)
  • a copy of ScopedPreferenceStore to remove E3 coupling !!
  • an E4PreferencesHandler which reads this extension point and display the face preference dialog.


To use it, just depend on it, and create your preference pages with the new extension point. Then add the E4Preference command and handlers in your application.

Of course, preference dialogs should be UI agnostic and this solution is bound to JFace, and it does not use the Dialog concept in the Luna application model (when it will be ready and the bug on fragment will be fixed, this solution will be obsolete). But today, the main migration issues on this problem concern JFace.

You can get this plugin and its test sample on github (I can not put url on this forum !! So search for opcoach and the repository is e4Preferences (opcoach/e4Preferences)

Feel free to post any remark about it...

[Updated on: Wed, 26 February 2014 12:47]

Report message to a moderator

Previous Topic:Switch Perspective on startup in E4 application
Next Topic:Command handlers enabled state polled (in 4.3)
Goto Forum:
  


Current Time: Sat Jun 12 21:42:25 GMT 2021

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

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

Back to the top