Example: Writing a German fragment for XYZ Plug-in

The PDE wizards and editors that manipulate plug-ins and fragments are nearly the same.  However, you must be aware of some important differences.

We start by creating a new fragment project.  

On the first page of the New Fragment Wizard, type the project name "com.example.german."  Press Next and accept the default values of the second page.  (Press Next again.)  On the "Fragment Code Generators" page, choose the radio button for creating a fragment from a template and select the "Default Fragment Generator" wizard.  After pressing Next, you should see the "Simple Fragment Content" page.

This page looks a little different from the plug-in wizard since it has two additional fields: target plug-in id and version. Since we are writing a fragment for a specific plug-in, we can use the Browse button to select "XYZ Plugin" from the "Workspace Plug-ins" group (we could also pick any of the external plug-ins).

Fragment example - sample fragment content page

Once the project is created, it opens the fragment manifest editor.

Fragment example - manifest overview

It is almost identical to plug-in manifest editor with the following exceptions:

  1. In the Overview page, the "class" attribute is gone.  Fragments do not have a plug-in class since they follow the life cycle of their target plug-in.  Instead, the target plug-in id and version fields are shown.
  2. A drop-down combo box allows precise definition of the plug-in reference (perfect, compatible, equivalent etc.).

We will add a similar action set as in the plug-in example, but this time in German.

  1. Go to  the Extensions page in the fragment manifest editor. Press Add to launch the Extension wizard.
  2. Select "Generic Wizards" and "Schema-based extension". Press Next.
  3. Select "Actions Sets" from the list of extension points. Press Finish.
  4. Select the new action set. Select New->actionSet from the popup menu.
  5. Move to the property sheet and change the label property to "Deutsche Aktionsmenge."
  6. Move to the "Extension Element Children" section and select New->menu from the popup.
  7. Change the label property of the menu to "Beispiel Menu" and the id property to "beispielMenu."
  8. Select the menu element again and choose New->separator from the popup menu. Change its name in properties to "beispielGruppe" and save it.
  9. Create a new "action" element (similar to step 6). Set the label property to "Beispiel Aktion." Set the menubarPath to "beispielMenu/beispielGruppe."
  10. Select the class property for editing and bring up the cell editor dialog. Select the "Generate a new class" radio button.
  11. Browse for the class container and select the "GERMAN Fragment" folder in the "com.example.german" project.
  12. Change the class name to "DeutscheBeispielAktion". Press Finish.
  13. When the Java editor with the new class opens, find the "run" method and add the following:
   System.out.println("Hallo, PDE welt!");

Save and close the Java editor and fragment manifest editor.

When you run the fragment using the "Run" tool bar button, the run-time platform instance should have the "Deutsche Aktionsmenge" action set available.  (Use Window->Customize Perspective...->Other to get to the list of action sets). When you activate the action set, the "Beispiel Menu" menu should appear on the tool bar. When you select its menu item, you should see "Hallo, PDE welt!" in the Console. The runtime platform didn't see the German fragment directly. Instead, its plug-in registry resolved fragment references in such a way that the fragment's action set appeared to the platform as though it came directly from the XYZ Plug-in.

 
Copyright IBM Corporation and others 2000, 2003