Search in sources :

Example 6 with ValidationStatusProvider

use of org.eclipse.core.databinding.ValidationStatusProvider in project jbosstools-openshift by jbosstools.

the class ServerSettingsWizardPage method createEnableDebuggingControls.

@SuppressWarnings("unchecked")
private void createEnableDebuggingControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Label enableDevmodeLabel = new Label(parent, SWT.None);
    enableDevmodeLabel.setText("Enable debugging:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(enableDevmodeLabel);
    Button useImageDevmodeKey = new Button(parent, SWT.CHECK);
    useImageDevmodeKey.setText("use image provided key");
    GridDataFactory.fillDefaults().span(4, 1).align(SWT.FILL, SWT.CENTER).applyTo(useImageDevmodeKey);
    IObservableValue<Boolean> useImageDevmodeKeyObservable = BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_USE_IMAGE_DEVMODE_KEY).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(useImageDevmodeKey)).to(useImageDevmodeKeyObservable).in(dbc);
    // 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 devmodeKeyText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().span(3, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(devmodeKeyText);
    IObservableValue<String> devmodeKeyObservable = WidgetProperties.text(SWT.Modify).observe(devmodeKeyText);
    ValueBindingBuilder.bind(devmodeKeyObservable).to(BeanProperties.value(OpenShiftServerEditorModel.PROPERTY_DEVMODE_KEY).observe(model)).in(dbc);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(devmodeKeyText)).notUpdating(useImageDevmodeKeyObservable).converting(new InvertingBooleanConverter()).in(dbc);
    ValidationStatusProvider devmodeKeyValidator = new DisableableMultiValitdator<String>(useImageDevmodeKeyObservable, devmodeKeyObservable, new OpenShiftIdentifierValidator());
    dbc.addValidationStatusProvider(devmodeKeyValidator);
    ControlDecorationSupport.create(devmodeKeyValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
}
Also used : RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) Button(org.eclipse.swt.widgets.Button) 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)

Example 7 with ValidationStatusProvider

use of org.eclipse.core.databinding.ValidationStatusProvider in project jbosstools-openshift by jbosstools.

the class AdvancedConnectionEditor method createControls.

