DekGenius.com
Previous Section  < Day Day Up >  Next Section

Recipe 13.1 Creating a Plug-in That Supports Wizards and Editors

13.1.1 Problem

You want to create a plug-in that uses a wizard to create files and an editor to edit them.

13.1.2 Solution

Use a PDE Wizard template. Create a new plug-in project, select the "Plug-in with a multi-page editor" template, and follow the onscreen directions to create a skeletal template, ready to be customized.

13.1.3 Discussion

In this example, we're going to create a plug-in that Eclipse will associate with the file extension .new. The plug-in's wizard will enable the user to create files with this extension, and when the user double-clicks those files, they'll appear in the plug-in's editor.

The PDE can help us out here by creating a template for our plug-in. Select New Project. In the New Project dialog, select Plug-in Development in the left box and Plug-in Project in the right box, and click Next. Specify the name of the project as org.cookbook.ch13.EditorPlugIn in the following dialog, as shown in Figure 13-1.

Figure 13-1. Naming the plug-in
figs/ecb_1301.gif


Click Next once again to bring up the Plug-in Code Generators dialog shown in Figure 13-2. Select the "Plug-in with a multi-page editor" template, as shown in the figure, and click Next.

Figure 13-2. Creating a plug-in with a multipage editor
figs/ecb_1302.gif


In the next dialog, give the provider name as Eclipse Cookbook, as shown in Figure 13-3, and click Next.

Figure 13-3. Giving the provider name
figs/ecb_1303.gif


The following dialog enables you to give the extension you want to use for the files created by this plug-in; enter new here, as shown in Figure 13-4. Then click Next.

Figure 13-4. Configuring the plug-in's editor
figs/ecb_1304.gif


In the last dialog, shown in Figure 13-5, set the file extension to new, and enter document.new as the initial filename.

Figure 13-5. Configuring the wizard
figs/ecb_1305.gif


Finally, click Finish to create the code template for the plug-in. The following files are created by the PDE and added to the org.cookbook.ch13.EditorPlugIn project.

org.cookbook.ch13.EditorPlugIn
|
|_  _  _build.properties                          Controls the build script
|
|_  _  _plugin.xml                                Plug-in manifest
|
|_  _  _src                                       Source folder
    |
    |_  _org.cookbook.ch13.EditorPlugIn
    |   |_  _EditorPlugInPlugin.java            Plug-in's Java file
    |
    |_  _org.cookbook.ch13.EditorPlugIn.editors
    |   |_  _MultiPageEditor.java               Editor's code
    |   |_  _MultiPageEditorContributor.java    Editor actions
    |
    |_  _org.cookbook.ch13.EditorPlugIn.wizards
        |_  _SampleNewWizard.java               Wizard's code
        |_  _SampleNewWizardPage.java           Wizard's page

13.1.4 See Also

Recipe 13.2 on customizing a wizard; Recipe 13.3 on customizing editors; Chapter 12 of Eclipse (O'Reilly).

    Previous Section  < Day Day Up >  Next Section