SWTML FAQs


Q) What are all supported XML attributes for SWT Widget in SWTML?

For any SWT Widget all "setter" methods with basic Java types as parameter are supported as attribute.

For example, setToolTipText(<str>)  is supported as attribute "toolTipText".

There are few custom attributes defined in swtml. Custome attributes are prefix with underscore "_" symbol.


Top

Q) Which SWT events are common to all widgets? 

SWT.Dispose, SWT.DragDetect, SWT.FocusIn, SWT.FocusOut, SWT.Help, SWT.KeyDown, SWT.KeyUp, SWT.MenuDetect, SWT.MouseDoubleClick, SWT.MouseDown, SWT.MouseEnter, SWT.MouseExit, SWT.MouseHover, SWT.MouseUp, SWT.MouseMove, SWT.Move, SWT.Paint, SWT.Resize and SWT.Traverse.
Top

Q) How to declare SWT resources like Image, Font and Color in SWTML?

Image

Image can be assigned to a widget in two ways.
1) Using _image-id attribute :
 
<!-- Declare image as resource -->
<image src="/com/sheelapps/swtml/examples/run.gif" id="img-run" />

<!-- use with multiple control -->
<tool-item  _image-id="img-run" ></tool-item>
<menu-item text="Run" _image-id="img-run" ></menu-item>

 
 
2) Using _image attribute :
 
<!-- Inline image -->
<tool-item  _image="/com/sheelapps/swtml/examples/run.gif" ></tool-item>

 
 

Font

Font can be assigned to a widget in two ways.­
1) Using _font-id attribute :

 
<font name="Arial" size="14" id="arial14" />

<text text="Font test"  style="SWT.WRAP | SWT.MULTI" _font-id="arial14">
</text>
 

 
2) Using sub-element <font> tag :
 
<label text="Hello" >

	<font name="Helvetica" size="16" style="SWT.BOLD"/>
</label>

 
 

Color

1) For widget with color support :

 
<text text="Color Test"  style="SWT.WRAP | SWT.MULTI">

	<color fg-color="SWT.COLOR_GREEN" bg-color="SWT.COLOR_BLACK"/>
</text>
 
 
Top

Q) How to define SWT Layout in SWTML?

SWT layout controls the position and size of children in composite.
SWT Layout SWTML tag
FillLayout <fill-layout>
RowLayout <row-layout>
GridLayout <grid-layout> and <grid-data>
StackLayout <stack-layout>
<fill-layout>
Attribute Supported Values
type SWT.HORIZONTAL or SWT.VERTICAL

<row-layout>
Attribute Supported Values
fill true or false
justify true or false
marginbottom integer
marginheight integer
marginleft integer
marginright integer
pack true or false
spacing integer
type SWT.HORIZONTAL or SWT.VERTICAL
wrap true or false

<grid-layout>
Attribute Supported Values
equalwidth true or false
horizontalspacing integer
marginbottom integer
marginheight integer
marginleft integer
marginright integer
numcolumns integer

<grid-data>
Attribute Supported Values
h-grab true or false
v-grab true or false
h-align Supported SWT Constants, for example SWT.FILL
v-align Supported SWT Constants, for example SWT.FILL
h-span integer
v-span integer

<stack-layout>
Attribute Supported Values
marginheight integer
marginwidth integer
_control "id" of control to display at top of stack

Top

Q) How can I use SWTML to create Eclipse plugin UI?

In XML use composite as root element and before parsing set View's composite as parent widget.

 
/*
For example in View Class
*/
public void createPartControl(Composite parent) {          
       parser.addParent(parent)

      (Composite) parser.doParse(<xmlfile>);    
 }
 
 
SWTML's XML :
 
<?xml version="1.0" encoding="UTF-8"?>

<!-- Top level widget is Composite-->
<composite>
<!-- Other widgets--> 
</composite> 
 
 
Top

Q) How to get reference of SWT Widget in Java Code?

Assign "id" attribute to widget in XML. Example :
 
<text id="status" /> 

 
 
Then use SWTObjectMap class to get reference of SWT Widget.
 
(Text)SWTObjectMap.getInstance().getObjectMap().get("status"); 

 
 
Top