Previous Page
Next Page

13.4. Property Pages Reused as Preference Pages

Since PropertyPage inherits from PreferencePage, with a little work you can reuse a Property page as a Preference page. In this case, you want to reuse the FavoriteItemPropertyPage as a Preference page for specifying the Color and comment properties' default values. To accomplish this, create a new FavoriteDefaultsPreferencePage as a subclass of FavoriteItemPropertyPage, which implements org.eclipse.ui.IWorkbenchPreferencePage and overrides the property accessor methods.


import ...

public class FavoriteDefaultsPreferencePage
   extends FavoriteItemPropertyPage
   implements IWorkbenchPreferencePage
   public void init(IWorkbench workbench) {

   protected RGB getColorPropertyValue() {
      return BasicFavoriteItem.getDefaultColor().getRGB();

   protected void setColorPropertyValue(RGB rgb) {

   protected String getCommentPropertyValue() {
      return BasicFavoriteItem.getDefaultComment();

   protected void setCommentPropertyValue(String comment) {

Then, create a new Preference page declaration in the Favorites plug-in manifest (see Section 12.1, Creating a Preference Page, on page 451) with the following attributes:

category = "com.qualityeclipse.favorites.prefs.view"

class = ""

id = "com.qualityeclipse.favorites.prefs.defaults"

name = "Defaults"

When complete, the Defaults preference page appears in the workbench Preferences dialog as a child of the Favorites preference page (see Figure 13-7).

Figure 13-7. Favorite Defaults preference page.

Previous Page
Next Page