Search in sources :

Example 1 with TrimmingStringConverter

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

the class OAuthDetailView method bindWidgetsToInternalModel.

private void bindWidgetsToInternalModel(DataBindingContext dbc) {
    IValidator validator = new RequiredStringValidator("token");
    this.tokenBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(tokenText)).converting(new TrimmingStringConverter()).validatingAfterConvert(validator).to(tokenObservable).validatingBeforeSet(validator).in(dbc);
    ControlDecorationSupport.create(tokenBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, tokenObservable, tokenText);
}
Also used : RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) IValidator(org.eclipse.core.databinding.validation.IValidator) RequiredStringValidator(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredStringValidator)

Example 2 with TrimmingStringConverter

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

the class BasicAuthenticationDetailView method bindWidgetsToInternalModel.

private void bindWidgetsToInternalModel(DataBindingContext dbc) {
    // username
    this.usernameBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(usernameText)).converting(new TrimmingStringConverter()).validatingAfterConvert(new RequiredStringValidator("v3 username")).to(usernameObservable).in(dbc);
    ControlDecorationSupport.create(usernameBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, usernameObservable, usernameText);
    // password
    this.passwordBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(passwordText)).converting(new TrimmingStringConverter()).validatingAfterConvert(new RequiredStringValidator("v3 password")).to(passwordObservable).in(dbc);
    ControlDecorationSupport.create(passwordBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater());
    org.jboss.tools.common.ui.databinding.DataBindingUtils.addDisposableValueChangeListener(changeListener, passwordObservable, passwordText);
    connectionAuthProvider = new ConnectionAuthenticationProvider();
}
Also used : RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) IConnectionAuthenticationProvider(org.jboss.tools.openshift.internal.common.ui.connection.ConnectionWizardPageModel.IConnectionAuthenticationProvider) RequiredStringValidator(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredStringValidator)

Example 3 with TrimmingStringConverter

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

the class DeployImagePage method createImageNameControls.

private void createImageNameControls(final Composite parent, final DataBindingContext dbc) {
    // Image
    final Label imageNameLabel = new Label(parent, SWT.NONE);
    imageNameLabel.setText("Image Name: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(imageNameLabel);
    final Text imageNameText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(imageNameText);
    final IObservableValue<String> imageNameTextObservable = WidgetProperties.text(SWT.Modify).observeDelayed(500, imageNameText);
    final IObservableValue<String> imageNameObservable = BeanProperties.value(IDeployImagePageModel.PROPERTY_IMAGE_NAME).observe(model);
    Binding imageBinding = ValueBindingBuilder.bind(imageNameTextObservable).converting(new TrimmingStringConverter()).validatingAfterConvert(new DockerImageValidator()).to(imageNameObservable).in(dbc);
    ControlDecorationSupport.create(imageBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    imageNameProposalAdapter = new ContentProposalAdapter(imageNameText, // move the cursor to the end of the selected value
    new TextContentAdapter() {

        @Override
        public void insertControlContents(Control control, String text, int cursorPosition) {
            final Text imageNameText = (Text) control;
            final Point selection = imageNameText.getSelection();
            imageNameText.setText(text);
            selection.x = text.length();
            selection.y = selection.x;
            imageNameText.setSelection(selection);
        }
    }, getImageNameContentProposalProvider(imageNameText), null, null);
    // List local Docker images
    Button btnDockerBrowse = new Button(parent, SWT.NONE);
    btnDockerBrowse.setText("Browse...");
    btnDockerBrowse.setToolTipText("Look-up an image by browsing the Docker daemon");
    btnDockerBrowse.addSelectionListener(onBrowseImage());
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerBrowse);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerBrowse)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
    // search on Docker registry (Docker Hub)
    Button btnDockerSearch = new Button(parent, SWT.NONE);
    btnDockerSearch.setText("Search...");
    btnDockerSearch.setToolTipText("Search an image on the Docker registry");
    btnDockerSearch.addSelectionListener(onSearchImage(imageNameText));
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(btnDockerSearch);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(btnDockerSearch)).notUpdatingParticipant().to(BeanProperties.value(IDeployImagePageModel.PROPERTY_DOCKER_CONNECTION).observe(model)).converting(new IsNotNull2BooleanConverter()).in(dbc);
}
Also used : Binding(org.eclipse.core.databinding.Binding) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Point(org.eclipse.swt.graphics.Point) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) ContentProposalAdapter(org.eclipse.jface.fieldassist.ContentProposalAdapter) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) ResourceNameControl(org.jboss.tools.openshift.internal.ui.wizard.common.ResourceNameControl) Control(org.eclipse.swt.widgets.Control) Button(org.eclipse.swt.widgets.Button) IsNotNull2BooleanConverter(org.jboss.tools.openshift.internal.common.ui.databinding.IsNotNull2BooleanConverter) DockerImageValidator(org.jboss.tools.openshift.internal.ui.validator.DockerImageValidator)

