Search in sources :

Example 6 with IValidator

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

the class ApplicationSourceListPage method createLocalTemplateControls.

private IObservableValue createLocalTemplateControls(TabFolder tabContainer, TabFolderTraverseListener tabFolderTraverseListener, IObservableValue useLocalTemplate, DataBindingContext dbc) {
    TabItem localTemplatesTab = new TabItem(tabContainer, SWT.NONE);
    localTemplatesTab.setText("Custom template");
    final Composite parent = new Composite(tabContainer, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(3).margins(10, 10).spacing(6, 2).applyTo(parent);
    Label lbl = new Label(parent, SWT.NONE);
    lbl.setText("Select a local template file or a full URL:");
    GridDataFactory.fillDefaults().span(3, 1).applyTo(lbl);
    // local template file name
    Text txtLocalTemplateFileName = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).span(3, 1).applyTo(txtLocalTemplateFileName);
    IObservableValue localTemplateFilename = WidgetProperties.text(SWT.Modify).observe(txtLocalTemplateFileName);
    IValidator validator = (o -> {
        IStatus status = ValidationStatus.ok();
        if (!OpenshiftUIConstants.URL_VALIDATOR.isValid(o.toString()) && StringUtils.isNotBlank(o.toString()) && !isFile(o.toString())) {
            status = ValidationStatus.error(o + " is not a file");
        }
        // force redraw since removed decorations somehow stay visible, GTK3 bug?
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=478618
        asyncRedraw(parent);
        return status;
    });
    ValueBindingBuilder.bind(localTemplateFilename).validatingBeforeSet(validator).to(BeanProperties.value(IApplicationSourceListPageModel.PROPERTY_LOCAL_APP_SOURCE_FILENAME).observe(model)).in(dbc);
    // browse button
    Button btnBrowseFiles = new Button(parent, SWT.NONE);
    btnBrowseFiles.setText("Browse File System...");
    GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).span(2, 1).grab(true, false).applyTo(btnBrowseFiles);
    btnBrowseFiles.addSelectionListener(onFileSystemBrowseClicked());
    // browse button
    Button btnBrowseWorkspaceFiles = new Button(parent, SWT.NONE);
    btnBrowseWorkspaceFiles.setText("Browse Workspace...");
    GridDataFactory.fillDefaults().align(SWT.END, SWT.CENTER).applyTo(btnBrowseWorkspaceFiles);
    btnBrowseWorkspaceFiles.addSelectionListener(onBrowseWorkspaceClicked());
    UIUtils.setEqualButtonWidth(btnBrowseFiles, btnBrowseWorkspaceFiles);
    localTemplatesTab.setControl(parent);
    tabFolderTraverseListener.bindTabControls(tabContainer.getItemCount() - 1, txtLocalTemplateFileName, btnBrowseFiles, btnBrowseWorkspaceFiles);
    return localTemplateFilename;
}
Also used : TabItem(org.eclipse.swt.widgets.TabItem) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 7 with IValidator

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

Example 8 with IValidator

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

the class ServerSettingsWizardPage method createSourcePathControls.

@SuppressWarnings("unchecked")
private void createSourcePathControls(Composite parent, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
    Label sourcePathLabel = new Label(parent, SWT.NONE);
    sourcePathLabel.setText("Source Path: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(sourcePathLabel);
    Text sourcePathText = new Text(parent, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(sourcePathText);
    Binding sourcePathBinding = ValueBindingBuilder.bind(WidgetProperties.text(SWT.Modify).observe(sourcePathText)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            String path = (String) value;
            if (StringUtils.isEmpty(path)) {
                return ValidationStatus.cancel("Please provide a local path to deploy from.");
            }
            String provideValidPathMessage = "Please provide a valid local path to deploy from.";
            try {
                path = VariablesHelper.replaceVariables(path);
            } catch (OpenShiftCoreException e) {
                String message = org.apache.commons.lang.StringUtils.substringAfter(e.getMessage(), "Exception:");
                return ValidationStatus.error(provideValidPathMessage + "\nError: " + message);
            }
            if (!isReadableFile(path)) {
                return ValidationStatus.error(provideValidPathMessage);
            }
            return ValidationStatus.ok();
        }

        private boolean isReadableFile(String path) {
            return new File(path).canRead();
        }
    }).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_SOURCE_PATH).observe(model)).in(dbc);
    ControlDecorationSupport.create(sourcePathBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    Button browseSourceButton = new Button(parent, SWT.PUSH);
    browseSourceButton.setText("Browse...");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).indent(10, SWT.DEFAULT).applyTo(browseSourceButton);
    browseSourceButton.addSelectionListener(onBrowseSource(browseSourceButton.getShell()));
    Button browseWorkspaceSourceButton = new Button(parent, SWT.PUSH | SWT.READ_ONLY);
    browseWorkspaceSourceButton.setText("Workspace...");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(browseWorkspaceSourceButton);
    browseWorkspaceSourceButton.addSelectionListener(onBrowseWorkspace(browseWorkspaceSourceButton.getShell()));
    UIUtils.setEqualButtonWidth(browseSourceButton, browseWorkspaceSourceButton);
}
Also used : Binding(org.eclipse.core.databinding.Binding) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IStatus(org.eclipse.core.runtime.IStatus) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) OpenShiftCoreException(org.jboss.tools.openshift.common.core.OpenShiftCoreException) File(java.io.File)

