XSWT Tips and Tricks

How can I make a checkbox or radio button? <checkbox> and <radio> are not recognized in my XSWT files!

They are called <button x:style="CHECK"> and <button x:style="RADIO"> in SWT.

My text fields, combo boxes, etc. look strange. What am I doing wrong?

You usually want to add the BORDER option, like this: <text x:style="BORDER">

How can I make a long label wrap nicely?

Specifying x:style="WRAP" is necessary, but not enough. You must also make sure that the label widget expands and fills the space horizontally:

<label text="Some long text...." x:style="WRAP">
    <layoutData x:class="GridData" horizontalAlignment="FILL"
       grabExcessHorizontalSpace="true"/>
</label>

How can I set the initial focus?

Add <setFocus/> to the XML body of the desired widget.

How can I make the presence of some widget conditional to some previous input?

You can use <#if> and other FreeMarker directives in XSWT files. These files undergo template processing each time the corresponding page appears.

How can I carry forward data from a previous page to the next?

Use FreeMarker variables (${varName}) in the page.

How can I fill a combo box with values that I will only know at runtime?

You can generate the <option> children of the combo using FreeMarker directives (e.g. <#list>...</#list>).

How can I have more sophisticated user input than what I can get through simple textedit fields, checkboxes and the like?

You can implement custom SWT controls in Java and use them in the wizard pages. The custom controls may even be packaged into jar files in the template’s directory (i.e. you do not need to write a separate Eclipse plug-in, etc.). Have a look at the source files of the existing custom controls (FileChooser, NedTypeChooser, InfoLink, etc.).

How can I dynamically enable/disable controls on a page, depending on other controls (i.e. the state of a checkbox or a radio button)?

Currently, you cannot do this. If you are desperate, you have the following options: (1) put the dependent controls on a separate page, which you can make conditional; (2) write a custom CheckboxComposite control in Java that features a checkbox that enables/disables child controls when the checkbox selection changes; (3) write the full custom wizard page entirely in Java and register it in template.properties with page.xx.class= instead of page.xx.file=; or (4) implement scripting support for XSWT 1.x and contribute the patch to us.

In the Project wizard, how does it get decided which templates get offered when the With C⁠+⁠+ Support checkbox is selected and when it is not selected on the first page?

If the C⁠+⁠+ support checkbox is cleared, templates that require C⁠+⁠+ support will not appear; when it is checked, there is no such filtering. A template is regarded as one that requires C⁠+⁠+ support if the template.properties file contains any of the following: sourceFolders=, makemakeOptions=, or requiresCPlusPlus=true.