Presentation is loading. Please wait.

Presentation is loading. Please wait.

Preferences in Eclipse 3.0 Present by Kun-Tse Wu.

Similar presentations


Presentation on theme: "Preferences in Eclipse 3.0 Present by Kun-Tse Wu."— Presentation transcript:

1 Preferences in Eclipse 3.0 Present by Kun-Tse Wu

2 Outline Introduction Introduction Runtime preferences Runtime preferences Preference scope Preference scope Preference service Preference service Using scopes and nodes Using scopes and nodes Extending the scopes Extending the scopes

3 Introduction Plug-in preferences are key/value pairs, where the key describes the name of the preference, and the value is one of several different types (boolean, double, float, int, long, or string). Plug-in preferences are key/value pairs, where the key describes the name of the preference, and the value is one of several different types (boolean, double, float, int, long, or string).

4 Runtime preferences In Eclipse 3.0, it provides core support for Eclipse preferences. In Eclipse 3.0, it provides core support for Eclipse preferences. Package org.eclipse.core.runtime.preferences specifies API for defining and accessing preferences in the runtime. Package org.eclipse.core.runtime.preferences specifies API for defining and accessing preferences in the runtime.

5 Preference scope The preference service uses the notion of preference scopes to describe the various areas where preferences can be saved. The preference service uses the notion of preference scopes to describe the various areas where preferences can be saved. The platform includes the following four preference scopes: The platform includes the following four preference scopes: Configuration scope Configuration scope Instance scope Instance scope Default scope Default scope Project scope Project scope

6 Configuration scope Configuration scoped preferences are stored per installation of the platform. They are shared between workspaces. Configuration scoped preferences are stored per installation of the platform. They are shared between workspaces. For example, if a user has a single installation of the platform, but runs several different workspaces, preferences scoped at the configuration level will be shared between the workspaces. For example, if a user has a single installation of the platform, but runs several different workspaces, preferences scoped at the configuration level will be shared between the workspaces.

7 Instance scope Preferences in this scope are stored per workspace, or running the instance of per platform. Preferences in this scope are stored per workspace, or running the instance of per platform. The old API method getPluginPreferences on Plugin stores its preferences at this scope. The old API method getPluginPreferences on Plugin stores its preferences at this scope.

8 Default scope Default scoped preferences represent the default values for preferences. These are not changed or stored by the platform. Default scoped preferences represent the default values for preferences. These are not changed or stored by the platform. However, the values originate from files stored with the plug-in's product or primary feature. However, the values originate from files stored with the plug-in's product or primary feature. When values are not found in other scopes, the default scope is consulted last to provide reasonable default values. When values are not found in other scopes, the default scope is consulted last to provide reasonable default values.

9 Project scope This scope stores values that are specific to a single project in your workspace, such as code formatter and compiler settings. This scope stores values that are specific to a single project in your workspace, such as code formatter and compiler settings. Note that this scope is provided by the org.eclipse.core.resources plug-in, which is not included in the Eclipse Rich Client Platform. This scope will not exist in applications that don ’ t explicitly include the resources plug-in. Note that this scope is provided by the org.eclipse.core.resources plug-in, which is not included in the Eclipse Rich Client Platform. This scope will not exist in applications that don ’ t explicitly include the resources plug-in.

10 Order of the scopes The default preference search look-up order as defined by the plaform is: The default preference search look-up order as defined by the plaform is: Project Project Instance Instance Configuration Configuration default default

11 Preference Service Preference service new in Eclipse 3.0 can be used to store preferences in different places. Preference service new in Eclipse 3.0 can be used to store preferences in different places. Once the preference service is obtained, preference values can be queried by name using any of get... methods provided in IPreferencesService. Once the preference service is obtained, preference values can be queried by name using any of get... methods provided in IPreferencesService. IPreferencesService IPreferencesService service = Platform.getPreferencesService(); boolean value = service.getBoolean("com.example.myplugin", "MyPreference", true, null );

12 Using Scopes and Nodes (1/2) If a plug-in needs finer control over the scope search order, classes that represent the scopes can be used to access the actual node that represents the preference at a particular scope. If a plug-in needs finer control over the scope search order, classes that represent the scopes can be used to access the actual node that represents the preference at a particular scope. … IPreferencesService service = Platform.getPreferencesService(); Preferences configurationNode = new ConfigurationScope().getNode("com.example.myplugin"); Preferences instanceNode = new InstanceScope().getNode("com.example.myplugin"); Preferences[] nodes = new Preferences[] {configurationNode, instanceNode}; stringValue = service.get("MyPreference", "true", nodes); //do something with the value. …

13 Using Scopes and Nodes (2/2) The root node of the preference tree can be obtained from the preferences service. The scope classes can be used to further traverse the tree. The root node of the preference tree can be obtained from the preferences service. The scope classes can be used to further traverse the tree. … IPreferencesService service = Platform.getPreferencesService(); Preferences root = service.getRootNode(); Preferences myInstanceNode = root.node(InstanceScope.SCOPE).node("com.example.myplugin"); if (myInstanceNode != null) { value = node.getBoolean("MyPreference", "true"); //do something with the value. } …

14 Extending the scopes (1/3) Plug-ins can define their own preference scopes, using the org.eclipse.core.runtime.preferences extension point. Plug-ins can define their own preference scopes, using the org.eclipse.core.runtime.preferences extension point. If you define your own scope, you can control how and where your preferences are loaded and stored. However, for most clients, the four built in scopes will be sufficient. If you define your own scope, you can control how and where your preferences are loaded and stored. However, for most clients, the four built in scopes will be sufficient.

15 Extending the scopes (2/3) <!ATTLIST extension point CDATA #REQUIRED id CDATA #IMPLIED name CDATA #IMPLIED> Element describing a client's definition of a new preference scope. <!ATTLIST scope name CDATA #REQUIRED class CDATA #REQUIRED> Element which defines the class to use for runtime preference initialization. <!ATTLIST initializer class CDATA #REQUIRED> name - The name of the scope. class - The name of the class.

16 Extending the scopes (3/3) The org.eclipse.core.runtime.preferences extension point is being used a new preferences initializer has been added. This solves the problem where default preferences where stored/updated only when the preferences pages where visited. The org.eclipse.core.runtime.preferences extension point is being used a new preferences initializer has been added. This solves the problem where default preferences where stored/updated only when the preferences pages where visited. Following is an example of a preference scope declaration. Following is an example of a preference scope declaration.

17 Example This example declares that this plug-in will provide a preference implementation for the scope "foo". This example declares that this plug-in will provide a preference implementation for the scope "foo". The class MyPreferenceInitializer contains code to be run to initialize preference default values at runtime. The class MyPreferenceInitializer contains code to be run to initialize preference default values at runtime.


Download ppt "Preferences in Eclipse 3.0 Present by Kun-Tse Wu."

Similar presentations


Ads by Google