Creating a custom HTML widget

ZIETrans provides a Create Widget wizard to help you create custom widgets. You can start the wizard in several ways:
  • From the File > New > ZIETrans Widget menu in ZIETrans Toolkit
  • From the ZIETrans > New > Widget menu in ZIETrans Toolkit
  • From the context (right click) menu of a ZIETrans project, select New ZIETrans > Widget

There are two panels in the Create Widget wizard. On the first panel, you provide the name of the project, the name of the new widget, and the name of the Java™ package for the widget. Optionally, you can select a check box to include stub methods that allow you to define a GUI panel for configuring the settings used by the new widget (see ZIETrans Toolkit support for custom component and widget settings for more information). On the second panel, enter the name you want displayed for the new widget in the ZIETrans Toolkit and select the components to associate with the widget.

The wizard provides the following required elements of a custom widget:
  • Extends the widget abstract class and implements the HTMLRenderer interface: public class MyCustomWidget extends Widget implements HTMLRenderer.

    See Extending widget classes for more information.

  • Adds the constructor method:
    public MyCustomWidget(ComponentElement[] arg0, Properties arg1) {
    		super(arg0, arg1);
  • Adds the following method to generate HTML for Web project output.
    public StringBuffer drawHTML() {
     		StringBuffer buffer = new StringBuffer(256);
     		HTMLElementFactory factory = HTMLElementFactory.newInstance(
     				contextAttributes, settings);
     		return (buffer);

    The HTMLElementFactory class automatically generates any JavaScript needed to present the widget. Refer to the ZIETrans API References (Javadoc) for detailed information about the HTMLElementFactory class and more examples of its use. See Using the API documentation (Javadoc).

  • Adds the source code for the widget into the Source folder of your project
  • Compiles the new widget .java file, if you have Build Automatically selected in the Rational® SDP workbench preferences (Window > Preferences > General > Workspace) or the Project menu. If the widget is not compiled into a .class file, it is not available for use in the ZIETrans Toolkit.
  • Registers the new widget in the ComponentWidget.xml file. See Registering your component or widget for more information about registering widgets.
If you selected the check box to include ZIETrans Toolkit graphical user interface support methods, enabling you to modify the settings of the widget, the Create Widget wizard adds the following methods:
  • Method to return the number of pages in the property settings:
    public int getPropertyPageCount() {
    		return (1);
  • Method to return the settings that can be customized:
    public Vector getCustomProperties(int iPageNumber, Properties properties,
    			ResourceBundle bundle) {
    		return (null);
  • Method to return the default values of the settings that can be customized:
    public Properties getDefaultValues(int iPageNumber) {
    		return (super.getDefaultValues(iPageNumber));

See ZIETrans Toolkit support for custom component and widget settings for more information about the methods necessary to support your custom widget.