use of org.springsource.ide.eclipse.commons.livexp.ui.UIConstants.FIELD_TEXT_AREA_WIDTH in project eclipse-integration-commons by spring-projects.
the class ChooseOneSectionCombo method createContents.
@Override
public void createContents(Composite page) {
Composite field = new Composite(page, SWT.NONE);
GridLayout layout = GridLayoutFactory.fillDefaults().numColumns(2).create();
field.setLayout(layout);
GridDataFactory.fillDefaults().grab(true, false).applyTo(field);
Label fieldNameLabel = new Label(field, SWT.NONE);
fieldNameLabel.setText(label);
GridDataFactory labelGridData = GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER);
if (useFieldLabelWidthHint) {
labelGridData.hint(UIConstants.fieldLabelWidthHint(fieldNameLabel), SWT.DEFAULT);
}
labelGridData.applyTo(fieldNameLabel);
final Combo combo = new Combo(field, inputParser == null ? SWT.READ_ONLY : SWT.NONE);
options.addListener(new ValueListener<T[]>() {
public void gotValue(org.springsource.ide.eclipse.commons.livexp.core.LiveExpression<T[]> exp, T[] value) {
if (combo != null) {
String oldText = combo.getText();
// This will clear the selection sometimes
combo.setItems(getLabels());
combo_setText(combo, oldText);
}
}
});
GridDataFactory gridData = GridDataFactory.fillDefaults();
if (inputParser != null) {
gridData = gridData.hint(FIELD_TEXT_AREA_WIDTH, SWT.DEFAULT).minSize(FIELD_TEXT_AREA_WIDTH, SWT.DEFAULT);
}
if (grabHorizontal) {
gridData = gridData.grab(grabHorizontal, false);
}
gridData.applyTo(combo);
combo.addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
handleModifyText(combo);
}
});
selection.selection.addListener(UIValueListener.from((exp, newSelection) -> {
if (newSelection != null && !combo.isDisposed()) {
// Technically, not entirely correct. This might
// select the wrong element if more than one option
// has the same label text.
String newText = labelProvider.getText(newSelection);
combo_setText(combo, newText);
if (!combo.getText().equals(newText)) {
// widget rejected the selection. To avoid widget state
// and model state getting out-of-sync, refelct current
// widget state back to the model:
handleModifyText(combo);
}
}
}));
}
Aggregations