Previous Page
Next Page

17.5. Using the Extension Point

The FavoriteItemType has been refactored to use information from the favorites extension point. So now, the constants in that class must be recast as extensions and associated factory classes. This modification will help you test your new extension point.

On the plug-in manifest editor's Extensions page, click the Add... button to open the New Extensions wizard. When the wizard appears, select the new favorites extension point (see Figure 17-7) and then click Finish.

Now that you have created an extension, you need to add a new item-Type representing the Workbench File item type. Right-click on the new favorites extension and select New > itemType to add a new Favorites item type. Click on the new itemType and change the properties as follows (see Figure 17-9).

Figure 17-9. The Extension Element Details showing Workbench File item type properties.


For the icon attribute specified, icons from the Eclipse UI and JDT UI plug-ins have been copied into the Favorites plug-in. Clicking the Browse... button at the right of the icon attribute field opens an image selection dialog so that you can select the appropriate image for the item type from images defined in the plug-in.

For the class attribute, select the class: label at the left of the class attribute field to open the Java Attribute Editor wizard. Enter "com.qualityeclipse.favorites.model.type" as the package name and "FileFactory" as the type name. Click on the Finish button to generate the new class. Move the newFavorite() and loadFavorite() methods from the WORKBENCH_FILE constant in the FavoriteItemType class so that the new FileFactory class looks like this:

package com.qualityeclipse.favorites.model.type;

import ...

public class FileFactory extends FavoriteItemFactory
{
   public IFavoriteItem newFavorite(
      FavoriteItemType type, Object obj
   ) {
      if (!(obj instanceof IFile))
         return null;
      return new FavoriteResource(type, (IFile) obj);
   }
   public IFavoriteItem loadFavorite(
      FavoriteItemType type, String info
   ) {
      return FavoriteResource.loadFavorite(type, info);
   }
}

Once complete, the first of several Favorites item types have been converted from a constant to an extension. Repeat this process multiple times to recast each constant Favorites item type in FavoriteItemType, except for the UNKNOWN item type discussed earlier (see Section 17.3.2, Constructing proxies, on page 609).


Previous Page
Next Page