blob: a7d20d3ff96fdca770ffa625dd074c98490dc7e1 [file] [log] [blame]
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../../../wtp.xsl"?>
<html>
<head>
<meta name="root" content="../../../../" />
<title>WTP Tutorials - Developing the WTP with Eclipse</title>
</head>
<body>
<h1>WTP Tutorials - Developing the WTP with Eclipse</h1>
<p>
<b>By Mark Hutchinson, IBM</b>
<BR />
February 21, 2005
<BR />
Updated on June 2, 2006
<BR /><BR/>
</p>
<p>
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.
</p>
<br/>
<h2>Checking Out the Source Code</h2>
<ol>
<li>
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.
<br/><br/></li>
<li>
The CVS Repositories view is now on the left side of your
screen. Select the Add CVS Repository icon
<img src="images/addrepositoryicon.gif" alt="Add Repository Icon"
width="25" heigt="23" border="0" />
and in the Add CVS repository dialog enter the following values:
<br />
<b>Host:</b>
dev.eclipse.org
<br />
<b>Repository Path:</b>
/cvsroot/webtools
<br />
<b>User:</b>
anonymous
<br />
Select finish.
<br />
<img src="images/addrepository.gif" width="438" height="542"
border="0" alt="Add CVS Repository" />
<br />
<br />
</li>
<li>
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
<a href="http://www.eclipse.org/webtools/wst/main.html">Web Standards Tools</a>
plug-ins are found in the wst folder, and the
<a href="http://www.eclipse.org/webtools/jst/main.html">J2EE Standard Tools</a>
plug-ins are found in the jst folder. For this tutorial we will modify
<b>HEAD/wst/components/xml/plugins/org.eclipse.wst.xml.ui</b>
<br/><br/></li>
<li>
Add the source into your local workspace by right clicking
on that plug-in and selecting "Check Out".
<br />
<img src="images/repositories.gif" alt="check out source code"
width="487" height="689" border="0" />
<br />
<br />
</li>
<li>
Switch back to the Java perspective. The source code for the
plug-in you downloaded is now in your workspace.
</li>
</ol>
<br/>
<h2>Setting up the Target Platform</h2>
<p>
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.
</p>
<p>To set up your target platform:</p>
<ol>
<li>
<a href="http://download.eclipse.org/webtools/downloads/">Download</a>
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.
<br/><br/></li>
<li>
From your development workbench select Window > Preferences
> Plug-in development > Target Platform.
<br/><br/></li>
<li>
Enter the location of the platform you wish to target.
<br/><br/>
<img src="images/targetplatform.gif"
alt="target platform preferences" width="686" height="560"
border="0" />
</li>
</ol>
<br/>
<h2>Modifying the Source Code</h2>
<p>
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
</p>
<ol>
<li>
In the Java perspective, open the plugin.xml file for the
org.eclipse.wst.xml.ui plug-in you just checked out.
<br/><br/></li>
<li>Add the following to the plugin.properties file. This will be the
text of the label that appears in your new pop-up menu.
<pre>
#Label to be added to the pop-up menu
SHOW_MESSAGE_DIALOG_LABEL = Show a Message Dialog
</pre><br/></li>
<li>
Add the following to the source of plugin.xml:
<pre>
&lt;!-- =============================================================================== --&gt;
&lt;!-- My Popup Menu --&gt;
&lt;!-- =============================================================================== --&gt;
&lt;extension point="org.eclipse.ui.popupMenus"&gt;
&lt;objectContribution
objectClass="org.eclipse.core.resources.IFile"
nameFilter="*.xml"
id="org.eclipse.wst.xml.ui.actions"&gt;
&lt;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" /&gt;
&lt;/objectContribution&gt;
&lt;/extension&gt;
</pre>
</li>
<li>
In the package Explorer expand "src" and right click on
org.eclipse.wxt.xml.ui.actions and select new class.
Name this class MyMessageDialog.
<br/><br/></li>
<li>
Add this source code to MyMessageDialog.java:
<pre>
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();
}
}
</pre>
</li>
</ol>
<h2>Running Your Eclipse Application</h2>
<ol>
<li>
In the Java perspective from the menu bar select Run > Run.
<br/><br/></li>
<li>
In the Run dialog select the Eclipse Application option,
then select new.
<br/><br/></li>
<li>
Enter the location of the desired workspace, and select Run.
<br />
<img src="images/run.gif" alt="run" width="800" height="600"
border="0" />
</li>
</ol>
<p>
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.
</p>
<p>Now test out your modification:</p>
<ol start="4">
<li>
We need a project in the navigator to test this on. Select
File > New > Example > Editing and Validating XML Files.
<br/><br/></li>
<li>
Right click on any XML file, for example Invoice.xml. Notice
that the new option "Show Message Dialog" has been
added to this menu.
<br />
<img src="images/menu.gif" alt="menu" border="0" width="370"
height="663" />
<br />
<br />
</li>
<li>
Select "Show a Message Dialog." A message dialog appears.
<br />
<img src="images/dialog.gif" alt="My Message Dialog" border="0"
width="444" height="142" />
</li>
</ol>
<br/>
<h2>Creating a Patch for your Modification</h2>
<p>
To contribute an enhancement to WTP, you can submit
your code changes as a patch.
</p>
<ol>
<li>In the Package Explorer view, right click on the modified plug-in
project and select Team > Create Patch.
<br/>
<img src="images/createpatchmenu.gif" alt="select Team > Create Patch" width="818" height="735"/>
<br/><br/>
</li>
<li>Select "Save in File System" and enter the file name. Select Next.
<br/>
<img src="images/createpatch.gif" alt="Create Patch" border="0" width="543" height="543"/>
<br/><br/>
</li>
<li>Ensure the Diff Output Format is set to "unified." Select Finish.<br/><br/></li>
<li>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
<a href="https://bugs.eclipse.org/bugs/">
Bugzilla
</a>
</li>
</ol>
<br/>
<h2>Summary</h2>
<p>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.
</p>
<p></p><p></p>
</body>
</html>