Search in sources :

Example 1 with IValidator

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

the class BindingHelper method bindMandatoryStringInput.

public final Control bindMandatoryStringInput(Composite editArea, final String label, String property) {
    Text txtValue = createTextInput(editArea, label);
    // 
    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 ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, 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)

Example 2 with IValidator

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

the class EditSecurityDialog method createUpperArea.

private void createUpperArea(Composite container) {
    Composite header = new Composite(container, SWT.NONE);
    header.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_WHITE));
    header.setLayout(new FormLayout());
    GridDataFactory.fillDefaults().grab(true, false).applyTo(header);
    Label lblName = new Label(header, SWT.NONE);
    lblName.setText(Messages.ColumnName);
    lblName.setBackground(header.getBackground());
    Text name = new Text(header, SWT.BORDER);
    name.setBackground(header.getBackground());
    errorMessage = new Label(header, SWT.NONE);
    errorMessage.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_RED));
    errorMessage.setBackground(header.getBackground());
    Label imageLabel = new Label(header, SWT.NONE);
    imageLabel.setBackground(header.getBackground());
    imageLabel.setImage(Images.BANNER.image());
    // form layout
    FormDataFactory.startingWith(imageLabel).right(new FormAttachment(100));
    // 
    FormDataFactory.startingWith(lblName).left(new FormAttachment(0, 5)).top(// 
    new FormAttachment(0, 10)).thenRight(name).right(new FormAttachment(imageLabel, -10));
    // 
    FormDataFactory.startingWith(errorMessage).left(new FormAttachment(0, 5)).top(new FormAttachment(lblName, 10)).right(new FormAttachment(imageLabel, -10));
    // bind to model
    // 
    bindings.getBindingContext().bindValue(// 
    WidgetProperties.text(SWT.Modify).observe(name), // $NON-NLS-1$
    BeanProperties.value("name").observe(model), new UpdateValueStrategy().setAfterConvertValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            String v = (String) value;
            return v != null && v.trim().length() > 0 ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnName));
        }
    }), null);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Composite(org.eclipse.swt.widgets.Composite) IValidator(org.eclipse.core.databinding.validation.IValidator) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FormAttachment(org.eclipse.swt.layout.FormAttachment)

Example 3 with IValidator

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

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

the class SelectProjectComponentBuilder method build.

public void build(Composite container, DataBindingContext dbc) {
    Label existingProjectLabel = new Label(container, SWT.NONE);
    existingProjectLabel.setText("Eclipse Project: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(existingProjectLabel);
    final Text existingProjectNameText = new Text(container, SWT.BORDER);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).span(hSpan, 1).align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(existingProjectNameText);
    projectNameTextObservable = WidgetProperties.text(SWT.Modify).observe(existingProjectNameText);
    Binding eclipseProjectBinding = ValueBindingBuilder.bind(projectNameTextObservable).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value instanceof String) {
                return ValidationStatus.ok();
            } else if (value == null) {
                if (required) {
                    return ValidationStatus.error("Select an existing project");
                } else if (!StringUtils.isEmpty(existingProjectNameText.getText())) {
                    return ValidationStatus.error(NLS.bind("Project {0} does not exist", existingProjectNameText.getText()));
                }
            }
            return ValidationStatus.ok();
        }
    }).converting(new Converter(String.class, IProject.class) {

        @Override
        public Object convert(Object fromObject) {
            String name = (String) fromObject;
            return ProjectUtils.getProject(name);
        }
    }).to(eclipseProjectObservable).converting(new Converter(IProject.class, String.class) {

        @Override
        public Object convert(Object fromObject) {
            return fromObject == null ? "" : ((IProject) fromObject).getName();
        }
    }).in(dbc);
    ControlDecorationSupport.create(eclipseProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    // project name content assist
    ControlDecoration dec = new ControlDecoration(existingProjectNameText, SWT.TOP | SWT.RIGHT);
    FieldDecoration contentProposalFieldIndicator = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_CONTENT_PROPOSAL);
    dec.setImage(contentProposalFieldIndicator.getImage());
    dec.setDescriptionText("Auto-completion is enabled when you start typing a project name.");
    dec.setShowOnlyOnFocus(true);
    new AutoCompleteField(existingProjectNameText, new TextContentAdapter(), ProjectUtils.getAllAccessibleProjectNames());
    // browse projects
    Button browseProjectsButton = new Button(container, SWT.NONE);
    browseProjectsButton.setText("Browse...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.CENTER).indent(buttonIndent, 0).applyTo(browseProjectsButton);
    UIUtils.setDefaultButtonWidth(browseProjectsButton);
    browseProjectsButton.addSelectionListener(selectionListener);
}
Also used : Binding(org.eclipse.core.databinding.Binding) IStatus(org.eclipse.core.runtime.IStatus) FieldDecoration(org.eclipse.jface.fieldassist.FieldDecoration) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) TextContentAdapter(org.eclipse.jface.fieldassist.TextContentAdapter) AutoCompleteField(org.eclipse.jface.fieldassist.AutoCompleteField) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) ControlDecoration(org.eclipse.jface.fieldassist.ControlDecoration) Converter(org.eclipse.core.databinding.conversion.Converter)

