This page last changed on Nov 08, 2005 by jgarnett.

We have been able to make the following plug-in tutorial available:

The tutorial is in the form of a Adobe PDF file, if you have time help us convert this tutorial to confluence!
This tutorial was also coverted in the uDig presentation at OSG'05.

Distance Tool Tutorial

Create your first uDig plug-in! (Featured at OSG'05 conference)

Goals

After completing this tutorial, you will have gained the skills to:

  • Create a new Plugin
  • Define a new Extension
  • Implement a new Tool Extension
  • Update the user interface from within a tool

Create a New Plugin

  1. Open the Plug-in Development perspective.
  2. From the File menu, select New > Project…. Select Plug-in Project from the dialog, and then click the Next button.

    Figure 1 - New Plug-in Project
  3. Create a name for the plug-in by entering net.refractions.udig.tutorials.distancetool in the Project Name text field and click the Next button.

    Figure 2 - Naming the New Plug-in
  4. Accept the default values used to generate the plug-in and click the Finish button.

    Figure 3 - New Plug-in Details
    At this point the feature editor plug-in is created. Configuring the plug-in is the focus of the next section.

Configuring Your New Plug-in

In this section you will configure the feature editor plug-in. Specifically, you will specify dependencies on other plug-ins in order to create a new feature editor.

  1. Open the Plug-in Development perspective.
  2. In the Package Explorer navigate to the plug-in created in the previous section. Open the plug-in manifest by navigating to the META-INF/MANIFEST.MF file under the root of the feature editor plug-in. Double click on the file to open the plug-in manifest editor.

    Figure 4 - Plug-in Manifest Editor
  3. Open the plug-in dependencies by clicking on the Dependencies tab located at the bottom of the editor area.
  4. Click the Add… button in the Required plugins column and add the following plugin:
    net.refractions.udig.project.ui

    Figure 5 - Add New Plugin Dependencies
  5. At this point it is critical that you save your work as the dependencies need to propagate into the project.

    Figure 6 - Plug-in Dependencies

Import Resources Into Project

In this section we are going to set up an icon directory and import the pictures we will use for our measure tool.

  1. Download measure_source.gif and measure_mode.gif to your desktop (Right click and Save Link As...)
  2. Select your plug-in project, net.refractions.udig.tutorials.distancetool, in the Package Explorer.
  3. Select File → New → Folder from the Menubar.
  4. Enter icons/etool16 as the folder name.
  5. Click the Finish button.
  6. Select icons directory.
  7. Select File → New → Folder from the Menubar.
  8. Enter pointers as the folder name.
  9. Click the Finish button.
  10. Right click on etool16 and select Import.
  11. Select File System.
  12. Click on browse and choose Desktop from the list (this will populate the directory field).
  13. Select the measure_mode.gif file and press Finish.
  14. Import the measure_source.gif file into the pointers directory following the same steps.

Define a New Extention

  1. Open the extensions page by clicking on the Extensions tab
  2. Click the Add… button
  3. Select the net.refractions.udig.project.ui.tool extension point from the list.
  4. Click the Finish button.
  5. Select net.refractions.udig.project.ui.tool Enter the following Extention Details:
    • ID: net.refractions.udig.tutorial.distancetool
    • Name: Distance Tool Example

Create a New Tool

  1. Right click on newly added extension, net.refractions.udig.project.ui.tool, and select New > modalTool
  2. Replace the default data in the id field with net.refractions.udig.tutorial.distancetool.
  3. Enter a tool tip message into the tooltip field: Measure the surface distance between two points
  4. Enter net.refractions.udig.tutorial.distancetool.DistanceTool into the class field.
    11. Enter icons/etool16/measure_mode.gif into the icon field.
    a. Or press the Browse button and locate the icon.
    12. Enter Distance into the name field.
    13. Set onToolbar to true.
    14. Enter net.refractions.udig.tool.category.info into the categoryId field.

Figure 12 - Completed Modal Tool Definition
15. Right click on net.refractions.udig.tutorial.distancetool (modalTool) and select New → cursor.
16. Enter icons/pointers/measure_source.gif in the image field.
b. Or press the browse button and find the pointer icon.
17. Enter 10 in the hotSpotX field.
18. Enter 10 in the hotSpotY field.

Figure 13 - Tool Cursor Definition

The file tutorials\day\DistanceTool\sources\plugin.zip contains the plugin you are creating at this stage of development. You can compare the work you have done with the plugin provided if you are having problems.


1NewProject.png (image/png)
1NewProject.png (image/png)
2NewPluginProject.png (image/png)
3NewPluginContent.png (image/png)
4PluginManifest.png (image/png)
5PluginDependencies.png (image/png)
5PluginDependencies.png (image/png)
6AddDependencies.png (image/png)
6AddDependencies.png (image/png)
measure_mode.gif (image/gif)
measure_source.gif (image/gif)
7NewFolder.png (image/png)
8Import.png (image/png)
9ImportToolIcon.png (image/png)
11NewExtention.png (image/png)
11NewExtention.png (image/png)
12ExtentionDetails.png (image/png)
12ExtentionDetails.png (image/png)
Document generated by Confluence on Nov 19, 2005 20:03