@SuppressWarnings("unchecked")
@Override
public Composite createControls(Composite parent, Object context, DataBindingContext dbc) {
    this.pageModel = (ConnectionWizardPageModel) context;
    this.selectedConnection = BeanProperties.value(ConnectionWizardPageModel.PROPERTY_SELECTED_CONNECTION).observe(pageModel);
    this.model = new AdvancedConnectionEditorModel();
    Composite composite = setControl(new Composite(parent, SWT.None));
    GridLayoutFactory.fillDefaults().applyTo(composite);
    DialogAdvancedPart part = new DialogAdvancedPart() {

        @Override
        protected void createAdvancedContent(Composite advancedComposite) {
            Label lblRegistry = new Label(advancedComposite, SWT.NONE);
            lblRegistry.setText("Image Registry URL:");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
            Text txtRegistry = new Text(advancedComposite, SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(1, 1).applyTo(txtRegistry);
            Button registryDiscover = new Button(advancedComposite, SWT.PUSH);
            registryDiscover.setText("Discover...");
            registryDiscover.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    discoverRegistryPressed(registryDiscover.getShell());
                }
            });
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(registryDiscover);
            UIUtils.setDefaultButtonWidth(registryDiscover);
            registryURLObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtRegistry);
            Binding registryURLBinding = ValueBindingBuilder.bind(registryURLObservable).validatingAfterConvert(new URLValidator(VALIDATOR_URL_TYPE, true)).converting(new TrimTrailingSlashConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_REGISTRY_URL).observe(model)).in(dbc);
            ControlDecorationSupport.create(registryURLBinding, SWT.LEFT | SWT.TOP);
            Label lblNamespace = new Label(advancedComposite, SWT.NONE);
            lblNamespace.setText("Cluster namespace:");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblNamespace);
            Text txtClusterNamespace = new Text(advancedComposite, SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(txtClusterNamespace);
            clusterNamespaceObservable = WidgetProperties.text(SWT.Modify).observeDelayed(DELAY, txtClusterNamespace);
            ValueBindingBuilder.bind(clusterNamespaceObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_CLUSTER_NAMESPACE).observe(model)).in(dbc);
            Link ocWorkspace = new Link(advancedComposite, SWT.PUSH);
            ocWorkspace.setText("<a>Workspace OC Settings</a>");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).span(3, 1).applyTo(ocWorkspace);
            // Override OC location widgets
            Button overrideOC = new Button(advancedComposite, SWT.CHECK);
            overrideOC.setText("Override 'oc' location: ");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(lblRegistry);
            IObservableValue<Boolean> overrideOCObservable = WidgetProperties.selection().observe(overrideOC);
            ValueBindingBuilder.bind(overrideOCObservable).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE).observe(model)).in(dbc);
            final Text ocText = new Text(advancedComposite, SWT.SINGLE | SWT.BORDER);
            GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(ocText);
            IObservableValue<String> ocLocationObservable = WidgetProperties.text(SWT.Modify).observe(ocText);
            Binding ocLocationBinding = ValueBindingBuilder.bind(ocLocationObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(AdvancedConnectionEditorModel.PROP_OC_OVERRIDE_LOCATION).observe(model)).in(dbc);
            overrideOCObservable.addValueChangeListener(new IValueChangeListener<Boolean>() {

                @Override
                public void handleValueChange(ValueChangeEvent<? extends Boolean> event) {
                    updateOcObservables();
                }
            });
            ocLocationBinding.getValidationStatus().addValueChangeListener(new IValueChangeListener<IStatus>() {

                @Override
                public void handleValueChange(ValueChangeEvent<? extends IStatus> event) {
                    updateOcObservables();
                }
            });
            ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocText)).notUpdatingParticipant().in(dbc);
            Button ocBrowse = new Button(advancedComposite, SWT.PUSH);
            ocBrowse.setText("Browse...");
            GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).applyTo(ocBrowse);
            UIUtils.setDefaultButtonWidth(ocBrowse);
            ocWorkspace.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    PreferenceDialog pd = PreferencesUtil.createPreferenceDialogOn(null, IOpenShiftCoreConstants.OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] {}, null);
                    pd.open();
                    if (!overrideOC.getSelection()) {
                        String ocLoc = OpenShiftCorePreferences.INSTANCE.getOCBinaryLocation();
                        String nullsafe = ocLoc == null ? "" : ocLoc;
                        ocText.setText(nullsafe);
                    }
                    updateOcObservables();
                }
            });
            // Validation here is done via a listener rather than dbc validators
            // because dbc validators will validate in the UI thread, but validation
            // of this field requires a background job.
            ocBrowse.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    FileDialog fd = new FileDialog(ocBrowse.getShell());
                    fd.setText(ocText.getText());
                    IPath p = new Path(ocText.getText());
                    if (p.segmentCount() > 1) {
                        fd.setFilterPath(p.removeLastSegments(1).toOSString());
                    }
                    String result = fd.open();
                    if (result != null) {
                        ocLocationObservable.setValue(result);
                    }
                }
            });
            ValueBindingBuilder.bind(overrideOCObservable).to(WidgetProperties.enabled().observe(ocBrowse)).notUpdatingParticipant().in(dbc);
            ValidationStatusProvider ocValidator = new MultiValidator() {

                public IObservableList getTargets() {
                    WritableList targets = new WritableList();
                    targets.add(ocLocationObservable);
                    targets.add(ocLocationValidity);
                    targets.add(ocVersionValidity);
                    return targets;
                }

                @Override
                protected IStatus validate() {
                    // access all observables that the framework should listen to
                    IStatus ocLocationStatus = ocLocationValidity.getValue();
                    IStatus ocVersionStatus = ocVersionValidity.getValue();
                    IStatus status;
                    if (!ocLocationStatus.isOK()) {
                        status = ocLocationStatus;
                    } else {
                        status = ocVersionStatus;
                    }
                    return status;
                }
            };
            dbc.addValidationStatusProvider(ocValidator);
            ControlDecorationSupport.create(ocValidator, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
        }

        protected GridLayoutFactory adjustAdvancedCompositeLayout(GridLayoutFactory gridLayoutFactory) {
            return gridLayoutFactory.numColumns(3);
        }
    };
    part.createAdvancedGroup(composite, 1);
    this.connectionAdvancedPropertiesProvider = new ConnectionAdvancedPropertiesProvider();
    updateOcObservables();
    return composite;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Label(org.eclipse.swt.widgets.Label) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) Button(org.eclipse.swt.widgets.Button) URLValidator(org.jboss.tools.openshift.internal.ui.validator.URLValidator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DialogAdvancedPart(org.jboss.tools.openshift.internal.common.ui.utils.DialogAdvancedPart) TrimTrailingSlashConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimTrailingSlashConverter) Binding(org.eclipse.core.databinding.Binding) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) Composite(org.eclipse.swt.widgets.Composite) IPath(org.eclipse.core.runtime.IPath) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) WritableList(org.eclipse.core.databinding.observable.list.WritableList) IConnectionAdvancedPropertiesProvider(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel.IConnectionAdvancedPropertiesProvider) FileDialog(org.eclipse.swt.widgets.FileDialog) Link(org.eclipse.swt.widgets.Link)

