Search in sources :

Example 1 with NumericValidator

use of org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator 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)

Example 2 with NumericValidator

use of org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator in project jbosstools-openshift by jbosstools.

the class OpenShiftServerEditorSection method createDebuggingPortControls.

@SuppressWarnings("unchecked")
private void createDebuggingPortControls(FormToolkit toolkit, Composite container, DataBindingContext dbc) {
    Label debugPortLabel = new Label(container, SWT.None);
    debugPortLabel.setText("Debugging Port:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(debugPortLabel);
    // use image key & value checkbox
    useImageDebugPortKeyButton = new Button(container, SWT.CHECK);
    useImageDebugPortKeyButton.setText("use image provided key and value");
    GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.CENTER).applyTo(useImageDebugPortKeyButton);
    // port key field
    // filler
    new Label(container, SWT.NONE);
    Label keyLabel = new Label(container, SWT.NONE);
    keyLabel.setText("Key:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(keyLabel);
    debugPortKeyText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortKeyText);
    debugPortKeyListener = new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            execute(new ServerWorkingCopyPropertyTextCommand(input.getServer(), "SetDebugPortKey", debugPortKeyText, debugPortKeyText.getText(), OpenShiftServerUtils.ATTR_DEBUG_PORT_KEY, (ModifyListener) this));
        }
    };
    ModifyListener debugPortKeyDecoration = new TextboxDecoratorSupport(debugPortKeyText, value -> {
        if (!useImageDebugPortKeyButton.getSelection()) {
            return new OpenShiftIdentifierValidator().validate(debugPortKeyText.getText());
        }
        return Status.OK_STATUS;
    });
    debugPortKeyText.addModifyListener(debugPortKeyDecoration);
    // port value field
    Label portLabel = new Label(container, SWT.NONE);
    portLabel.setText("Port:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(portLabel);
    debugPortText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortText);
    debugPortValListener = new ModifyListener() {

        public void modifyText(ModifyEvent e) {
            execute(new ServerWorkingCopyPropertyTextCommand(input.getServer(), "SetDebugPortValue", debugPortText, debugPortText.getText(), OpenShiftServerUtils.ATTR_DEBUG_PORT_VALUE, this));
        }
    };
    ModifyListener debugPortValDecoration = new TextboxDecoratorSupport(debugPortText, value -> {
        if (!useImageDebugPortKeyButton.getSelection()) {
            return new NumericValidator("integer", Integer::parseInt, true).validate(debugPortText.getText());
        }
        return Status.OK_STATUS;
    });
    debugPortText.addModifyListener(debugPortValDecoration);
    debugPortKeyValSelectionListener = new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            execute(new ToggleDebugKeyValueCommand(server, useImageDebugPortKeyButton, this, debugPortKeyText, debugPortKeyListener, debugPortText, debugPortValListener));
        }
    };
}
Also used : ModifyListener(org.eclipse.swt.events.ModifyListener) OpenShiftIdentifierValidator(org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FormText(org.eclipse.ui.forms.widgets.FormText) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) ServerWorkingCopyPropertyTextCommand(org.jboss.ide.eclipse.as.wtp.ui.editor.ServerWorkingCopyPropertyTextCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 3 with NumericValidator

use of org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createDebuggingPortControls.

@SuppressWarnings("unchecked")
private void createDebuggingPortControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Label debugPortLabel = new Label(parent, SWT.None);
    debugPortLabel.setText("Debugging Port:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(debugPortLabel);
    // use image key & value checkbox
    Button useImageDebugPortKeyButton = new Button(parent, SWT.CHECK);
    useImageDebugPortKeyButton.setText("use image provided key and value");
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).applyTo(useImageDebugPortKeyButton);
    IObservableValue<Boolean> useImageDebugPortKey = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEBUG_PORT_KEY).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDebugPortKeyButton)).to(useImageDebugPortKey).in(dbc);
    // filler
    new Label(parent, SWT.NONE);
    // key text field
    // filler
    new Label(parent, SWT.NONE);
    Label keyLabel = new Label(parent, SWT.NONE);
    keyLabel.setText("Key:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(keyLabel);
    Text debugPortKeyText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortKeyText);
    IObservableValue<String> debugPortKeyTextObservable = WidgetProperties.text(SWT.Modify).observe(debugPortKeyText);
    ValueBindingBuilder.bind(debugPortKeyTextObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEBUG_PORT_KEY).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(debugPortKeyText)).notUpdating(useImageDebugPortKey).converting(new InvertingBooleanConverter()).in(dbc);
    ValidationStatusProvider debugPortKeyValidator = new DisableableMultiValitdator<String>(useImageDebugPortKey, debugPortKeyTextObservable, new OpenShiftIdentifierValidator());
    dbc.addValidationStatusProvider(debugPortKeyValidator);
    ControlDecorationSupport.create(debugPortKeyValidator, SWT.LEFT | SWT.TOP, parent, new RequiredControlDecorationUpdater(true));
    // port text field
    IObservableValue<Boolean> useImageDebugPortValue = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEBUG_PORT_VALUE).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDebugPortKeyButton)).to(useImageDebugPortValue).in(dbc);
    Label portLabel = new Label(parent, SWT.NONE);
    portLabel.setText("Port:");
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.CENTER).applyTo(portLabel);
    Text debugPortText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(debugPortText);
    IObservableValue<String> debugPortValueObservable = WidgetProperties.text(SWT.Modify).observe(debugPortText);
    ValueBindingBuilder.bind(debugPortValueObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEBUG_PORT_VALUE).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(debugPortText)).notUpdating(useImageDebugPortValue).converting(new InvertingBooleanConverter()).in(dbc);
    ValidationStatusProvider debugPortValueValidator = new DisableableMultiValitdator<String>(useImageDebugPortValue, debugPortValueObservable, new NumericValidator("integer", Integer::parseInt, true));
    dbc.addValidationStatusProvider(debugPortValueValidator);
    ControlDecorationSupport.create(debugPortValueValidator, SWT.LEFT | SWT.TOP, parent, new RequiredControlDecorationUpdater(true));
}
Also used : OpenShiftIdentifierValidator(org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator) InvertingBooleanConverter(org.jboss.tools.common.ui.databinding.InvertingBooleanConverter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DisableableMultiValitdator(org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) NumericValidator(org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button)

Aggregations

Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 NumericValidator (org.jboss.tools.openshift.internal.common.ui.databinding.NumericValidator)3 Button (org.eclipse.swt.widgets.Button)2 OpenShiftIdentifierValidator (org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator)2 IContainer (com.openshift.restclient.model.IContainer)1 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 FormText (org.eclipse.ui.forms.widgets.FormText)1 ServerWorkingCopyPropertyTextCommand (org.jboss.ide.eclipse.as.wtp.ui.editor.ServerWorkingCopyPropertyTextCommand)1 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)1 AggregatingConverter (org.jboss.tools.openshift.internal.common.ui.databinding.AggregatingConverter)1 DisableableMultiValitdator (org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator)1 KeywordConverter (org.jboss.tools.openshift.internal.common.ui.databinding.KeywordConverter)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1