use of org.jboss.tools.openshift.internal.common.ui.databinding.KeywordConverter in project jbosstools-openshift by jbosstools.
the class EditResourceLimitsPage method createResourceWidgets.
private void createResourceWidgets(String label, String property, String[] suffixes, String[] labels, Group parent, DataBindingContext dbc) {
// label
Label labelComp = new Label(parent, SWT.NONE);
labelComp.setText(label);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelComp);
// value text
Text text = new Text(parent, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(text);
// unit combo
ComboViewer combo = new ComboViewer(parent);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).hint(140, SWT.DEFAULT).applyTo(combo.getControl());
combo.setContentProvider(ArrayContentProvider.getInstance());
combo.setInput(suffixes);
combo.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return getLabelForSuffix(element, suffixes, labels);
}
private String getLabelForSuffix(Object element, String[] suffixes, String[] labels) {
String label = (String) element;
for (int i = 0; i < suffixes.length; ++i) {
if (element.equals(suffixes[i])) {
label = labels[i];
break;
}
}
return label;
}
});
IObservableValue<String> valueObservable = WidgetProperties.text(SWT.Modify).observe(text);
IObservableValue<String> selectedUnitObservable = ViewerProperties.singleSelection().observe(combo);
IObservableValue<IContainer> master = BeanProperties.value(EditResourceLimitsPageModel.SELECTED_CONTAINER).observe(model);
ValueBindingBuilder.bind(valueObservable).validatingAfterGet(new NumericValidator("integer", Integer::parseInt)).converting(new AggregatingConverter(selectedUnitObservable, true)).to(PojoProperties.value(property).observeDetail(master)).converting(new KeywordConverter(suffixes, true)).in(dbc);
ValueBindingBuilder.bind(selectedUnitObservable).converting(new AggregatingConverter(valueObservable, false)).to(PojoProperties.value(property).observeDetail(master)).converting(new KeywordConverter(suffixes, false)).in(dbc);
}
Aggregations