The Format extension is only provided for the text widget. The input string can be converted into the required output format with this function, and the output string is displayed on the Text GUI.
The format of user input is different from the format of the under layer Data Model in some case. For this reason, XML UI Engine provides a Formatter Interface. It can format the user input in the text field to the format of under layer Data Model.
How does the XML UI Formatter works
IFormat interface
package com.ibm.btt.rcp.xui.format; public interface IFormat { public String format(String text); public Object formatToConversionType(String text); public String formatFromConversionType(Object obj); } public String format(String text); format the text to String public Object formatToConversionType(String text); format the text to an Object public String formatFromConversionType(Object obj); format the obj to String
The invoking process
Once the formatter is defined for a Text, it will be invoked by the XML UI Engine automatically as the following steps:
When | Action | Direction | Example | Method |
---|---|---|---|---|
Initialize the Text Field(step1) | Format the data object in the Data Model to a String | Data Model(Object) Shadow of Text Field(String) | Date(instance: 2007-01-01 00:00:00) String (20070707) | Iformat.formatFromConversionType() |
Initialize the Text Field(step2) | Format the shadow variable (Sting) to the predefined format(String) | Shadow of Text Field(String) Text Field(String) | String (20070707) String(2007-07-07) | Iformat.format() |
Initialize the Text Field(step3) | Display the Formatted Sting of this Text Field | NA | 2007-07-07 | NA |
Text Field on focus | Display the Shadow of Text Field(String) | NA | 20070707 | NA |
Text Field lost focus(step1) | Format the shadow variable (Sting) to the predefined format(String) | Shadow of Text Field(String) Text Field(String) | String (20070707) String(2007-07-07) | Iformat.format() |
Text Field lost focus(step2) | Display the Formatted Sting of this Text Field | NA | 2007-07-07 | NA |
Text Field lost focus(step3) | Format the shadow variable(String) to an object of Data Model | Shadow of Text Field(String) Data Model(Object) | String (20070707) Date(instance: 2007-01-01 00:00:00) | Iformat.formatToConversionType() |
Text Field lost focus(step4) | Save the formated object to Data Model | NA | Date(instance: 2007-01-01 00:00:00) | NA |
To use this function, you should extend the Format class in BTT for your own format class, and implement your own format function. The following is the sample code for this function.
package DeveloperPackage; public class DeveloperFormat extends com.ibm.btt.rcp.xui.format.Format { <Override public String format(String inText) { // implement Developer’s format return outText; }}The xui.xml file should be edited like the following sample code.
<Text> <list Injection="formats"> <DeveloperPackage.DeveloperFormat/> </list> </Text>
Definition
<Text bounds="182,77,280,22"> <list Injection="initializers"> <com.ibm.btt.xmluiengine.test.initializers.TextInitializer /> </list> <com.ibm.btt.rcp.xui.format.NumericFormat Injection="format" /> <list Injection="actions"> <com.ibm.btt.rcp.xui.action.TestAction /> </list> </Text>
Prebuilt Formatter
XML UI Engine provides three types of pre-built Formatters:
<Text bounds="182,122,280,22" dataName="number"> <com.ibm.btt.rcp.xui.format.NumericFormat Injection="format" inputPattern="#.##" outputPattern="#,###.##" /> </Text>
<Text bounds="182,200,280,22" dataName="currency"> <com.ibm.btt.rcp.xui.format.CurrencyFormat Injection="format" inputPattern="##" outputPattern="#,###.## rmb" /> </Text>
<Text bounds="182,165,280,22" dataName="date"> <com.ibm.btt.rcp.xui.format.DateFormat Injection="format" inputPattern="yyyyMMdd" outputPattern="yyyy-MM-dd kk:mm:ss Z" /> </Text>