protected Control createSWTControl(FormControl control,
BasicRenderer parent, LayoutContext c, CalculatedStyle style,
UserAgentCallback uac) {
final ButtonControl bc = (ButtonControl) control;
final Button button = new Button(parent, SWT.PUSH);
button.setText(bc.getLabel());
if (bc.isExtended()) {
// when defined with <button>, allow the first image to be used
NodeList images = bc.getElement().getElementsByTagName("img");
if (images.getLength() > 0) {
Element img = (Element) images.item(0);
String uri = c.getNamespaceHandler().getImageSourceURI(img);
ImageResource res = uac.getImageResource(uri);
SWTFSImage fsi = (SWTFSImage) res.getImage();
// copy the image to prevent disposal, and apply a disabled
// effect if needed
_image = new Image(button.getDisplay(), fsi.getImage(), (bc
.isEnabled() ? SWT.IMAGE_COPY : SWT.IMAGE_DISABLE));
button.setImage(_image);
}
}
if (bc.getType().equals("submit")) {
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (bc.press()) {
bc.getForm().submit();
}
}
});
// TODO better per form handling?
parent.getShell().setDefaultButton(button);
} else if (bc.getType().equals("reset")) {
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (bc.press()) {
bc.getForm().reset();
}
}
});
} else {
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
bc.press();
}
});
}
return button;