3.4 Implementing Your Own Metawidget

Metawidget creates widgets native to a particular UI framework. Having to implement your own Metawidget should be far less common than having to implement your own Inspector or WidgetBuilder, but if your chosen UI framework is not supported 'out of the box' you may need to implement your own.

Metawidgets are not required to extend any base class or implement any interface. However, it is recommended developers familiarize themselves with existing Metawidgets (such as UIMetawidget) to make their API similar. Whilst there is no one Metawidget base class, a number of convenience classes are provided:

MetawidgetMixin

Mixins are a frequently used workaround for multiple inheritance in Java. Classes extend the mixin as an inner class and override its methods as needed.

All the built-in Metawidgets use MetawidgetMixin to ease their implementation. The mixin provides pre-built functionality such as deciding when to use single versus compound widgets, support for overriding widgets, incorporating stubs, and changing between read-only and active modes.

Android

Android already defines a separation between Views and ViewGroups. org.metawidget.android.widget.layout.Layout and its subclasses automate the use of existing Android ViewGroups.

Java Server Faces

For frameworks based on JSF, org.metawidget.faces.component.UIMetawidget provides base widget functionality. See org.metawidget.faces.component.html.HtmlMetawidget for example usage.

JSF already defines a clean separation between widgets and their renderers. org.metawidget.faces.renderkit.LayoutRenderer and its subclasses leverage this to support different layouts.

Java Server Pages

For frameworks based on JSP, org.metawidget.jsp.tagext.MetawidgetTag and the more commonly used org.metawidget.jsp.tagext.html.BaseHtmlMetawidgetTag provide base taglib functionality. See StrutsMetawidgetTag for example usage.

MetawidgetTag also defines a clean separation between choosing widgets and laying them out. org.metawidget.jsp.tagext.Layout and its subclasses can perform the layout for all JSP-based frameworks.

Swing

Swing already defines a clean separation between widgets and layout managers. org.metawidget.swing.layout.Layout and its subclasses automate the use of existing Swing LayoutManagers.