Time for action – searching for preferences

Eclipse has a search field in the preferences list. This is defined not from the UI but from a separate keyword extension instead. The keyword has an id and a label. The label is a space-separated list of words that can be used in the filtering dialog.

  1. To add the offset and timezone keywords to ClockPreferencePage, create a new extension point in plugin.xml for org.eclipse.ui.keywords:
    <extension point="org.eclipse.ui.keywords">
    <keyword id="com.packtpub.e4.clock.ui.keywords"label="offset timezone"/>
    </extension>
  2. Now associate these keywords with the preference page itself:
    <extension point="org.eclipse.ui.preferencePages">
    <page name="Clock" ... ><keywordReference id="com.packtpub.e4.clock.ui.keywords"/>
    </page>
    </extension>
  3. Run the target Eclipse instance, go to the Preferences page, and type timezone or offset in the search box. The Clock preference page should be shown in both cases:
    Time for action – searching for preferences

What just happened?

By providing a list of keywords and associating them with the preferences page, the user can search for the item in the preferences tree. The same keyword support is used to search for items in other places, such as the New dialog wizards and the properties page.

Furthermore, these keywords are translatable. By specifying a key with a percent symbol (%), Eclipse can load the keywords from an externalized file called plugin.properties. If %clock.keywords was used as the label and the plugin.properties had an entry clock.keywords=timezone offset, then other translations could be provided; for example, a French translation of the keywords can be provided in a plugin_fr.properties file.

Have a go hero – translating into different languages

Eclipse's internationalization support is provided by a plugin.properties file. In plugin.xml, instead of using strings for the values, use %keys. The % instructs the engine to look for a corresponding entry in plugin.properties to display the value.

To support different languages, use different language codes, such as plugin_fr.properties and plugin_de.properties for French and German respectively (remember to add these files to build.properties or else they won't be found). The keys are still the same, but the values can be localized appropriately. The search keywords are an example of something that can be searched as well, so use an online translation service or make up a translation to test out the effect of running Eclipse in a different language. Eclipse can be launched in different languages with eclipse -nl de on the command line.

Pop quiz – understanding preferences

Q1. What is the default style used for FieldEditorPreferencePage and how can it be changed to something more aesthetically pleasing?

Q2. What kinds of primitive values can be edited with a FieldEditorPreferencePage?

Q3. How can a preference value be searched for in the preference page?

Q4. How can preference values be injected into an E4 part?

Q5. How can a part respond to changes in a preference value?

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.38.221