Example 8 with ValidationStatusProvider

use of org.eclipse.core.databinding.ValidationStatusProvider 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)

Example 9 with ValidationStatusProvider

use of org.eclipse.core.databinding.ValidationStatusProvider in project portfolio by buchen.

the class SecurityTaxonomyPage method recreateTaxonomyPicker.

private void recreateTaxonomyPicker(final Composite taxonomyPicker) {
    // invalid bindings and error messages
    for (ValidationStatusProvider validator : validators) {
        if (validator instanceof Binding)
            bindings.getBindingContext().removeBinding((Binding) validator);
        else
            bindings.getBindingContext().removeValidationStatusProvider(validator);
    }
    validators.clear();
    Composite parent = taxonomyPicker.getParent();
    taxonomyPicker.dispose();
    createTaxonomyPicker(parent);
    parent.layout();
}
Also used : Binding(org.eclipse.core.databinding.Binding) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ValidationStatusProvider(org.eclipse.core.databinding.ValidationStatusProvider)

Aggregations

ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)9 Button (org.eclipse.swt.widgets.Button)4 Iterator (java.util.Iterator)3 IObservable (org.eclipse.core.databinding.observable.IObservable)3 IObservableList (org.eclipse.core.databinding.observable.list.IObservableList)3 Composite (org.eclipse.swt.widgets.Composite)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)3 Binding (org.eclipse.core.databinding.Binding)2 IStatus (org.eclipse.core.runtime.IStatus)2 InvertingBooleanConverter (org.jboss.tools.common.ui.databinding.InvertingBooleanConverter)2 DisableableMultiValitdator (org.jboss.tools.openshift.internal.common.ui.databinding.DisableableMultiValitdator)2 OpenShiftIdentifierValidator (org.jboss.tools.openshift.internal.ui.validator.OpenShiftIdentifierValidator)2 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)1 ChangeEvent (org.eclipse.core.databinding.observable.ChangeEvent)1 IChangeListener (org.eclipse.core.databinding.observable.IChangeListener)1 IStaleListener (org.eclipse.core.databinding.observable.IStaleListener)1 StaleEvent (org.eclipse.core.databinding.observable.StaleEvent)1 IListChangeListener (org.eclipse.core.databinding.observable.list.IListChangeListener)1