====== XSWT Mini-Tutorial ====== This mini-tutorial will walk you through getting started with XSWT. ===== Getting started ===== To download XSWT, use the XSWT update site: * http://xswt.sourceforge.net/updates To create a new XSWT file: * File | New | Other… | XSWT | XSWT file To display the XSWT preview pane: * Window | Show view | Other… | XSWT | XSWT Preview ===== First steps ===== Writing XSWT is just like writing SWT, but with a more convenient syntax. If you want a Label: Label myLabel = new Label(parentComposite, SWT.NULL); Just write: Or more simply: To set a property value, if the value is a simple data type (not an object itself with multiple fields that need to be initialized), just set the attribute with the same name: To set a property value where the new property value object itself also needs properties set, create a subnode: This translates to the following Java code: Composite composite1 = new Composite(parent, SWT.NULL); GridLayout layout1 = new GridLayout(); layout1.numColumns = 2; composite1.setLayout(layout1); To say the same thing in English: * We will call setLayout() on the parent Composite. * The parameter type to the setter, in this case, setLayout, is of the abstract type Layout, so XSWT does not know the type of the object to construct. Consequently, we use the x:class attribute to tell XSWT what type to construct. * We can set properties on the new object that was constructed (in this case the GridLayout) just by supplying attributes. * Note that XSWT automatically capitalizes the first letter of property names and x:classes, allowing you to write ideomatic XML code. You can add further children by adding an: node. For example: