Extending the Wizards in Java

It is possible to create new Wizard pages, custom widgets or add new template variables by extending the wizards in Java.

Creating Wizard Pages

Defining a wizard page in Java requires that you install the Eclipse Plug-in Development Environment (PDE) and that you have some Eclipse development skills.

The template.properties key for denoting a Java-based wizard page is page.<NN>.class, and the value should be the fully qualified name of the Java class that implements the wizard page. The requirements for the class are:

  • the class must be accessible to the class loader,
  • the class must extend org.omnetpp.common.wizard.ICustomWizardPage, and
  • the class must have a public constructor with the following argument list: (String name, IContentTemplate creatorTemplate, String condition)

Creating Custom Widgets

Since XSWT works via Java reflection, your own custom widgets can be used in forms, similar to normal SWT widgets. No glue or registration code is needed; simply add their package to the <import> tags at the top of the XSWT file.

However, some Java code is needed so that the wizard knows how to write template variables into your widgets and how to extract them after editing. This functionality can be added via the org.omnetpp.common.wizard.IWidgetAdapter interface. This interface must be implemented either by the widget class itself, or by a class named <widgetclass>Adapter in the same package. The interface has methods to tell whether the adapter supports a given widget, to read the value out of the widget, and to write a value into the widget.

In addition to basic data types (Boolean, Integer, Double, String, etc.), it is possible to use compound data types as well (i.e. those composed of the List and Map interfaces of the Java Collections API). The default values can be given in the template.properties file in the JSON notation and the result can be used in the templates (iteration via <#list>, etc.).

Extending your Template with Custom Classes and Widgets

Jar files placed into the plugins/ subdirectory of an OMNeT++ project will be loaded automatically and will be available to all templates. Jar files in that directory may be plain Java jars and Eclipse plug-in jars (the latter makes it also possible to contribute new functionality into the IDE via various extension points, but this is outside the scope of this discussion about wizards).

Jar files placed in the folder of the template will be loaded automatically when the template is used and the classes in it will be available for that template. Custom SWT widget classes can be imported and used in XSWT forms, and other code can be used in the template files via the FreeMarker Bean Wrapper (e.g. ${classes["org.example.SomeClass"].someStaticMethod(...)}, see the example wizards.) Like .xswt files and template.properties, jar files are not copied over into the destination folder when the wizard executes.

Extending the Template Processing

If you are skilled in writing Eclipse plug-ins, there are ways you can extend content templates. One is to contribute to the org.omnetpp.common.wizard.templatecontributor extension point, which lets you supply IContentTemplateContributor objects that can extend the content template implementation in various ways. You can contribute new variables, functions or macros to the template context.