Search in sources :

Example 11 with UpdateValueStrategy

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)));
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy)

Example 12 with UpdateValueStrategy

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);
        }
    });
}
Also used : Binding(org.eclipse.core.databinding.Binding) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Text(org.eclipse.swt.widgets.Text)

Example 13 with UpdateValueStrategy

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);
}
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 14 with UpdateValueStrategy

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);
}
Also used : FormLayout(org.eclipse.swt.layout.FormLayout) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) FormDataFactory.startingWith(name.abuchen.portfolio.ui.util.FormDataFactory.startingWith) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Spinner(org.eclipse.swt.widgets.Spinner) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) ComboViewer(org.eclipse.jface.viewers.ComboViewer) MessageFormat(java.text.MessageFormat) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) AbstractWizardPage(name.abuchen.portfolio.ui.wizards.AbstractWizardPage) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) BindingHelper(name.abuchen.portfolio.ui.util.BindingHelper) SWTHelper.widest(name.abuchen.portfolio.ui.util.SWTHelper.widest) FormLayout(org.eclipse.swt.layout.FormLayout) Security(name.abuchen.portfolio.model.Security) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) List(java.util.List) ViewersObservables(org.eclipse.jface.databinding.viewers.ViewersObservables) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Composite(org.eclipse.swt.widgets.Composite) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Spinner(org.eclipse.swt.widgets.Spinner) Label(org.eclipse.swt.widgets.Label) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) Security(name.abuchen.portfolio.model.Security) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) ComboViewer(org.eclipse.jface.viewers.ComboViewer) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 15 with UpdateValueStrategy

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;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IObservableMap(org.eclipse.core.databinding.observable.map.IObservableMap) ObservableListContentProvider(org.eclipse.jface.databinding.viewers.ObservableListContentProvider) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ObservableMapLabelProvider(org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider) IObservableList(org.eclipse.core.databinding.observable.list.IObservableList)

Aggregations

UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)30 Label (org.eclipse.swt.widgets.Label)14 Text (org.eclipse.swt.widgets.Text)13 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)11 Composite (org.eclipse.swt.widgets.Composite)11 DataBindingContext (org.eclipse.core.databinding.DataBindingContext)10 IValidator (org.eclipse.core.databinding.validation.IValidator)7 Button (org.eclipse.swt.widgets.Button)7 ISWTObservableValue (org.eclipse.jface.databinding.swt.ISWTObservableValue)6 IStatus (org.eclipse.core.runtime.IStatus)5 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)4 IEMFValueProperty (org.eclipse.emf.databinding.IEMFValueProperty)4 WidgetProperties (org.eclipse.jface.databinding.swt.WidgetProperties)4 LabelProvider (org.eclipse.jface.viewers.LabelProvider)4 MessageFormat (java.text.MessageFormat)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Messages (name.abuchen.portfolio.ui.Messages)3 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)3 EObject (org.eclipse.emf.ecore.EObject)3