Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse preference changes by code itself(Eclipse preferences)
Eclipse preference changes by code itself [message #759252] Mon, 28 November 2011 05:14 Go to next message
tskumarme is currently offline tskumarmeFriend
Messages: 13
Registered: November 2011
Junior Member
Hi All,
I would like to change eclipse preference options programmatically, I don't want my users do manual configurations. Kindly guide me on this. I've searched in net, but didn't get a exact example to achieve this. (Ex: changing code formatter profile automatically when the eclipse starts.)

Thanks in advance.
Re: Eclipse preference changes by code itself [message #759503 is a reply to message #759252] Mon, 28 November 2011 20:10 Go to previous messageGo to next message
Michael Pellaton is currently offline Michael PellatonFriend
Messages: 289
Registered: July 2009
Senior Member
Hello

I guess you need the extension point org.eclipse.ui.startup and IStartup
to implement the automatic preference handling during the workbench start.

IPreferenceService is the interface to perferences related issues:
http://help.eclipse.org/helios/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fruntime_preferences.htm

In your case, I would consider importing your default preferences from
an EPF file located within your plugin. The code should be similar to
this one, except for the loading from classpath resource instead of a
HTTP transfer:
https://svn.kenai.com/svn/ete~svn/ete/trunk/ch.netcetera.eclipse.workspaceconfig.ui

BTW: there is a IStartup handler in the code above too.

Cheers
Michael
Re: Eclipse preference changes by code itself [message #759542 is a reply to message #759503] Tue, 29 November 2011 05:49 Go to previous messageGo to next message
tskumarme is currently offline tskumarmeFriend
Messages: 13
Registered: November 2011
Junior Member
Hi,

Thanks for your wonderful example for my problem. Very Happy I've loaded my own preferences for code formatter by using JavaCore.setOptions(xml file) and able to format successfully.

Now I'm in need of changing the preference's code formatter profile change, since I've done programmatically its preview, profile still pointing to the old one.

Able to traverse up to "Formatter" node of the preference window, but not able to retrieve the page to modify the things to wanted to.

Thanks in advance.
Re: Eclipse preference changes by code itself [message #760047 is a reply to message #759542] Thu, 01 December 2011 05:37 Go to previous message
tskumarme is currently offline tskumarmeFriend
Messages: 13
Registered: November 2011
Junior Member
Hi,
At the end of big struggle got a solution to my problem. I've provided the sample codes here (may be it will useful for others like me Smile ).

IProfileVersioner versioner = new ProfileVersioner();
ProfileStore store = new FormatterProfileStore(versioner);
IScopeContext scope = PreferencesAccess.getOriginalPreferences().getInstanceScope();
List profiles = store.readProfiles(scope);
ProfileManager manager = new FormatterProfileManager(profiles, scope, PreferencesAccess.getOriginalPreferences(), versioner);
Collection cprofiles = store.readProfilesFromFile(propertiesFile);
for ( Object profile : cprofiles) {
org.eclipse.jdt.internal.ui.preferences.formatter.ProfileManager.CustomProfile cc = (CustomProfile) profile;
versioner.update(cc);
manager.addProfile(cc);
}
store.writeProfiles(manager.getSortedProfiles(), scope);
manager.commitChanges(scope);

Really it was very hard to find these easy methods to work it out.Thanks Michael.
Previous Topic:Need Help on How to Access Information of a Eclipse Plugin Programatically
Next Topic:FATAL ERROR: No such file or directory??
Goto Forum:
  


Current Time: Fri Aug 06 03:55:43 GMT 2021

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

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

Back to the top