Search in sources :

Example 1 with KeywordConverter

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);
}
Also used : AggregatingConverter(org.jboss.tools.openshift.internal.common.ui.databinding.AggregatingConverter) KeywordConverter(org.jboss.tools.openshift.internal.common.ui.databinding.KeywordConverter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IContainer(com.openshift.restclient.model.IContainer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

IContainer (com.openshift.restclient.model.IContainer)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 AggregatingConverter (org.jboss.tools.openshift.internal.common.ui.databinding.AggregatingConverter)1 KeywordConverter (org.jboss.tools.openshift.internal.common.ui.databinding.KeywordConverter)1 NumericValidator (org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator)1