Sie sind auf Seite 1von 35

All rights reserved.

Reproduction and/or distribution in whole or in part in electronic, paper or other forms without written permission is prohibited.

Java ReferencePoint Suite


SkillSoft Corporation. (c) 2002. Copying Prohibited.

Reprinted for Balaji Nallathambi, Verizon Balaji@verizon.com Reprinted with permission as a subscription benefit of Books24x7, http://www.books24x7.com/

Table of Contents
Point 25: Creating Plugins using the Eclipse PDE......................................................................1 Introducing the Eclipse PDE ............................................................................................................2 Understanding the PDE Workbench.......................................................................................2 Understanding the Plugin Manifest Editor............................................................................2 . Understanding the Plugin.xml File..........................................................................................7 Creating a JDBCView Plugin Project............................................................................................8 Adding References to the JDBCView Plugin Project..........................................................12 Creating the JdbcView Class................................................................................................15 Configuring the Plugin.xml File for the JDBCView Plugin ...................................................20 Running the JDBCView Plugin...........................................................................................21 Creating a Button in Toolbar.........................................................................................................24 Creating the TestTool Class.................................................................................................25 Configuring the plugin.xml File for the Toolbar Project.........................................................28 Running the Toolbar Button Plugin.....................................................................................29 Related Topics................................................................................................................................33

Point 25: Creating Plugins using the Eclipse PDE


P. Surya The Plugin Development Environment (PDE) in Eclipse is a toolset, which allows you to create, test, debug, and deploy plugins. You can deploy these plugins in the Eclipse platform to extend the functionality of the platform. To create and deploy a plugin, you need to create a manifest file, write Java source code, compile the code into a library, and test and package the plugin. This ReferencePoint introduces the Eclipse PDE. It also describes how to create a view and a button plugin in the Eclipse PDE.

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Introducing the Eclipse PDE


The Eclipse PDE workbench integrates itself into the Eclipse workbench by providing tools, such as new perspectives, wizards and editors. As a result, you need not launch the Eclipse PDE separately. These tools enable you to develop and test plugins inside the Eclipse workbench.

Note

To learn more about the Eclipse workbench, see the Understanding Eclipse IDE ReferencePoint.

The Eclipse PDE enables you to create plugin projects. A plugin project contains folders and files, such as manifest file, Java code library, and properties files.

Understanding the PDE Workbench


The Eclipse PDE provides two instances of the Eclipse workbench, host instance, and runtime instance. You can use these workbench instances to develop, test, debug, and deploy the plugins that you build in your project. You can use the Eclipse PDE host workbench instance to develop plugins. The host workbench instance allows you to use plugins that are available in the Eclipse IDE. The Eclipse PDE provides a launcher to test your plugins. The launcher is a runtime workbench instance that runs independent of the Eclipse host workbench. The runtime workbench instance integrates the plugins you need to test with the features of the Eclipse PDE workbench allowing you to test the plugins in a realtime environment.

Understanding the Plugin Manifest Editor


The plugin Manifest Editor is a multipage UI editor in the Eclipse PDE. You can view the plugin Manifest Editor after creating a plugin project. The plugin Manifest Editor generates the plugin.xml file also called plugin manifest file, which describes its content to the Eclipse runtime. When you select the plugin.xml file, you can view the plugin Manifest Editor, which consists of pages, such as Overview, Dependencies, Runtime, Extensions, Extension Points, and Source. The Overview page of the plugin Manifest Editor provides you an outline view of the subsequent pages, as shown in Figure 2251:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

Figure 2251: The Overview Page of the Plugin Manifest Editor The Overview page displays the basic plugin information, such as plugin identifier, plugin name, version, and provider name. You can edit this information in the General Information section. You can only view the contents of other sections in the Overview page. The Dependencies page allows you to select a list of plugins that are required for your plugin to work. Figure 2252 shows the Dependencies page:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

Figure 2252: The Dependencies Page of the Plugin Manifest Editor The Runtime Information page helps you to add runtime libraries to your plugin. This page allows you to include library content, specify library type, and library exporting rules. Figure 2253 shows the Runtime Information page:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

Figure 2253: The Runtime Information Page of the Plugin Manifest Editor You can use the Extensions page to add extensions to your plugin. You can browse and edit plugin extensions using the Extensions page. The extensions serve as a key mechanism to extend the behavior of a plugin. Figure 2254 shows the Extensions page:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

