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;
}
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);
}
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);
}
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);
}
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());
}
Aggregations