Example 5 with IValidator

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

the class AbstractProjectPage method createProjectControls.

private void createProjectControls(Composite parent, DataBindingContext dbc) {
    Label projectLabel = new Label(parent, SWT.NONE);
    projectLabel.setText("OpenShift project: ");
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).applyTo(projectLabel);
    StructuredViewer projectsViewer = new ComboViewer(parent);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(projectsViewer.getControl());
    final OpenShiftExplorerLabelProvider labelProvider = new OpenShiftExplorerLabelProvider();
    projectsViewer.setContentProvider(new ObservableListContentProvider());
    projectsViewer.setLabelProvider(new ObservableTreeItemLabelProvider());
    projectsViewer.setInput(BeanProperties.list(IProjectPageModel.PROPERTY_PROJECT_ITEMS).observe(model));
    projectsViewer.setComparator(ProjectViewerComparator.createProjectTreeSorter(labelProvider));
    model.setProjectsComparator(new ProjectViewerComparator(labelProvider).asItemComparator());
    IObservableValue selectedProjectObservable = ViewerProperties.singleSelection().observe(projectsViewer);
    Binding selectedProjectBinding = ValueBindingBuilder.bind(selectedProjectObservable).converting(new ObservableTreeItem2ModelConverter(IProject.class)).validatingAfterConvert(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value instanceof IProject) {
                return ValidationStatus.ok();
            }
            return ValidationStatus.cancel("Please choose an OpenShift project.");
        }
    }).to(BeanProperties.value(IProjectPageModel.PROPERTY_PROJECT).observe(model)).converting(new Model2ObservableTreeItemConverter(null)).in(dbc);
    ControlDecorationSupport.create(selectedProjectBinding, SWT.LEFT | SWT.TOP, null, new RequiredControlDecorationUpdater(true));
    IObservableValue connectionObservable = BeanProperties.value(IProjectPageModel.PROPERTY_CONNECTION).observe(model);
    DataBindingUtils.addDisposableValueChangeListener(onConnectionChanged(), connectionObservable, projectsViewer.getControl());
    Button newProjectButton = new Button(parent, SWT.PUSH);
    newProjectButton.setText("New...");
    GridDataFactory.fillDefaults().align(SWT.LEFT, SWT.FILL).applyTo(newProjectButton);
    UIUtils.setDefaultButtonWidth(newProjectButton);
    newProjectButton.addSelectionListener(onNewProjectClicked());
}
Also used : Binding(org.eclipse.core.databinding.Binding) ObservableTreeItemLabelProvider(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItemLabelProvider) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) Label(org.eclipse.swt.widgets.Label) ObservableTreeItem2ModelConverter(org.jboss.tools.openshift.internal.ui.treeitem.ObservableTreeItem2ModelConverter) ProjectViewerComparator(org.jboss.tools.openshift.internal.ui.comparators.ProjectViewerComparator) IProject(com.openshift.restclient.model.IProject) RequiredControlDecorationUpdater(org.jboss.tools.openshift.internal.common.ui.databinding.RequiredControlDecorationUpdater) IValidator(org.eclipse.core.databinding.validation.IValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Model2ObservableTreeItemConverter(org.jboss.tools.openshift.internal.ui.treeitem.Model2ObservableTreeItemConverter) Button(org.eclipse.swt.widgets.Button) OpenShiftExplorerLabelProvider(org.jboss.tools.openshift.internal.ui.explorer.OpenShiftExplorerLabelProvider) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

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