Figure 2254: The Extensions Page of the Plugin Manifest Editor The Extension Points page allows you to define the extension points for a plugin. Other plugins can use this extension point to extend their operation. Figure 2255 shows the Extension Points page:

Figure 2255: The Extension Points Page of the Plugin Manifest Editor
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

The plugin Manifest Editor provides a Source page to edit the plugin code. Figure 2256 shows the Source page:

Figure 2256: The Source Page of the Plugin Manifest Editor

Understanding the Plugin.xml File


Each plugin contains a plugin manifest file or plugin.xml file in the Eclipse workbench. The plugin.xml file describes the properties of plugin, such as Plugin name, Plugin version, Plugin runtime JAR name, dependencies, and extensions to the Eclipse runtime. You can configure the information in the plugin.xml file using the Eclipse PDE. The plugin.xml file describes the plugin including the location of code and the extensions it is using.

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Creating a JDBCView Plugin Project


You can create a plugin project using the File menu or the New Wizard button on the toolbar located in the Eclipse workbench. For example, you can create a JDBCView plugin, which displays a user interface in the workbench. This interface is a view in the workbench that accepts values, such as JDBC driver, URL, user name, and password. You can extend this user interface to perform other functions, such as connecting to a database. To create the JDBCView plugin: 1. Select File>New>Project. The New Project dialog box appears. 2. Select the Plugin Development option in the left pane of the New Project dialog box and Plugin Project in the right pane, as shown in Figure 2257:

Figure 2257: The New Project Dialog Box 3. Click the Next button. The Plugin Project Name page of the New Plugin Project dialog box appears. 4. Specify a name for the project as JDBCView in the Project name text box.

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

Note Do not use spaces and special characters in the project name.

5. Clear the Use default check box and specify the directory where you want to save the project, as shown in Figure 2258:

Figure 2258: The Plugin Project Name Page of the New Plugin Project Dialog Box 6. Click the Next button. The Plugin Project Structure page appears. 7. Select the Create a Java project option and provide a value for output folder, plugin runtime library name and source folder, as shown in Figure 2259:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

10

Figure 2259: The Plugin Project Structure Page of the New Plugin Project Dialog Box 8. Click the Next button. The Plugin Code Generators page appears to define the plugin code generation options, as shown in Figure 22510:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

11

Figure 22510: The Plugin Code Generators Page of the New Plugin Project Dialog Box 9. Click the Finish button to create the project. The Plugin project is created by the Eclipse PDE with default values, as shown in Figure 22511:

Figure 22511: The Package Explorer with the Default Set of Configuration

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

12

Adding References to the JDBCView Plugin Project


The user interface components used in this example extend the Standard Widget Toolkit (SWT) user interface APIs that are available in the Eclipse project. You can import the org.eclipse.ui and the org.eclipse.core.boot packages, and other dependent packages, such as org.eclipse.core.resources and org.eclipse.help to the JDBCView plugin project. These packages provide the basic support for launching the Eclipse platform. To import the references: 1. Select File>Import. The Import wizard appears. 2. Select the External Plugins and Fragments from the available import source options, as shown in Figure 22512:

Figure 22512: The Import Wizard 3. Click the Next button. The Import External Plugins page of the Import Plugins and Fragments dialog box appears, as shown in Figure 22513:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

13

Figure 22513: The Import Plugins and Fragments Dialog Box 4. Click the Next button. The Selection page of the Import Plugins and Fragments dialog box appears. 5. Select org.eclipse.ui and org.eclipse.core.boot packages and other dependent packages. Figure 22514 shows the packages from which you can select:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

14

Figure 22514: The Selection Page of the Import Plugins and Fragments Dialog Box 6. Click Finish. The Package Explorer appears, as shown in Figure 22515:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

15

Figure 22515: The Package Explorer Dialog Box

Creating the JdbcView Class


You need to create the JdbcView class to display the fields, such as JDBC driver, URL, user name and password, which accept data from the end user. You can create the JdbcView class by extending the existing ViewPart class of the Eclipse PDE. To create the JdbcView class: 1. Right click the src folder in the JDBCView project and select New >Class option. The New Java Class dialog box appears. Type the class name as JdbcView in the Name field of the Java Class page, as shown in Figure 22516:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