Example 9 with IValidator

use of org.eclipse.core.databinding.validation.IValidator in project egit by eclipse.

the class InitDialog method initDataBinding.

private DataBindingContext initDataBinding() {
    DataBindingContext context = new DataBindingContext();
    UpdateValueStrategy noModelToTarget = new UpdateValueStrategy(false, POLICY_ON_REQUEST);
    UpdateValueStrategy developUpdateStrategy = new UpdateValueStrategy();
    developUpdateStrategy.setBeforeSetValidator(new BranchValidator());
    bind(context, noModelToTarget, developUpdateStrategy, DEVELOP_BRANCH_PROPERTY, developText);
    UpdateValueStrategy masterUpdateStrategy = new UpdateValueStrategy();
    masterUpdateStrategy.setBeforeSetValidator(new BranchValidator());
    masterUpdateStrategy.setAfterConvertValidator(new BranchExistsValidator(branchList));
    bind(context, noModelToTarget, masterUpdateStrategy, MASTER_BRANCH_PROPERTY, masterText);
    UpdateValueStrategy prefixTargetToModel = new UpdateValueStrategy();
    prefixTargetToModel.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || !isValidRefName(R_HEADS + value + DUMMY_POSTFIX)) {
                return error(NLS.bind(InitDialog_invalidPrefix, value));
            }
            return Status.OK_STATUS;
        }
    });
    bind(context, noModelToTarget, prefixTargetToModel, FEATURE_BRANCH_PREFIX_PROPERTY, featureText);
    bind(context, noModelToTarget, prefixTargetToModel, RELEASE_BRANCH_PREFIX_PROPERTY, releaseText);
    bind(context, noModelToTarget, prefixTargetToModel, HOTFIX_BRANCH_PREFIX_PROPERTY, hotfixText);
    bind(context, noModelToTarget, prefixTargetToModel, VERSION_TAG_PROPERTY, versionTagText);
    context.updateTargets();
    return context;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IStatus(org.eclipse.core.runtime.IStatus) IValidator(org.eclipse.core.databinding.validation.IValidator) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Example 10 with IValidator

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

the class BindingHelper method bindISINInput.

public final Control bindISINInput(Composite editArea, final String label, String property) {
    Text txtValue = createTextInput(editArea, label, SWT.NONE, 12);
    txtValue.setTextLimit(12);
    // 
    context.bindValue(// 
    WidgetProperties.text(SWT.Modify).observe(txtValue), // 
    BeanProperties.value(property).observe(model), new UpdateValueStrategy().setAfterConvertValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            String v = (String) value;
            return v == null || v.trim().length() == 0 || Isin.isValid(v) ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogNotAValidISIN, label));
        }
    }), null);
    return txtValue;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IValidator(org.eclipse.core.databinding.validation.IValidator) Text(org.eclipse.swt.widgets.Text)

Aggregations

IValidator (org.eclipse.core.databinding.validation.IValidator)12 Text (org.eclipse.swt.widgets.Text)9 Label (org.eclipse.swt.widgets.Label)7 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)6 IStatus (org.eclipse.core.runtime.IStatus)5 Button (org.eclipse.swt.widgets.Button)5 RequiredControlDecorationUpdater (org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater)5 Binding (org.eclipse.core.databinding.Binding)4 Composite (org.eclipse.swt.widgets.Composite)4 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)3 IProject (com.openshift.restclient.model.IProject)1 File (java.io.File)1 MessageFormat (java.text.MessageFormat)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Account (name.abuchen.portfolio.model.Account)1 Client (name.abuchen.portfolio.model.Client)1