Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "E4/Doc/Preferences"

< E4‎ | Doc
(Relevant Terms)
Line 2: Line 2:
  
 
[[Image:Service diagram.jpg|thumb|alt=Diagram of services in E4.|A placeholder diagram.]]
 
[[Image:Service diagram.jpg|thumb|alt=Diagram of services in E4.|A placeholder diagram.]]
 +
Users often require the ability to customize application features according to their individual needs or preferences.
 +
Eclipse e4 provides a mechanism to persist and retrieve these customizations, known as Preferences, within a range of scopes.
  
The ability for users to customize application features according to their individual requirements is often useful.  Eclipse e4 provides a mechanism to persist and retrieve these customizations, known as preferences, within a range of scopes. 
+
In the most common case, a user preference is simply a key-value pair that is associated with an Eclipse instance.  For example, the preference which specifies that a user would like a tool tip displayed on startup may be stored as  "showToolTip=true".
 
+
In the most common case, a user preference is simply a key-value pair that is associated with an Eclipse instance.  For example, the preference that specifies that a user would like to have a tool tip displayed on startup could be stored as  "showToolTip=true".
+
  
 
== Relevant Terms ==
 
== Relevant Terms ==
 
 
*Key - A key is a unique string identifier for a preference setting.
 
*Key - A key is a unique string identifier for a preference setting.
 
*Value - A value is the current preference setting associated with a key, within a specific scope.
 
*Value - A value is the current preference setting associated with a key, within a specific scope.
 
*Instance scope - Preferences in this scope are specific to a single Eclipse workspace.
 
*Instance scope - Preferences in this scope are specific to a single Eclipse workspace.
*Configuration scope - Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by that user. On a multi-user installation, these preferences are shared by all users of the configuration.
+
*Configuration scope - Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by the user. On a multi-user installation, these preferences are shared by all users of the configuration.
 +
*Workbench model - an XML file specifying the injections.
  
 
== Motivation ==
 
== Motivation ==
Over time there were lots of API's with varying degrees of completeness developed in Eclipse 3.x and earlier to manage user preferences. In E4, and effort was made to streamline the most common case while maintaining the functionality of older API's.
+
Eclipse 3.x and earlier offered a number of API's with varying degrees of completeness allowing to manage user preferences. In E4, an effort was made to streamline the most common case while maintaining the functionality of older API's.
  
The most frequent case for preferences is simply retrieving a value that has already been set. This is easily done through dependency injection by the framework at runtime, using the appropriate JSR Annotations. The framework will update the value of your preference variable as it is changed as well however through this method you are unable to be notified of these changes.
+
The most frequent use case for preferences is retrieving a value that has already been set. This is easily done through dependency injection by the framework at runtime, using the appropriate JSR Annotations. Eclipse also allows the value of a preference to be injected into the component without persistence.  
  
The next case for preferences is when you need to set or create them. In E4 you can still access the existing IEclipsePreferences API through dependency injection as well. IEclipsePreferences will allow you, among other things, to create/modify preference values but also use "setters" on preferences and attach listeners to be notified when they change so you can react appropriately.
+
Other use cases are: creating preferences, setting values of particular keys and persisting preference changes. In e4 developers can still access the existing IEclipsePreferences API through dependency injection in order to implement the aforementioned features. In addition, IEclipsePreferences allows the attachment of listeners which are notified upon preference changes. By default all values are stored in the "instance scope" of the corresponding bundle (plugin).
  
Finally the framework allows you to set various scopes on the preferences (instance scope by default) as well as chain scopes for precedence through the use of IEclipsePreferences too.
+
Finally the framework allows developers to set various scopes on preferences as well as to chain scopes for precedence through the use of IEclipsePreferences. Preferences associated with the currently running Eclipse instance can also be retrieved.
  
 
== Applicability ==
 
== Applicability ==
Line 47: Line 47:
  
 
</source>
 
</source>
 +
 +