16

Figure 22516: The New Java Class Dialog Box 2. Click the Browse button to select superclass for the JdbcView class. The Superclass Selection window appears, as shown in Figure 22517:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

17

Figure 22517: The Superclass Selection Window 3. The JdbcView class should extend the ViewPart class to implement a view. As a result, you need to select the ViewPart class as superclass and click OK. The New Java Class creation dialog box appears with the superclass name, as shown in Figure 22518:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

18

Figure 22518: The New Java Class Dialog Box for the JdbcView Class 4. Click Finish button. The Eclipse PDE generates code for the JdbcView class, which appears in the Source page of the plugin Manifest Editor.

Listing 2251 shows the JdbcView class with the generated code:
Listing 2251: The JdbcView Class

package jdbcview; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.part.ViewPart; /** * @author Xyz * * To change the template for this generated type comment go to * Window>Preferences>Java>Code Generation>Code and Comments */ public class JdbcView extends ViewPart { /* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ public void createPartControl(Composite parent) { // TODO Autogenerated method stub }
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

19

/* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchPart#setFocus() */ public void setFocus() { // TODO Autogenerated method stub } }

In the above code, by default the ViewPart class inherits the methods createPartControl() and the setFocus() from the IViewPart class, which defines the interface for views. You can write the implementation of the JdbcView class by including the logic for these methods. Listing 2252 shows the modified version of the JdbcView class:
Listing 2252: The Modified JdbcView Class

/* * Created on Aug 29, 2003 * This class helps in creating a new view that help * in configuring the JDBC properties. This Class is * an example for creating the User Interface only. * You can extend the functionality according to your * requirements. * */ package jdbcview; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.part.ViewPart; /** * @author Xyz * * This class helps in displaying the view containing the labels * and text fields that accept JDBC properties. * */ public class JdbcView extends ViewPart { /* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite) */ Text driverTxt, urlTxt, userTxt, passTxt; Label driver,url,userName,password; /** * */ public JdbcView() { super(); // TODO Autogenerated constructor stub } public void createPartControl(Composite parent) { // TODO Autogenerated method stub GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; parent.setLayout(gridLayout); driver = new Label(parent, SWT.NONE); driver.setText("JDBC Driver"); driverTxt = new Text(parent,SWT.BORDER); url = new Label(parent, SWT.NONE); url.setText("URL"); urlTxt = new Text(parent,SWT.BORDER); userName = new Label(parent, SWT.NONE); userName.setText("User Name");
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

20

userTxt = new Text(parent,SWT.BORDER); password = new Label(parent, SWT.NONE); password.setText("Password"); passTxt = new Text(parent,SWT.BORDER); passTxt.setEchoChar('#'); GridData gridData = new GridData(); gridData.widthHint = 100; driver.setLayoutData(gridData); gridData = new GridData(); gridData.widthHint = 100; url.setLayoutData(gridData); gridData = new GridData(); gridData.widthHint = 100; userName.setLayoutData(gridData); gridData = new GridData(); gridData.widthHint = 100; password.setLayoutData(gridData); GridData gridData2 = new GridData(GridData.FILL_VERTICAL); gridData2.widthHint = 100; driverTxt.setLayoutData(gridData2); gridData2 = new GridData(GridData.FILL_VERTICAL); gridData2.widthHint = 100; urlTxt.setLayoutData(gridData2); gridData2 = new GridData(GridData.FILL_VERTICAL); gridData2.widthHint = 100; userTxt.setLayoutData(gridData2); gridData2 = new GridData(GridData.FILL_VERTICAL); gridData2.widthHint = 100; passTxt.setLayoutData(gridData2); } /* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchPart#setFocus() */ public void setFocus() { // TODO Autogenerated method stub } public void widgetSelected(SelectionEvent e) { } }

In the above code, you modify the method createPartControl() to add controls, such as Label, and TextField to accept the values, such as database URL, user name and password to connect to the database.

Configuring the Plugin.xml File for the JDBCView Plugin


You need to configure the plugin.xml file, after creating the JdbcView class. By default, the plugin.xml file would contain the information provided in the Listing 2253: Listing 2253: The plugin.xml File for the JdbcView Class
<?xml version="1.0" encoding="UTF8"?> <plugin id="JDBCView" name="JDBCView" version="1.0.0"> <runtime> <library name="JDBCView.jar"/> </runtime> </plugin>

The above code contains the plugin id, plugin name, and the runtime library name configured in it. You can use the extension tag to specify the JdbcView class in the plugin.xml file.
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

21

Listing 2254 shows the plugin.xml file with the JdbcView class configured in it: Listing 2254: Configured plugin.xml File for the JdbcView Class
<?xml version="1.0" encoding="UTF8"?> <plugin id="JDBCView" name="JDBCView" version="1.0.0"> <runtime> <library name="JDBCView.jar"/> </runtime> <requires> <import plugin="org.eclipse.ui"/> <import plugin="org.eclipse.core.runtime"/> </requires> <extension point="org.eclipse.ui.views"> <category name="JDBC Views" id="jdbc.views"/> <view class="jdbcview.JdbcView" category="jdbc.views" name ="JDBC View" id ="custom.jdbc.views"/> </extension> </plugin>

The above code contains the extension tag, which specifies that the plugin is an extension of org.eclipse.ui.views. The View tag specifies the name of the view and the class name of the view.

Running the JDBCView Plugin


You can invoke the JDBCView plugin from the Eclipse PDE and run on a separate Eclipse instance. To run the JDBCView plugin: 1. Click the Run button on the toolbar and select the Run As option, as shown in Figure 22519:

Figure 22519: The Runtime Workbench Option

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

22

2. Click Runtime Workbench, a new instance of Eclipse opens, as shown in Figure 22520:

Figure 22520: The New Eclipse Window 3. Select Window>Customize Perspective, the Customize Perspective dialog box appears. 4. Expand the Window>Show View option and select the JDBC View option in the Customize Perspective dialog box, as shown in Figure 22521:

Figure 22521: JDBC View Option

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

23

5. Click OK. The Eclipse window appears. Select the menu option Window> Show View>JDBC View option, as shown in Figure 22522:

Figure 22522: The Eclipse Window with the JDBC View Selected 6. Place the JDBC View in the Workspace, as shown in Figure 22523:

Figure 22523: The Eclipse Window with the JDBC View

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Creating a Button in Toolbar


You can create a new button as a plugin project and add this button to the toolbar. You can assign any action to the click event of this button. To create a Toolbar project: 1. Select the Plugin Project in the New Plugin Project dialog box. Click the Next button. The Plugin Project page of the New Plugin Project dialog box appears, as shown in the Figure 2258. 2. Specify a name for the project as com.test.toolbar in the Project name text box. 3. Clear the Use default check box and click the Browse button to select the folder where you want to save the project. 4. Click the Next button. The Plugin Project Structure page of the New Plugin Project appears, as shown in the Figure 2259. 5. Select the Create a Java project option and provide a value for output folder, plugin runtime library name, and source folder. 6. Click the Next button. The Plugin Code Generators page of the New Plugin Project dialog box appears, as shown in the Figure 22510. 7. Click the Finish button to create the Toolbar project. The Eclipse PDE creates the Toolbar project with default values, as shown in Figure 22524:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

25

Figure 22524: The Package Explorer with the Default Set of Configuration for the Toolbar Project 8. You can add the org.eclipse.ui, the org.eclipse.core.boot packages, and the dependencies to the Toolbar project to display the button in the toolbar.

Creating the TestTool Class


You can enable the button created in the toolbar to handle events. The click event of the button should invoke an action. For this you can create a TestToolAction class, which implements the IWorkbenchWindowActionDelegate interface. The TestToolAction class should override the methods of this interface. When the end user clicks the button, a popup message is displayed to the end user using the MessageDialog class. To create a TestToolAction class: 1. Right click the src folder in the project com.test.toolbar and select New > Class option. The New Java Class dialog appears. 2. Provide the class name as TestToolAction and click the Add button. The Implemented Interfaces Selection window for TestToolAction class appears, as shown in Figure 22525:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

26

Figure 22525: The Implemented Interfaces Selection Window 3. Select the IWorkbenchWindowActionDelegate interface and click OK. 4. Select the Constructors from superclass and Inherited abstract methods checkbox options in the New Java Class dialog box, as shown in Figure 22526:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

27

Figure 22526: The New Java Class Dialog Box for the Toolbar Project 5. Click Finish to create the TestToolAction class. The Eclipse PDE generates code for the TestToolAction class that appears in the source page of the plugin Manifest Editor.

You can add the default constructor and the inherited abstract methods, after creating the TestToolAction class. Listing 2255 shows the constructors and the inherited abstract methods included while creating the TestToolAction class:
Listing 2255: The TestToolAction Class

/* * Created on Sep 4, 2004 * * To change the template for this generated file go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */ package com.test.toolbar; import org.eclipse.jface.action.IAction; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkbenchWindowActionDelegate; /** * @author xyz * * To change the template for this generated type comment go to * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments */
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

28

public class TestToolAction implements IWorkbenchWindowActionDelegate { /** * */ public TestToolAction() { super(); // TODO Autogenerated constructor stub } /* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose() */ public void dispose() { // TODO Autogenerated method stub } /* (nonJavadoc) * @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWin */ public void init(IWorkbenchWindow window) { // TODO Autogenerated method stub } /* (nonJavadoc) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { // TODO Autogenerated method stub } /* (nonJavadoc) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IActio org.eclipse.jface.viewers.ISelection) */ public void selectionChanged(IAction action, ISelection selection) { // TODO Autogenerated method stub } }

In the above code, modify the run method to include the following line of code that displays the test message:
MessageDialog.openInformation(null, null,"Test ToolButton");

When you click the button in the toolbar, the screen displays this message. After modifying the run() method, it is necessary to update the plugin.xml file for the toolbar button.

Configuring the plugin.xml File for the Toolbar Project


You need to configure the plugin.xml file, after creating the Toolbar project to display the button in the toolbar. By default, the plugin.xml file would contain the information provided in the Listing 2256: Listing 2256: The plugin.xml File for the Toolbar Project
<?xml version="1.0" encoding="UTF8"?> <plugin id="com.test.toolbar" name="TestTool" version="1.0.0"> <runtime> <library name="toolbar.jar"/> </runtime> </plugin>

The above code shows the plugin id as com.test.toolbar, name as TestTool, and the runtime library name as toolbar.jar. You need to configure the plugin to add the button in the toolbar. The extension tag provides configuration information about plugin.
Reprinted for v697039, Verizon SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

29

Listing 2257 shows the plugin.xml configuration file that helps to display the button in the toolbar: Listing 2257: Configured plugin.xml File for the Toolbar Project
<?xml version="1.0" encoding="UTF8"?> <plugin id="com.test.toolbar" name="TestTool" version="1.0.0"> <runtime> <library name="toolbar.jar"/> </runtime> <requires> <import plugin="org.eclipse.ui"/> </requires> <extension point="org.eclipse.ui.actionSets"> <actionSet id="com.test.toolbar.actionSet" label="TestToolButton"> <action id="com.test.toolbar.TestToolAction" label="TestTool" toolbarPath="TestToolGroup" class="com.test.toolbar.TestToolAction"> </action> </actionSet> </extension> </plugin>

In the above code, the extension tag specifies the action name, the button name, and the toolbar path. After configuring the plugin.xml file, you can test the plugin by running it in the workbench.

Running the Toolbar Button Plugin


You can invoke the Toolbar button plugin from the Eclipse PDE that run on a separate Eclipse instance. To run the Toolbar button plugin: 1. Click the Run option from the toolbar and select the Run As> Runtime Workbench option. A new workbench appears. 2. Select Window>Customize Perspective option, the Customize Perspective window appears. 3. Expand the Other option and select the TestToolButton option, as shown in Figure 22527:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

30

Figure 22527: The Customize Perspective Dialog Box 4. Click OK to save the changes. The toolbar in the workbench contains a red button, as shown in Figure 22528:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

31

Figure 22528: The Eclipse Window with Red Button Displayed 5. Click the red button in the toolbar, a dialog box appears, as shown in Figure 22529:

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Java ReferencePoint Suite

32

Figure 22529: A Dialog Box with Test Message 6. Click OK to close the dialog box.

The Eclipse PDE places the TestToolButton in the toolbar and adds the action to work accordingly.

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Related Topics
For related information on this topic, you can refer to: Understanding Eclipse IDE Using the Java plugin Understanding Classes and Objects in Java

Reprinted for v697039, Verizon

SkillSoft, SkillSoft Corporation (c) 2002, Copying Prohibited

Das könnte Ihnen auch gefallen