WTP Tutorials - Developing the WTP with Eclipse
WTP Tutorials - Developing the WTP with Eclipse
 

By Mark Hutchinson, IBM
February 21, 2005
Updated on June 2, 2006

 

This tutorial shows you how to set up your Eclipse environment to develop or modify the Web Tools Platform (WTP) project plug-ins. First we will discuss how to connect to the CVS repository to check out the WTP source code. We will then set up our target platform. Next we will make a modification to the WTP source and run our eclipse application. Finally, we will create a patch for our change, which we could submit to the WTP project.

 
Checking Out the Source Code
 
  1. Access the source code for the Eclipse Web Tools Platform from the Concurrent Versions System (CVS) repository. To access the CVS repository select Window > Open Perspective > Other and select CVS Repository Exploring.

  2. The CVS Repositories view is now on the left side of your screen. Select the Add CVS Repository icon Add Repository Icon and in the Add CVS repository dialog enter the following values:
    Host: dev.eclipse.org
    Repository Path: /cvsroot/webtools
    User: anonymous
    Select finish.
    Add CVS Repository

  3. Navigate through the folders and find the plug-ins that you are interested in having the source for. The most recent code is in HEAD. The Web Standards Tools plug-ins are found in the wst folder, and the J2EE Standard Tools plug-ins are found in the jst folder. For this tutorial we will modify HEAD/wst/components/xml/plugins/org.eclipse.wst.xml.ui

  4. Add the source into your local workspace by right clicking on that plug-in and selecting "Check Out".
    check out source code

  5. Switch back to the Java perspective. The source code for the plug-in you downloaded is now in your workspace.
 
Setting up the Target Platform
 

The target platform specified contains the eclipse plug-ins which your code will be compiled against. Having a target platform allows you to compile and run your modified code without having to bring all of the source code into your development workbench. The target platform should be the same platform you are developing for.

 

To set up your target platform:

 
  1. Download and install the desired Eclipse and WTP versions in a separate folder from your current development Eclipse platform. Ensure that this new platform runs. This will be your target platform.

  2. From your development workbench select Window > Preferences > Plug-in development > Target Platform.

  3. Enter the location of the platform you wish to target.

    target platform preferences
 
Modifying the Source Code
 

As an example, we are going to add to the pop-up menu shown when the user right clicks on an XML file in the Navigator view. First we need to add to the plugin.xml file

 
  1. In the Java perspective, open the plugin.xml file for the org.eclipse.wst.xml.ui plug-in you just checked out.

  2. Add the following to the plugin.properties file. This will be the text of the label that appears in your new pop-up menu.
    #Label to be added to the pop-up menu
    SHOW_MESSAGE_DIALOG_LABEL = Show a Message Dialog
    

  3. Add the following to the source of plugin.xml:
    <!--  =============================================================================== --> 
    <!--                                 My Popup Menu                                    --> 
    <!--  =============================================================================== -->
    <extension point="org.eclipse.ui.popupMenus">
    	 <objectContribution 
    	 	objectClass="org.eclipse.core.resources.IFile" 
    	 	nameFilter="*.xml" 
    	 	id="org.eclipse.wst.xml.ui.actions">	
    	  	<action 
    	  		label="%SHOW_MESSAGE_DIALOG_LABEL" 
    	  		class="org.eclipse.wst.xml.ui.internal.actions.MyMessageDialog" 
    	  		menubarPath="My Menu" 
    	  		enablesFor="1" 
    	  		id="org.eclipse.wst.xml.ui.actions.PopUp" /> 
    	  </objectContribution>
      </extension>
    			
  4. In the package Explorer expand "src" and right click on org.eclipse.wxt.xml.ui.actions and select new class. Name this class MyMessageDialog.

  5. Add this source code to MyMessageDialog.java:
    package org.eclipse.wst.xml.ui.internal.actions;
    
    import org.eclipse.jface.action.IAction;
    import org.eclipse.jface.dialogs.MessageDialog;
    import org.eclipse.swt.widgets.Shell;
    import org.eclipse.ui.actions.ActionDelegate;
    import org.eclipse.wst.xml.ui.internal.XMLUIPlugin;
    
    public class MyMessageDialog extends ActionDelegate {
    	public void run(IAction action) {
    		MessageDialog message;
    		Shell shell = XMLUIPlugin.getInstance().getWorkbench()
    				.getActiveWorkbenchWindow().getShell();
    		String labels[] = new String[1];
    		labels[0] = "OK";
    		message = new MessageDialog(shell, "My Message Dialog", null,
    				"I have modified eclipse!", 2, labels, 1);
    		message.open();
    	}
    }
    			
Running Your Eclipse Application
 
  1. In the Java perspective from the menu bar select Run > Run.

  2. In the Run dialog select the Eclipse Application option, then select new.

  3. Enter the location of the desired workspace, and select Run.
    run
 

When this version of Eclipse is run it compiles the source code in your workspace, and runs from your target platform. A second instance of Eclipse is now running and you are now able to test any code modifications you have made.

 

Now test out your modification:

 
  1. We need a project in the navigator to test this on. Select File > New > Example > Editing and Validating XML Files.

  2. Right click on any XML file, for example Invoice.xml. Notice that the new option "Show Message Dialog" has been added to this menu.
    menu

  3. Select "Show a Message Dialog." A message dialog appears.
    My Message Dialog
 
Creating a Patch for your Modification
 

To contribute an enhancement to WTP, you can submit your code changes as a patch.

 
  1. In the Package Explorer view, right click on the modified plug-in project and select Team > Create Patch.
    select Team > Create Patch

  2. Select "Save in File System" and enter the file name. Select Next.
    Create Patch

  3. Ensure the Diff Output Format is set to "unified." Select Finish.

  4. The patch has been saved to your file system. If this were an actual feature enhancement the patch could be submitted to the webtools project using Bugzilla
 
Summary
 

In this tutorial you learned how to set up your Eclipse environment to get started developing Web Tools Platform plug-ins by creating a simple addition to the user interface.