Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » migrating preference-setting code to 3.0
migrating preference-setting code to 3.0 [message #259434] Thu, 08 July 2004 00:31 Go to next message
Tom Roche is currently offline Tom RocheFriend
Messages: 160
Registered: July 2009
Senior Member
I need to migrate some preference-setting code from 2.x to 3.0 and I'd
like to know if I'm doing this correctly: please advise.

When automating GUI testing (JUnit driving SWT using Abbot), I want to
minimize my interactions with "non-essential" UIs (i.e. unrelated to
the UIs I want to test), such as the welcome page and preference-
switching dialogs. To prevent the latter I created some utility
methods that worked with 2.1.3; now I want to migrate them to 3.0. The
following code compiles ...

> /**
> * Get the preference found in UI as
> * Windows>Preferences>Workbench>Perspecti ves>
> * Switch to associated perspective when creating a new project
> */
> public static String getSwitchToPerspectivePreference() {
> String val = null;
> IPreferenceStore ps =
WorkbenchPlugin.getDefault().getPreferenceStore();
> if (ps == null) {
> Logger.log("ERROR: could not get PreferenceStore from
WorkbenchPlugin");
> } else {
> val = ps.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E);
> if (isEmpty(val)) {
> if
(ps.contains(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E)) {
> Logger.log("ERROR: PreferenceStore returned empty pref value");
> } else {
> Logger.log("ERROR: PreferenceStore does not contain desired
pref key");
> }
> }
> }
> return val;
> }

> /**
> * Set the preference found in UI as
> * Windows>Preferences>Workbench>Perspecti ves>
> * Switch to associated perspective when creating a new project
> * Note that this pref is persisted!
> */
> public static void setSwitchToPerspectivePreference(String val) {
> IPreferenceStore ps =
WorkbenchPlugin.getDefault().getPreferenceStore();
> Assert.isNotNull(ps);
> if (ps.contains(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E)) {
> ps.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE , val);
> } else {
> Logger.log("ERROR: PreferenceStore does not contain desired pref
key");
> }
> }

> /**
> * Set the preference found in UI as
> * Windows>Preferences>Workbench>Perspecti ves>
> * Switch to associated perspective when creating a new project
> * to always switch. Note that this pref is persisted!
> */
> public static void alwaysSwitchToPerspective() {
> setSwitchToPerspectivePreference(IDEInternalPreferences.PSPM _ALWAYS);
> }

.... but I'm wondering if, e.g., I should be accessing the preferences
differently.
Re: migrating preference-setting code to 3.0 [message #259653 is a reply to message #259434] Thu, 08 July 2004 15:00 Go to previous message
Eclipse UserFriend
Originally posted by: dj_houghton.nospam.ca.ibm.com

This should work fine in 3.0. The underlying preference mechanism has
changed but it hasn't been surfaced to the user yet and all the backward
compatibility code is fully functional.

Tom Roche wrote:
> I need to migrate some preference-setting code from 2.x to 3.0 and I'd
> like to know if I'm doing this correctly: please advise.
>
> When automating GUI testing (JUnit driving SWT using Abbot), I want to
> minimize my interactions with "non-essential" UIs (i.e. unrelated to
> the UIs I want to test), such as the welcome page and preference-
> switching dialogs. To prevent the latter I created some utility
> methods that worked with 2.1.3; now I want to migrate them to 3.0. The
> following code compiles ...
>
> > /**
> > * Get the preference found in UI as
> > * Windows>Preferences>Workbench>Perspecti ves>
> > * Switch to associated perspective when creating a new project
> > */
> > public static String getSwitchToPerspectivePreference() {
> > String val = null;
> > IPreferenceStore ps =
> WorkbenchPlugin.getDefault().getPreferenceStore();
> > if (ps == null) {
> > Logger.log("ERROR: could not get PreferenceStore from
> WorkbenchPlugin");
> > } else {
> > val =
> ps.getString(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E);
> > if (isEmpty(val)) {
> > if
> (ps.contains(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E)) {
> > Logger.log("ERROR: PreferenceStore returned empty pref value");
> > } else {
> > Logger.log("ERROR: PreferenceStore does not contain desired
> pref key");
> > }
> > }
> > }
> > return val;
> > }
>
> > /**
> > * Set the preference found in UI as
> > * Windows>Preferences>Workbench>Perspecti ves>
> > * Switch to associated perspective when creating a new project
> > * Note that this pref is persisted!
> > */
> > public static void setSwitchToPerspectivePreference(String val) {
> > IPreferenceStore ps =
> WorkbenchPlugin.getDefault().getPreferenceStore();
> > Assert.isNotNull(ps);
> > if (ps.contains(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MOD E)) {
> > ps.setValue(IDEInternalPreferences.PROJECT_SWITCH_PERSP_MODE , val);
> > } else {
> > Logger.log("ERROR: PreferenceStore does not contain desired pref
> key");
> > }
> > }
>
> > /**
> > * Set the preference found in UI as
> > * Windows>Preferences>Workbench>Perspecti ves>
> > * Switch to associated perspective when creating a new project
> > * to always switch. Note that this pref is persisted!
> > */
> > public static void alwaysSwitchToPerspective() {
> > setSwitchToPerspectivePreference(IDEInternalPreferences.PSPM _ALWAYS);
> > }
>
> ... but I'm wondering if, e.g., I should be accessing the preferences
> differently.
Previous Topic:Eclipse 3.0 Ant editor problem
Next Topic:Availability ofGerman Language Pack for Eclipse 3.0 ?
Goto Forum:
  


Current Time: Thu Dec 26 14:06:43 GMT 2024

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

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

Back to the top