How to create, debug and install plugins
Level: primary
David Gallardo (David@gallardo.org) Software Consultant March 2003
In this article, David Gallardo shows you how to create an Eclipse plugin with the Code Generation Wizard of Plug-In Development Environment. You will learn how to run and debug plugins in the runtime workshop, and install the completed plugins in Eclipse. David also studies issues related to packaging plug-ins - included maintenance version information, updating features in the form of plugins, and combined plugins to create a complete feature.
Plug-in-based architecture Eclipse platform is the development framework for IBM donated to the development source community. It is not because IBM claims to invest in total funds - $ 40 million - but because of such a huge investment. : A mature, carefully designed and scalable architecture. The value of Eclipse is that it provides an open source platform for the creation of an extensible integrated development environment. This platform allows anyone to build tools for seamless integration with environment and other tools.
The key to the seamless integration of tools and eclipse is plugin. In addition to small runtime kernels, all things in Eclipse are plugins. From this perspective, all features are created in equally. From this perspective, all features are created in equally.
However, some plugins are more important than other plugins. Workbench and Workspace are two essential plugins for the Eclipse platform - they provide extensions used by most plugins, as shown in Figure 1. The plugin requires an extended point to insert so that it can run.
Figure 1. Eclipse Workbench and Workspace: Essential Plugin Support
The Workbench component contains some extensions, for example, allowing your plugin to extend the Eclipse user interface, making these user interfaces with menu selection and toolbar buttons; request notifications for different types of events; and create a new view. The Workspace component contains an extension point that allows you to interact with resources (including projects and files).
Of course, other plugins can extend the Eclipse components that do not have Workbench and Workspace. In addition, there is a Debug component that allows your plug-in to launch programs, interacting with running programs, and handling errors - this is necessary to build a debugger. Although Debug Components is required for certain types of applications, most applications don't need it.
There is also a Team component that allows the Eclipse resource and version control system (VCS) interaction, unless you are building a VCS's Eclipse client, otherwise the Team component is like the Debug component, does not expand or enhance its functionality.
Finally, there is a HELP component that allows you to provide an online documentation and help with context. No one will deny the help documentation is a must-have part of the professional application, but it is not the necessary part of the plug-in function.
The extended points provided by each of the above components are recorded in the Eclipse Platform Help, which helps in the reference section of the Platform Plug-in Developer Guide. At first glance, especially the API refers to the entire Workbench section, it will be expected at the beginning. We don't know more about the details of many available extensions, but just a simple plug-in and their components.
Introduction to Introduction to Creating Plugins is to use Plug-in Development Environment (PDE). PDE and Java Development Tooling (JDT) IDE are standard extensions for Eclipse. PDE provides some wizard to help create a plugin, including the "Hello, World" example we will study here. From the Eclipse menu, select File => New => Other (or press Ctrl-N), then select the Plug-In Development Wizard left on the SELECT dialog. On the right side of the SELECT dialog, select Plug-in Project. Press NEXT. On the next screen, enter the project name; I used com.example.hello. Press NEXT again. On the next screen, please note that the plugin identifier is the same as the project name. Use the project name as a plug-in to minimize the chance of conflicting the plugin with the name of the other plugin. Press again again. The next screen lets you choose to manually create an initial plugin code, or run the code generation wizard. Keep the default option of the code generation wizard, select "Hello, World", then press Next, as shown in Figure 2.
Figure 2. Select "Hello, World" Code Generation Wizard
The next screen requires some additional information. Note the information on this screen: it contains the plugin name, version number, provider name, and class name. These are important information about plug-ins, we will study later. You can accept the default value provided by the wizard. Press NEXT. On the next screen, accept the default value of the package, class name, and message text. Select the "Add The Action Set To The Resource Perspective" checkbox. Press Finish.
If you receive a notification: The wizard needs to enable some other plugins to complete, then press OK.
After a while, the wizard will be completed, and there will be a new project in your work area, named Com.example.Hello, as shown in Figure 3.
Figure 3. PDE perspective: Welcome to Hello Plug-in
In Package Explorer, the left side of the workbench is an overview of some things created by the wizard. Most of them are not persistent: including many .jar files in the project class path (these Eclipse classes needed when plugins and Java runts), an icon folder (including graphics of the toolbar button), and build .properties file (contains the variables used automatically built scripts).
The most interesting thing here is the SRC folder, which contains the source code for plugins and plugin.xml files - Plug-in.xml is a plus file for plugins. We will first look at Plugin.xml.
Plug-in list file plug-in file PLUGIN.XML contains Eclipse to integrate plugins into the description information used by the frame. By default, when the plugin is created for the first time, PLUGIN.XML will be opened in the list editor area. The tab at the bottom of the editor allows you to choose the different information collections about the plugin. The Welcome tab displays the message "Welcome to Hello Plug-IN" and briefly discusses the templates used and prompts for the use of Eclipse implementation plugins. Choosing the Source tab allows you to view the full source code of the Plugin.xml file.
Let us look at the various parts of the plug-in list file. The first is the general information about the plugin, including its name, version number, the name of its class file, and .jar file name.
Listing 1. Plug-in list file - General information
xmlversion = "1.0" eNCoding = "UTF-8"?> ID = "com.example.hello" Name = "Hello Plug-in" Version = "1.0.0" Provider-name = "example" Class = "com.example.hello.helloplugin"> runtime> Then, the plugins needed for our plug-in: Listing 2. Plug-in list file - required plugin requires> The first plugin listed org.eclipse.core.resources is a workspace plugin, but in fact our plugin does not need it. The second plugin org.eclipse.ui is a workbench. We need a table plug-in because we will extend its two extensions, as indicated by the following Extension tag. The first extension tag ownership attribute org.eclipse.ui.actionSets. The set of operations is a group of base values added to the table user interface - ie, menu, menu items, and toolbar. The set group is packetized, so that users can manage them more easily. For example, our Hello plug-in menu and toolbar items will appear in the Resource perspective, because when we do this when running the code generation wizard, we have made this option. If the user wants to change it, you can use the Window => Customize Perspective menu option to remove "Sample Action Set" from the item to be displayed in the Resource perspective. Figure 4. Customized Resource perspective The operation set contains two tags: MENU tag (where the menu item should appear in the table menu, and how to appear) and the action tag (describe what it should do) - especially the Action tag identifies the class of the execution operation. Note: This class is not the plugin class listed above. Listing 3. Operation collection Point = "org.eclipse.ui.actionsets"> Label = "Sample Action SET" Visible = "True" ID = "com.example.hello.action set">