Customizing property

XUI engine uses Element Factory to inject properties into widgets.

Which properties can be injected? XUI Rich Client engine uses wrapper pattern to wrap SWT widgets. All properties of XUI widget and its wrapped SWT widget can be injected. What are the valid properties? In the XUI widget or SWT widget class, all properties which have set and get method can be valid properties ready to be injected. For example, “org.eclipse.swt.widgets.Text” has setBackground and getBackground methods, so background is a valid property to be injected. Also its wrapper class XUIText, has setMaxLength and getMaxLength methods, so maxLength is valid property to be injected. All properties you want to modify using XUI editor, you need to specify the annotation for them, for more information about how to use customized widgets in XUI editor, and you can refer to XUI editor documents.

As you know, the property type is the set method parameter type, for example, setBackground() method accept “org.eclipse.swt.graphics.Color” parameter. So we use property converter to convert from String type in xml file to required object which can be accepted by set method. Element Factory offers basic property converter, such as String and basic types. XUI engine offers some more pre-built converters for UI use. They are all defined in “propertyConverters” section in XUI engine xml file. They are Image, Font, Color, Rectangle, String Array, and Alignment.

You can also inject your own object definition into the widget. Add the advanced attribute for the widget in the xui.xml file, and configure the xuiengine,xml file by adding the declaration line. You can use the source code of the property converter, and the Java™ documentation of the BTT XUI Engine Interface PropertyConverter for reference.

For example, if you have a widget named CustomerComposite, and has a set method which accept Customer instance, setCustomer(com.customercode.Customer customer), It’s easy to inject Customer object into CustomerComposite. Following these simple steps:

  1. Firstly, create a CustomerConverter, which implements PropertyConverter interface and write the logic to convert from String to Customer object instance.
  2. Secondly, add this converter to XUI engine global file, “propertyConverters” section. After you added this line, the “propertyConverters” section should look like this:
    <map id="propertyConverters">
    	<entry key="org.eclipse.swt.graphics.Image" value="com.ibm.btt.rcp.xui.converter.ImageConverter"/>
    ……
    	<entry key="com.customercode.Customer" value="com.customercode.CustomerConverter"/>
    </map>
  3. If you want to inject customer into CustomerComposite in XUI files, only need to write like this, the engine will automatically convert “Customer String” to Customer object and inject it to CustomerComposite.
    <XUI>
    	< CustomerComposite bounds="74, 61,590,366" customer="Customer String">
    	……	
    	</ CustomerComposite >
    </XUI> 

For more information about injection properties, you can refer to element factory’s document.