The client-side components, or in GWT terminology, widgets, must be made
usable in the client-side GWT application by defining a widget set factory
that can create the widgets by their UIDL tag name. The widget set
class needs to inherit the DefaultWidgetSet class and
implement the createWidget() and
resolveWidgetTypeName() methods. The methods must
call the default implementation to allow creation of the standard widgets.
The following example shows how to define a widget set factory class for the
Color Picker example. The tag name of the widget was defined in the
server-side implementation of the widget (see the section called “Example: A Color Picker GWT Widget”) as
colorpicker. The
resolveWidgetTypeName() must resolve it to the full
name of the ItkColorPicker integration class. The
createWidget() method must create a
ItkColorPicker object when it receives this name.
package com.itmill.toolkit.demo.colorpicker.gwt.client;
import com.google.gwt.user.client.ui.Widget;
import com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker;
import com.itmill.toolkit.terminal.gwt.client.DefaultWidgetSet;
import com.itmill.toolkit.terminal.gwt.client.UIDL;
public class WidgetSet extends DefaultWidgetSet {
/** Creates a widget according to its class name. */
public Widget createWidget(UIDL uidl) {
String className = resolveWidgetTypeName(uidl);
if ("com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker"
.equals(className))
return new ItkColorPicker();
// Let the DefaultWidgetSet handle creation of default widgets
return super.createWidget(uidl);
}
/** Resolves UIDL tag name to class name. */
protected String resolveWidgetTypeName(UIDL uidl) {
String tag = uidl.getTag();
if ("colorpicker".equals(tag))
return "com.itmill.toolkit.demo.colorpicker.gwt.client.ui.ItkColorPicker";
// Let the DefaultWidgetSet handle resolution of default widgets
return super.resolveWidgetTypeName(uidl);
}
}
The default widgets in IT Mill Toolkit actually use more than just the tag
name to resolve the actual widget class. For example, the
Button server-side component, which as tag name
button, can be resolved to either an
IButton or ICheckBox widget,
depending on the switch
(switchMode) attribute. IT Mill Toolkit Client-Side
Engine can actually replace the client-side object of the parameters change.
A widget set is actually a GWT application and needs to be defined in the
GWT module descriptor as the entry point of the application. A GWT module
descriptor is an XML file with extension .gwt.xml.
The following example shows the GWT module descriptor of the Color Picker
application. The client-side entry point will be the
WidgetSet class. We also define the default
stylesheet for the color picker widget, as described above in the section called “Styling GWT Widgets”.
<module>
<!-- Inherit the NoEntry version to avoid multiple entrypoints -->
<inherits name="com.itmill.toolkit.terminal.gwt.DefaultWidgetSetNoEntry" />
<!-- WidgetSet default theme -->
<stylesheet src="colorpicker/styles.css"/>
<!-- Entry point -->
<entry-point class="com.itmill.toolkit.demo.colorpicker.gwt.client.WidgetSet"/>
</module>
For more information about the GWT Module XML Format, please see Google
Web Toolkit Developer Guide.