Preference values are stored in files, one file per plugin. If the developer is intending to create, view or modify preferences valid for all workspaces, the Equinox bundle can be used to access preferences stored at the level of the install. In addition, the Java IDE for example offers project specific settings; a "team" scope can also be specified. The lower level API can be used to implement chaining of various scopes.
  
 
== Related Services ==
 
== Related Services ==
[[E4/Doc/PersistingUIState|Persisting UI State]]
+
[[E4/Doc/PersistingUIState|Persisting UI State]] - related to the instance of a UI component (for example column width of a SearchView, previous search query, etc.). The Persisting UI State also involves the storage of keys and values but at a different scope and does not allow scope chaining.

Revision as of 22:26, 4 April 2010

Under Construction: Please read first!

The evolution of this document is a collaborative effort between a team of students at the University of Manitoba and the wider Eclipse community. Details about the project can be found here and on our Blog.

Your input is not just welcome; it is needed! Please contribute as your expertise allows, while adhering to our template. To send your feedback and any questions or comments you may have please email us. Also, while we do our very best to be as accurate and precise as possible, it is worth noting that we are students with limited exposure to the Eclipse platform, so if you see any incorrect technical details please let us know.

Diagram of services in E4.
A placeholder diagram.

Users often require the ability to customize application features according to their individual needs or preferences. Eclipse e4 provides a mechanism to persist and retrieve these customizations, known as Preferences, within a range of scopes.

In the most common case, a user preference is simply a key-value pair that is associated with an Eclipse instance. For example, the preference which specifies that a user would like a tool tip displayed on startup may be stored as "showToolTip=true".

Relevant Terms

  • Key - A key is a unique string identifier for a preference setting.
  • Value - A value is the current preference setting associated with a key, within a specific scope.
  • Instance scope - Preferences in this scope are specific to a single Eclipse workspace.
  • Configuration scope - Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by the user. On a multi-user installation, these preferences are shared by all users of the configuration.
  • Workbench model - an XML file specifying the injections.

Motivation

Eclipse 3.x and earlier offered a number of API's with varying degrees of completeness allowing to manage user preferences. In E4, an effort was made to streamline the most common case while maintaining the functionality of older API's.

The most frequent use case for preferences is retrieving a value that has already been set. This is easily done through dependency injection by the framework at runtime, using the appropriate JSR Annotations. Eclipse also allows the value of a preference to be injected into the component without persistence.

Other use cases are: creating preferences, setting values of particular keys and persisting preference changes. In e4 developers can still access the existing IEclipsePreferences API through dependency injection in order to implement the aforementioned features. In addition, IEclipsePreferences allows the attachment of listeners which are notified upon preference changes. By default all values are stored in the "instance scope" of the corresponding bundle (plugin).

Finally the framework allows developers to set various scopes on preferences as well as to chain scopes for precedence through the use of IEclipsePreferences. Preferences associated with the currently running Eclipse instance can also be retrieved.

Applicability

The applications of preferences are many:

  • UI customization: fonts, window & pane properties, and colors
  • Installation settings: locations of resources, working directories
  • Application settings: internationalization selections, program parameters

Implementation

In the most common case, e4 permits preference retrieval through dependency injection. By specifying an injection with a @Preference qualifier key, the qualifier's corresponding preference value is retrieved and injected.

For example, in the following Java code, a default username preference is retrieved to populate a field in a login window.

public class LoginWindow
 
@Inject @Preference(MyPrefConstants.DEFAULT_USERNAME) String username;
 
public LoginWindow(){
   getUserNameInput.setText(username);
}

Preference values are stored in files, one file per plugin. If the developer is intending to create, view or modify preferences valid for all workspaces, the Equinox bundle can be used to access preferences stored at the level of the install. In addition, the Java IDE for example offers project specific settings; a "team" scope can also be specified. The lower level API can be used to implement chaining of various scopes.

Related Services

Persisting UI State - related to the instance of a UI component (for example column width of a SearchView, previous search query, etc.). The Persisting UI State also involves the storage of keys and values but at a different scope and does not allow scope chaining.

Back to the top