Section 13.4. Property Pages Reused as Preference Pages


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.

package com.qualityeclipse.favorites.properties; 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) {       BasicFavoriteItem.setDefaultColor(          BasicFavoriteItem.getColor(rgb));    }    protected String getCommentPropertyValue() {       return BasicFavoriteItem.getDefaultComment();    }    protected void setCommentPropertyValue(String comment) {       BasicFavoriteItem.setDefaultComment(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 = "com.qualityeclipse.favorites.properties.FavoriteDefaultsPreferencePage"

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.




Eclipse(c) Building Commercial-Quality Plug-ins
Eclipse: Building Commercial-Quality Plug-ins (2nd Edition)
ISBN: 032142672X
EAN: 2147483647
Year: 2004
Pages: 200

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net