6. WidgetBuilders

This chapter covers each WidgetBuilder in detail. For an explanation of how WidgetBuilders fit into the overall architecture of Metawidget, see Chapter 2, Architecture

Throughout this chapter when we refer to 'Metawidget Attributes' we mean the intermediate XML that Metawidget passes between Inspectors and other parts of the architecture. Quite which Inspector set the attribute, and based on what, is covered in Chapter 4, Inspectors. For example, the maximum-value attribute could be set by HibernateValidatorInspector based on the @Max annotation, or by CommonsValidatorInspector based on an intRange element in an XML file, or some other source.

6.1 Desktop WidgetBuilders

Metawidget supports multiple WidgetBuilders for each desktop framework, targeting specific widget libraries within each environment.

6.1.1 Swing WidgetBuilders

OverriddenWidgetBuilder

OverriddenWidgetBuilder locates child widgets designed to override default generation. It matches JComponents whose getName equals the same name Metawidget would have generated.

ReadOnlyWidgetBuilder

ReadOnlyWidgetBuilder returns read-only widgets when either the business property is read-only or the Metawidget has setReadOnly. It instantiates the following widgets for the following Metawidget attributes:

Widget Metawidget Attribute
javax.swing
JLabel read-only (except when also type="java.util.Collection" or masked)
JPanel read-only and masked
org.metawidget.swing
Stub action when also read-only, type="java.util.Collection" when also read-only

SwingWidgetBuilder

SwingWidgetBuilder is the default WidgetBuilder for SwingMetawidget. It instantiates the following widgets for the following Metawidget attributes:

Widget Metawidget Attribute
javax.swing
JButton action (except when also read-only)
JCheckBox type="boolean" (and type="java.lang.Boolean" when also required)
JComboBox lookup
JPasswordField masked (except when also read-only)
JSlider type is a primitive (except boolean and char) and has both minimum-value and maximum-value
JSpinner type is a primitive (except boolean and char) and has only one, or neither minimum-value and maximum-value. For floats and doubles, the step size is governed by maximum-fractional-digits
JTable type="java.util.Collection". The JTable is automatically wrapped in a JScrollPane
JTextArea type="java.lang.String" and large. The JTextArea is automatically wrapped in a JScrollPane
JTextField type is a java.lang.String, java.util.Date, primitive wrapper (e.g. Integer or Float) except java.lang.Boolean. Also if property is of unknown type but dont-expand
org.metawidget.swing
Stub hidden

SwingXWidgetBuilder

SwingXWidgetBuilder is a pluggable WidgetBuilder for the SwingX library. It is intended to be used in conjunction with the default SwingWidgetBuilder. It instantiates the following widgets for the following Metawidget attributes:

Widget Metawidget Attribute
org.jdesktop.swingx
JXDatePicker type="java.util.Date"

6.1.2 SWT WidgetBuilders

OverriddenWidgetBuilder

OverriddenWidgetBuilder locates child widgets designed to override default generation. It matches Controls whose getData("name") equals the same name Metawidget would have generated.

ReadOnlyWidgetBuilder

ReadOnlyWidgetBuilder returns read-only widgets when either the business property is read-only or the Metawidget has setReadOnly. It instantiates the following widgets for the following Metawidget attributes:

Widget Metawidget Attribute
org.eclipse.swt.widgets
Label read-only (except when also type="java.util.Collection" or masked)
Composite read-only and masked
org.metawidget.swt
Stub action when also read-only, type="java.util.Collection" when also read-only

SwtWidgetBuilder

SwtWidgetBuilder is the default WidgetBuilder for SwtMetawidget. It instantiates the following widgets for the following Metawidget attributes:

Widget Metawidget Attribute
org.eclipse.swt.widgets
Button action (except when also read-only)
Button( SWT.CHECK ) type="boolean" (and type="java.lang.Boolean" when also required)
Combo lookup
Text( SWT.MASKED ) masked (except when also read-only)
Scale type is a primitive (except boolean and char) and has both minimum-value and maximum-value
Spinner type is a primitive (except boolean and char) and has only one, or neither minimum-value and maximum-value. For floats and doubles, the increment is governed by maximum-fractional-digits
Text( SWT.MULTI ) type="java.lang.String" and large
Text type is a java.lang.String, java.util.Date, primitive wrapper (e.g. Integer or Float) except java.lang.Boolean. Also if property is of unknown type but dont-expand
org.metawidget.swt
Stub hidden