Search in sources :

Example 1 with GitReferenceValidator

use of org.jboss.tools.openshift.internal.ui.validator.GitReferenceValidator in project jbosstools-openshift by jbosstools.

the class BuildConfigPage method createSourceControls.

@SuppressWarnings({ "unchecked" })
private void createSourceControls(Composite root, DataBindingContext dbc) {
    Composite parent = new Composite(root, SWT.NONE);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(parent);
    GridLayoutFactory.fillDefaults().numColumns(3).applyTo(parent);
    // url
    Label gitUrlLabel = new Label(parent, SWT.NONE);
    gitUrlLabel.setText("Git Repository URL:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitUrlLabel);
    final Text gitUrlText = new Text(parent, SWT.BORDER);
    gitUrlText.setToolTipText("The URL to the Git repository.");
    // TODO add 'try it' link here
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitUrlText);
    Binding gitUrlBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observeDelayed(500, gitUrlText)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (UrlUtils.isValid((String) value)) {
                return Status.OK_STATUS;
            }
            return ValidationStatus.error("A valid URL to a Git repository is required");
        }
    }).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REPOSITORY_URL).observe(model)).in(dbc);
    ControlDecorationSupport.create(gitUrlBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // reference
    Label gitReferenceLabel = new Label(parent, SWT.NONE);
    gitReferenceLabel.setText("Git Reference:");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(gitReferenceLabel);
    gitReferenceLabel.setToolTipText("Optional branch, tag, or commit.");
    final Text gitReferenceText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(gitReferenceText);
    IObservableValue gitReferenceTextObservable = WidgetProperties.text(SWT.Modify).observe(gitReferenceText);
    GitReferenceValidator validator = new GitReferenceValidator(gitReferenceTextObservable);
    Binding gitReferenceBinding = ValueBindingBuilder.bind(gitReferenceTextObservable).validatingAfterConvert(validator).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_GIT_REFERENCE).observe(model)).in(dbc);
    dbc.addValidationStatusProvider(validator);
    ControlDecorationSupport.create(gitReferenceBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // context dir
    Label contextDirLabel = new Label(parent, SWT.NONE);
    contextDirLabel.setText("Context Directory:");
    contextDirLabel.setToolTipText("Optional subdirectory for the application source code, used as the context directory for the build.");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(false, false).applyTo(contextDirLabel);
    final Text contextDirText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(2, 1).applyTo(contextDirText);
    ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(contextDirText)).to(BeanProperties.value(IBuildConfigPageModel.PROPERTY_CONTEXT_DIR).observe(model)).in(dbc);
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) IValidator(org.eclipse.core.databinding.validation.IValidator) Label(org.eclipse.swt.widgets.Label) GitReferenceValidator(org.jboss.tools.openshift.internal.ui.validator.GitReferenceValidator) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Aggregations

Binding (org.eclipse.core.databinding.Binding)1 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)1 IValidator (org.eclipse.core.databinding.validation.IValidator)1 IStatus (org.eclipse.core.runtime.IStatus)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Text (org.eclipse.swt.widgets.Text)1 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)1 GitReferenceValidator (org.jboss.tools.openshift.internal.ui.validator.GitReferenceValidator)1