Example 4 with TrimmingStringConverter

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

the class ServicesAndRoutingPage method doCreateControls.

@Override
protected void doCreateControls(Composite parent, DataBindingContext dbc) {
    GridLayoutFactory.fillDefaults().margins(10, 10).applyTo(parent);
    createExposedPortsControl(parent, dbc);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).applyTo(new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL));
    // routing
    Composite routingContainer = new Composite(parent, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(routingContainer);
    GridLayoutFactory.fillDefaults().margins(6, 6).numColumns(2).applyTo(routingContainer);
    Button btnAddRoute = new Button(routingContainer, SWT.CHECK);
    btnAddRoute.setText("Add Route");
    btnAddRoute.setToolTipText("Adding a route to the service will make the image accessible\noutside of the OpenShift cluster on all the available service ports. \nYou can target a specific port by editing the route later.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(false, false).span(2, 1).applyTo(btnAddRoute);
    final IObservableValue<Boolean> addRouteModelObservable = BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model);
    ValueBindingBuilder.bind(WidgetProperties.selection().observe(btnAddRoute)).to(addRouteModelObservable).in(dbc);
    Label labelRouteHostname = new Label(routingContainer, SWT.NONE);
    labelRouteHostname.setText("Hostname:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(labelRouteHostname);
    Text textRouteHostname = new Text(routingContainer, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(textRouteHostname);
    ValueBindingBuilder.bind(WidgetProperties.enabled().observe(textRouteHostname)).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ADD_ROUTE).observe(model)).in(dbc);
    final IObservableValue<String> routeHostnameObservable = WidgetProperties.text(SWT.Modify).observe(textRouteHostname);
    ValueBindingBuilder.bind(routeHostnameObservable).converting(new TrimmingStringConverter()).to(BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTE_HOSTNAME).observe(model)).in(dbc);
    MultiValidator validator = new MultiValidator() {

        @Override
        protected IStatus validate() {
            IStatus status = ValidationStatus.ok();
            boolean isAddRoute = addRouteModelObservable.getValue();
            String hostName = routeHostnameObservable.getValue();
            final IObservableList<IServicePort> portsObservable = BeanProperties.list(IServiceAndRoutingPageModel.PROPERTY_SERVICE_PORTS).observe(model);
            final IServicePort routingPort = (IServicePort) BeanProperties.value(IServiceAndRoutingPageModel.PROPERTY_ROUTING_PORT).observe(model).getValue();
            if (isAddRoute) {
                if (StringUtils.isBlank(hostName)) {
                    status = ValidationStatus.info(NLS.bind(OpenShiftUIMessages.EmptyHostNameErrorMessage, hostName));
                } else if (!DomainValidator.getInstance(true).isValid(hostName)) {
                    status = ValidationStatus.error(NLS.bind(OpenShiftUIMessages.InvalidHostNameErrorMessage, hostName));
                }
                if (!status.matches(IStatus.ERROR) && isAddRoute && (portsObservable.size() > 1) && (routingPort == null)) {
                    if (status.matches(IStatus.INFO)) {
                        status = ValidationStatus.info(status.getMessage() + "\n " + OpenShiftUIMessages.RoundRobinRoutingMessage);
                    } else {
                        status = ValidationStatus.info(OpenShiftUIMessages.RoundRobinRoutingMessage);
                    }
                }
            }
            return status;
        }
    };
    dbc.addValidationStatusProvider(validator);
    ControlDecorationSupport.create(validator, SWT.LEFT | SWT.TOP);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) TrimmingStringConverter(org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter) IServicePort(com.openshift.restclient.model.IServicePort) Button(org.eclipse.swt.widgets.Button)

Example 5 with TrimmingStringConverter

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

Aggregations

TrimmingStringConverter (org.jboss.tools.openshift.internal.common.ui.databinding.TrimmingStringConverter)5 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)4 Button (org.eclipse.swt.widgets.Button)3 Label (org.eclipse.swt.widgets.Label)3 Text (org.eclipse.swt.widgets.Text)3 Binding (org.eclipse.core.databinding.Binding)2 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)2 IStatus (org.eclipse.core.runtime.IStatus)2 Composite (org.eclipse.swt.widgets.Composite)2 RequiredStringValidator (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredStringValidator)2 IServicePort (com.openshift.restclient.model.IServicePort)1 ValidationStatusProvider (org.eclipse.core.databinding.ValidationStatusProvider)1 WritableList (org.eclipse.core.databinding.observable.list.WritableList)1 IValidator (org.eclipse.core.databinding.validation.IValidator)1 IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 ContentProposalAdapter (org.eclipse.jface.fieldassist.ContentProposalAdapter)1 TextContentAdapter (org.eclipse.jface.fieldassist.TextContentAdapter)1 GridLayoutFactory (org.eclipse.jface.layout.GridLayoutFactory)1 PreferenceDialog (org.eclipse.jface.preference.PreferenceDialog)1