}
protected Control createSWTControl(FormControl control,
BasicRenderer parent, LayoutContext c, CalculatedStyle style,
UserAgentCallback uac) {
final SelectControl sc = (SelectControl) control;
Map options = sc.getOptions();
_values = new ArrayList(options.keySet());
_labels = new ArrayList(options.values());
if (sc.getSize() > 1 || sc.isMultiple()) {
_combo = false;
final List list = new List(parent, SWT.BORDER | SWT.V_SCROLL
| (sc.isMultiple() ? SWT.MULTI : SWT.SINGLE));
list.setItems((String[]) _labels
.toArray(new String[_labels.size()]));
list.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
if (sc.isMultiple()) {
int[] indices = list.getSelectionIndices();
String[] values = new String[indices.length];
for (int i = 0; i < indices.length; i++) {
values[i] = (String) _values.get(indices[i]);
}
sc.setMultipleValues(values);
} else {
sc.setValue((String) _values.get(list
.getSelectionIndex()));
}
}
});
sc.addFormControlListener(new FormControlAdapter() {
public void changed(FormControl control) {
if (sc.isSuccessful()) {
if (sc.isMultiple()) {
String[] values = sc.getMultipleValues();
int[] indices = new int[values.length];
for (int i = 0; i < values.length; i++) {
indices[i] = _values.indexOf(values[i]);
}
list.setSelection(indices);
} else {
list.setSelection(_values.indexOf(sc.getValue()));
}
} else {
list.deselectAll();
}
}
public void successful(FormControl control) {
changed(control);
}
});
if (sc.isSuccessful()) {
if (sc.isMultiple()) {
String[] values = sc.getMultipleValues();
int[] indices = new int[values.length];
for (int i = 0; i < values.length; i++) {
indices[i] = _values.indexOf(values[i]);
}
list.setSelection(indices);
} else {
list.setSelection(_values.indexOf(sc.getValue()));
}
}
return list;
} else {
_combo = true;
final Combo combo = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY);
combo.setItems((String[]) _labels
.toArray(new String[_labels.size()]));
combo.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
int selection = combo.getSelectionIndex();
if (selection < 0) {
sc.setSuccessful(false);
} else {
sc.setValue((String) _values.get(selection));
}
}
});
sc.addFormControlListener(new FormControlAdapter() {
public void changed(FormControl control) {
if (sc.isSuccessful()) {
combo.select(_values.indexOf(sc.getValue()));
} else {
combo.deselectAll();
}
}
public void successful(FormControl control) {
changed(control);
}
});
if (sc.isSuccessful()) {
combo.select(_values.indexOf(sc.getValue()));
}
return combo;
}
}