# Extensibility

The following topic relate to extensibility in XWT. There are two types of extensibility: Support of new kind of user-defined UI element and Support register IMetaclass factory via API or EP.

- User-defined UI Element: The user-defined UI element can be used directly in XWT when the customer respects the SWT standard signature with two arguments: Composite/Widget parent and Style.
- IMetaclass factory: The IMetaclass factory is used to create some special IMetaclass, which takes care of the UI creation.

### User-defined UI Element

XWT support user-defined UI element which is extends from Composite class or other SWT class. The following is a user defined button.

XWT XML:

    <j:UserControl xmlns="http://www.eclipse.org/xwt/presentation"
        xmlns:x="http://www.eclipse.org/xwt"
        xmlns:j="clr-namespace:org.eclipse.e4.xwt.tests.usercontrol"
        x:Class="org.eclipse.e4.xwt.tests.usercontrol.UserControl">
        ...
        <Button text="Hello, world" />
    </j:UserControl>

java:

    public class UserControl extends Composite {

        public UserControl(Composite parent, int style) {
            super(parent, style);
        }
    }

The defined element can be used directly in XWT. In XWT XML, only need to declare the application class path and name in the place where you want like the following code.

    <Composite xmlns="http://www.eclipse.org/xwt/presentation"
        xmlns:x="http://www.eclipse.org/xwt"
        xmlns:y="clr-namespace:org.eclipse.e4.xwt.tests.usercontrol">
        <Composite.layout>
            <GridLayout numColumns="2"/>
        </Composite.layout>
        <y:UserControl/>
    </Composite>

### IMetaclass factory

XWT provide another way to registrate user defined component: IMetaclass Factory. The IMetaclass factory is used to create some special IMetaclass, Metaclass class implement IMetaclass interface. User can define component by a special Metaclass. Compared with User-defined UI Element, these component no need to extends from any SWT class.

******************** Sample ********************