< Day Day Up > |
Recipe 12.6 Writing a Plug-in from a Skeleton12.6.1 ProblemYou want to develop the code for a plug-in yourself, from scratch. 12.6.2 SolutionYou can create a skeletal plug-in project in the Plug-in Code Generators pane by selecting Default Plug-In Structure. We'll do that here and develop the rest of the plug-in from that starting point. 12.6.3 DiscussionAs an example, we'll create the plug-in created earlier in this chapter that displayed menus, but this time, we'll do the work ourselves instead of relying entirely on a wizard. We will use a wizard to get started, however, so select File 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. In the next pane, enter the new project's name, org.cookbook.ch12.MenuPlugInFromScratch, and click Next to open the Plug-in Project Structure pane. Click Next again to accept the defaults. In the Plug-in Code Generators pane, select Default Plug-In Structure, as shown in Figure 12-13, and click Next. Figure 12-13. Selecting a plug-in wizardThe next dialog enables you to set the provider name, which we'll set to Eclipse Cookbook. Because we'll be writing our own code here, uncheck the items in the "Plug-in code generation options" box, as shown in Figure 12-14, and click Finish. Figure 12-14. Setting the provider nameClicking Finish creates the MenuPlugInFromSratch plug-in, opening its manifest in Eclipse. Click the Source tab, which displays the XML in plugin.xml. That XML should look like this: <?xml version="1.0" encoding="UTF-8"?> <plugin id="org.cookbook.ch12.MenuPlugInFromScratch" name="MenuPlugInFromScratch Plug-in" version="1.0.0" provider-name="Eclipse Cookbook" class="org.cookbook.ch12.MenuPlugInFromScratch.MenuPlugInFromScratchPlugin"> <runtime> <library name="MenuPlugInFromScratch.jar"/> </runtime> <requires> <import plugin="org.eclipse.core.resources"/> <import plugin="org.eclipse.ui"/> </requires> </plugin> That's our new plug-in's manifest. Our goal in this plug-in is to add a new menu item and a button in the toolbar. To make things happen in a plug-in, you define actions and action sets. See the following recipe for further details. 12.6.4 See AlsoRecipe 12.2 on creating plugin.xml; Recipe 12.9 on creating an action set; Recipe 12.10 on coding an Eclipse action; Chapter 11 and Chapter 12 in Eclipse (O'Reilly). |
< Day Day Up > |