Creating the plug-in
Let's start the process rolling by using the Eclipse Plug-in wizard to define a plug-in.
Start Eclipse and define your project
Start Eclipse and choose File > New > Project.
On the New Project screen, select the Plug-in Development folder and choose Plug-in Project, as shown in Figure 1.
Figure 1. Selecting the Plug-in Project wizard
On the New Plug-In Project screen (see Figure 2), enter the name of your plug-in. Because this is a shootout game, use com.devworks.tutorial.shootout. Keep the default directory created by this name; it will be located under your workspace. Be sure the Create a Java Project box in Project Settings is checked, and keep the defaults of /src and /bin for the folder names. Finally, for your target platform, choose Eclipse V3.2.
Figure 2. Setting the project name and directories
Each plug-in is described by an XML manifest file called plugin.xml, which comes bundled with your package. The Plug-in Properties of this next screen (see Figure 3) save you from having to create this by hand -- always a nice thing to avoid. Leave the values as they are, but notice what kind of information the manifest provides: version, name, provider, etc.
On the Plug-in Options screen, ensure that the checkbox is selected for Generate an activator and that the class name is set to com.devworks.tutorial.shootout.ShootoutPlugin. Also make sure the checkbox is selected for This plug-in will make contributions to the UI.
Finally, answer No to the question of creating a rich client application. This is used to create a threadbare version of Eclipse that allows you to build an entire application on the Eclipse framework. You're just creating a single plug-in here.
Figure 3. Entering the plug-in properties that will be stored in the manifest
Choosing the template for the plug-in
The next screen of the wizard, shown in Figure 4, asks if you'd like to use a template. For your shootout game, you'll be creating a view, so select the checkbox Create a plug-in using one of the templates, then select the one labeled Plug-in with a view. As the text on the right panel of this figure explains, this template will give you the basic functionality of workbench view, including support for menus, tool bars, and so forth.
Figure 4. Selecting the plug-in with a view template
On this next screen, shown in Figure 5, you'll define various settings for your view. Again, in keeping with the shootout theme of the game, ensure that your View Class Name is ShootoutView and the View Name is Shootout View (note the space). Change the View Category name to Devworks Tutorial. This will keep things tidy later when you go to open your view in the Open View screen. Be sure Add the view to the resource perspective is checked so you can see it there. To start with, you'll be expanding on the basic Table Viewer model, so select the Table viewer as the type of viewer that should be hosted in this view.
Figure 5. Setting the view properties
Finally, on the last screen (see Figure 6), keep the default options (in this case, all features are chosen). Some of these will be used later, but all are instructive to see as you examine the code generated by the wizard.
Figure 6. Selecting the actions supported by the view
Finishing the wizard and examining the results
Click Finish, and Eclipse will ask if you want to switch to the perspective associated with the plug-in development. Say Yes, and it will generate the stub of your project and switch you to the appropriate perspective.
Your Eclipse desktop should now show you the plug-in view (see Figure 7). If you explore the com.devworks.tutorial.shootout package in the Package Explorer, you will see that the wizard has generated the two classes: ShootoutPlugin.java and ShootoutView.java. These match the names you chose in the wizard.
Figure 7. The plug-in perspective and generated classes
The ShootoutPlugin extends the AbstractUIPlugin defined by the Eclipse plug-in architecture and is the launching point for the behavior of your plug-in. The ShootoutView class extends the ViewPart abstract class and was created because you asked the wizard to provide a "Plug-in with a view." You will add your widgets and other visual elements to this class.
The wizard also generated the plugin.xml using the values you supplied on the appropriate screen. This is the manifest file that will be bundled with your final plug-in and is used to describe the package to Eclipse. Eclipse provides a nice set of tabular screens for editing the plug-in.xml, as seen in Figure 7. You can use this set of screens to adjust properties related to your plug-in -- specifically, dependencies on other plug-ins.



