use of org.eclipse.core.databinding.UpdateValueStrategy in project portfolio by buchen.
the class BindingHelper method bindMandatoryDecimalInput.
private void bindMandatoryDecimalInput(final String label, String property, Text txtValue, Values<?> type) {
StringToCurrencyConverter converter = new StringToCurrencyConverter(type);
UpdateValueStrategy input2model = //
new UpdateValueStrategy().setAfterGetValidator(//
converter).setConverter(//
converter).setAfterConvertValidator(value -> {
Long v = (Long) value;
return v != null && v.longValue() > 0 ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, label));
});
//
context.bindValue(//
WidgetProperties.text(SWT.Modify).observe(txtValue), //
BeanProperties.value(property).observe(model), // ,
input2model, new UpdateValueStrategy().setConverter(new CurrencyToStringConverter(type)));
}
use of org.eclipse.core.databinding.UpdateValueStrategy in project portfolio by buchen.
the class AttributesPage method addAttributeBlock.
private void addAttributeBlock(Composite container, final AttributeDesignation attribute) {
// label
final Label label = new Label(container, SWT.NONE);
label.setText(attribute.getType().getName());
// input
final Text value = new Text(container, SWT.BORDER);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(value);
// delete button
final Button deleteButton = new Button(container, SWT.PUSH);
deleteButton.setImage(Images.REMOVE.image());
// model binding
ToAttributeObjectConverter input2model = new ToAttributeObjectConverter(attribute);
final Binding binding = //
bindings.getBindingContext().bindValue(//
WidgetProperties.text(SWT.Modify).observe(value), // $NON-NLS-1$
BeanProperties.value("value").observe(attribute), new UpdateValueStrategy().setAfterGetValidator(input2model).setConverter(input2model), new UpdateValueStrategy().setConverter(new ToAttributeStringConverter(attribute)));
// delete selection listener
deleteButton.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
model.getAttributes().remove(attribute);
bindings.getBindingContext().removeBinding(binding);
Composite parent = deleteButton.getParent();
label.dispose();
value.dispose();
deleteButton.dispose();
parent.getParent().layout(true);
}
});
}
use of org.eclipse.core.databinding.UpdateValueStrategy 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.UpdateValueStrategy in project portfolio by buchen.
the class SelectSplitPage method createControl.
@Override
public void createControl(Composite parent) {
Composite container = new Composite(parent, SWT.NONE);
setControl(container);
container.setLayout(new FormLayout());
Label labelSecurity = new Label(container, SWT.NONE);
labelSecurity.setText(Messages.ColumnSecurity);
List<Security> securities = model.getClient().getActiveSecurities();
if (model.getSecurity() != null && !securities.contains(model.getSecurity()))
securities.add(0, model.getSecurity());
ComboViewer comboSecurity = new ComboViewer(container, SWT.READ_ONLY);
comboSecurity.setContentProvider(ArrayContentProvider.getInstance());
comboSecurity.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
return ((Security) element).getName();
}
});
comboSecurity.setInput(securities);
Label labelExDate = new Label(container, SWT.NONE);
labelExDate.setText(Messages.ColumnExDate);
DatePicker boxExDate = new DatePicker(container);
Label labelSplit = new Label(container, SWT.NONE);
labelSplit.setText(Messages.SplitWizardLabelSplit);
Spinner spinnerNewShares = new Spinner(container, SWT.BORDER);
spinnerNewShares.setMinimum(1);
spinnerNewShares.setMaximum(1000000);
spinnerNewShares.setSelection(1);
spinnerNewShares.setIncrement(1);
spinnerNewShares.setFocus();
Label labelColon = new Label(container, SWT.NONE);
labelColon.setText(Messages.SplitWizardLabelNewForOld);
Spinner spinnerOldShares = new Spinner(container, SWT.BORDER);
spinnerOldShares.setMinimum(1);
spinnerOldShares.setMaximum(1000000);
spinnerOldShares.setSelection(1);
spinnerOldShares.setIncrement(1);
// form layout data
int labelWidth = widest(labelSecurity, labelExDate, labelSplit);
//
startingWith(comboSecurity.getControl(), labelSecurity).thenBelow(boxExDate.getControl()).label(//
labelExDate).thenBelow(spinnerNewShares).label(labelSplit).thenRight(labelColon).thenRight(spinnerOldShares);
startingWith(labelSecurity).width(labelWidth);
// model binding
DataBindingContext context = bindings.getBindingContext();
context.bindValue(ViewersObservables.observeSingleSelection(comboSecurity), BeanProperties.value("security").observe(model), null, // $NON-NLS-1$
null);
//
context.bindValue(//
new SimpleDateTimeDateSelectionProperty().observe(boxExDate.getControl()), // $NON-NLS-1$
BeanProperties.value("exDate").observe(model), //
new UpdateValueStrategy().setAfterConvertValidator(value -> {
return value != null ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnExDate));
}), null);
final ISWTObservableValue observeNewShares = WidgetProperties.selection().observe(spinnerNewShares);
// $NON-NLS-1$
context.bindValue(observeNewShares, BeanProperties.value("newShares").observe(model));
final ISWTObservableValue observeOldShares = WidgetProperties.selection().observe(spinnerOldShares);
// $NON-NLS-1$
context.bindValue(observeOldShares, BeanProperties.value("oldShares").observe(model));
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
Object newShares = observeNewShares.getValue();
Object oldShares = observeOldShares.getValue();
return newShares.equals(oldShares) ? ValidationStatus.error(Messages.SplitWizardErrorNewAndOldMustNotBeEqual) : ValidationStatus.ok();
}
};
context.addValidationStatusProvider(validator);
}
use of org.eclipse.core.databinding.UpdateValueStrategy in project InformationSystem by ObeoNetwork.
the class ImportLibraryIntoProjectFileSelectionPage method initDataBindings.
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
IObservableMap observeMap = PojoObservables.observeMap(listContentProvider.getKnownElements(), ModelingProject.class, "project.name");
comboViewer.setLabelProvider(new ObservableMapLabelProvider(observeMap));
comboViewer.setContentProvider(listContentProvider);
//
IObservableList modelingProjectsWizardgetModelObserveList = PojoProperties.list("modelingProjects").observe(wizard.getModel());
comboViewer.setInput(modelingProjectsWizardgetModelObserveList);
//
IObservableValue observeTextTxtMarFileObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtMarFile);
IObservableValue filepathWizardgetModelObserveValue = PojoProperties.value("filepath").observe(wizard.getModel());
bindingContext.bindValue(observeTextTxtMarFileObserveWidget, filepathWizardgetModelObserveValue, null, null);
//
IObservableValue observeTextTxtProjectIdObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtProjectId);
IObservableValue projectIDWizardgetModelObserveValue = PojoProperties.value("projectID").observe(wizard.getModel());
bindingContext.bindValue(observeTextTxtProjectIdObserveWidget, projectIDWizardgetModelObserveValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
//
IObservableValue observeTextTxtVersionObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtVersion);
IObservableValue versionWizardgetModelObserveValue = PojoProperties.value("version").observe(wizard.getModel());
bindingContext.bindValue(observeTextTxtVersionObserveWidget, versionWizardgetModelObserveValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
//
IObservableValue observeTextTxtCommentObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtComment);
IObservableValue commentWizardgetModelObserveValue = PojoProperties.value("comment").observe(wizard.getModel());
bindingContext.bindValue(observeTextTxtCommentObserveWidget, commentWizardgetModelObserveValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
//
IObservableValue observeTextTxtCreationDateObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtCreationDate);
IObservableValue creationDateWizardgetModelObserveValue = PojoProperties.value("creationDate").observe(wizard.getModel());
bindingContext.bindValue(observeTextTxtCreationDateObserveWidget, creationDateWizardgetModelObserveValue, new UpdateValueStrategy(UpdateValueStrategy.POLICY_NEVER), null);
//
IObservableValue observeSingleSelectionComboViewer = ViewerProperties.singleSelection().observe(comboViewer);
IObservableValue modelingProjectWizardgetModelObserveValue = PojoProperties.value("modelingProject").observe(wizard.getModel());
bindingContext.bindValue(observeSingleSelectionComboViewer, modelingProjectWizardgetModelObserveValue, null, null);
//
return bindingContext;
}
Aggregations