Extend Table Column Widget

BTT provideds several default definitions for table column widget in XUI Editor. Besides, the widgets displayed in a table column, their properties and customized rules for JSP generation could also be extended through Eclipse extension points and BTT XML definitions.

Define Extension for Table Column Widget

If you need to customize table column widgets in your self-defined plug-in project, the prerequisite is to add plug-in ‘com.ibm.btt.tools.xui.editor2’ as the plug-in dependency.

To add a new widget into the widget selection list of a table column, firstly you need to declare an Eclipse extension for the extension point 'com.ibm.btt.tools.xui.editor2.widgets'.

Then, right click the newly added extension and choose to add a child option from the context menu. If you need to define a common XUI widget which could also be used as a table column widget, you should choose the option ‘widget’; otherwise, you should choose the option ‘internalWidget’ which means the extended widget is only for table column. See the picture above.

Then, move to its details panel to fill in the required attributes (name, label, icon and config) for the widget register. For the attribute ‘conifg’, you should choose or specify a relative path of the widget definition file. See the picture above. Later, you will take steps to create a XML file to describe this widget.

Configure Detailed Definition for Table Column Widget

In XUI Editor, users could follow the same style to describe a column widget just like common widget definition. For facility in this extension sample, we have copied the xml definition file of link widget (Link.xml) in BTT product and make some modification on it on below steps:
  •  Rename the file with ‘ColumnLink.xml’ and put it into the folder ‘widgets’.
  •  Remove the ‘functions’ and ‘events’ sections from the xml file.
  •  Add a tag named ‘columnWidget’ to indicate this widget will be used for table column
    <columnWidget editable="false"/>
    The details of available attributes for tag ‘columnWidget’ are listed in below table.
    Table 1. table 1
    Attribute Description
    name The attribute to identify the column widget. It is optional and the widget name registered in extended plug-in will be used if this attribute is not defined.
    editable The available values are ‘true’ and ‘false’ which indicate whether the widget could be chosen as a editable one or not for a table. Besides, it is optional and the widget could be chosen from both editable and read-only widget list in table properties view.
    addTypeInfo This attribute is optional and asks for a Boolean value. It will be used if the widget needs to be bound with a BTT typed data. If it is set to true, the generated jsp tag of the widget will contain the attribute named ‘type’.

    The sample code snippet of this column widget definition is listed below.

  •  Add or remove ‘property’ tag in the ‘properties’ block to indicate the properties of the widget
    <property name="visibility" default="visible" type="Visibility" showInColumn="true"/>
    The details of available attributes for tag ‘columnWidget’ are listed in below table.
    Table 2. table 2
    Attribute Description
    name The attribute is used to define the property name. It is required; otherwise this property will be ignored during generation.
    type The attribute is used to indicate which property editor will be used for this property. The value of it should equals with one of the registered property editor ID in existing BTT toolings. It is required; otherwise the property editor will be disabled in editor.
    default The attribute is used to indicate the default value of this property. The generated JSP tag will contain this default value attribute if it is defined. It is an optional one.
    showInColumn The attribute asks for a Boolean value which defines whether this property is available when this widget is used for a table column.

    The sample code snippet of this column widget definition is listed below.

Configure Mapping Rules for Table Column Widget

Note: You may find more details about this topic in chapter Creating a customized property mapping rule

If there are some special logics to be injected during the JSP generation, such as extra conversion for the names and values of JSP tag attributes, you need to define a mapping rule for the column widget..

Taking the above snippet as an example, the tagged block 'widget-mapping' matches with the generation rules for the sample column widget 'ColumnLink'. The attributes for tag ‘widget-mapping’ are listed in below table.
Table 3. table 3
Attribute Description
widgetName The attribute is used to link the generation rules with the registered column widget. It is required otherwise the rules could not be assigned correctly. So its value should equals with column widget identifier.
tagName The attribute is required and used to indicate the JSP tag name for column widget generation.
In the above sample snippet, the tag ‘property-mapping’ matches with the detailed mapping policy for each widget property during generation. The attributes for tag ‘property-mapping’ are listed in below table.
Table 4. table 4
Attribute Description
propName The attribute is used to indicate the identifier of the property which needs extra generation logic.
attrName The attribute is used to indicate that the property name will be replaced with the value of ‘attrName’ during JSP generation. It is used for conversion of JSP attribute name.
rule The attribute is used to indicate the identifier of a registered mapping rule. It is used for conversion of JSP attribute value.

Define Extension for Mapping Rule of Table Column Widget

Note: You may find more details about this topic in chapter Creating a customized property mapping rule

Finally, if you decide to use the extra rule to control the value generation of JSP attributes, you need also register the rule into BTT tooling extension to indicate the path of the configuration file which contains the mapping rules. For that, you could define an extension for the extension point 'com.ibm.btt.tools.xui.editor2.generator'. Then like the picture below, add a child option of type 'rule'.

Like the picture shown below, the required attributes 'name' and 'class' should be configured. Especially for the attribute 'class', you need to indicate the full path to a class which implements the interface 'com.ibm.btt.tools.xui.editor2.generator.IRule'. During the JSP generation, the class would be instantiated and executed for the configured mapping rules.

So, what you need to do is to add your codes for the attribute value conversion like the snippet above.