Search in sources :

Example 6 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project statecharts by Yakindu.

the class StatechartPropertySection method bindDomainCombo.

protected void bindDomainCombo(EMFDataBindingContext context) {
    IEMFValueProperty property = EMFEditProperties.value(TransactionUtil.getEditingDomain(eObject), BasePackage.Literals.DOMAIN_ELEMENT__DOMAIN_ID);
    IViewerObservableValue observeSingleSelection = ViewersObservables.observeSingleSelection(domainCombo);
    UpdateValueStrategy modelToTarget = new UpdateValueStrategy() {

        @Override
        public Object convert(Object value) {
            return ((IDomain) value).getDomainID();
        }
    };
    UpdateValueStrategy targetToModel = new UpdateValueStrategy() {

        @Override
        public Object convert(Object value) {
            return DomainRegistry.getDomain((String) value);
        }
    };
    context.bindValue(observeSingleSelection, property.observe(eObject), modelToTarget, targetToModel);
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IDomain(org.yakindu.sct.domain.extension.IDomain) EObject(org.eclipse.emf.ecore.EObject) IEMFValueProperty(org.eclipse.emf.databinding.IEMFValueProperty) IViewerObservableValue(org.eclipse.jface.databinding.viewers.IViewerObservableValue)

Example 7 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project statecharts by Yakindu.

the class StatechartPropertySection method bindSpecificationControl.

protected void bindSpecificationControl(EMFDataBindingContext context) {
    IEMFValueProperty modelProperty = EMFEditProperties.value(TransactionUtil.getEditingDomain(eObject), SGraphPackage.Literals.SPECIFICATION_ELEMENT__SPECIFICATION);
    ISWTObservableValue uiProperty = WidgetProperties.text(SWT.FocusOut).observe(textControl);
    context.bindValue(uiProperty, modelProperty.observe(eObject), null, new UpdateValueStrategy() {

        @Override
        protected IStatus doSet(IObservableValue observableValue, Object value) {
            if (getCompletionProposalAdapter() != null && !getCompletionProposalAdapter().isProposalPopupOpen())
                return super.doSet(observableValue, value);
            return Status.OK_STATUS;
        }
    });
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IStatus(org.eclipse.core.runtime.IStatus) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) EObject(org.eclipse.emf.ecore.EObject) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) IEMFValueProperty(org.eclipse.emf.databinding.IEMFValueProperty)

Example 8 with UpdateValueStrategy

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

the class BindingHelper method bindDatePicker.

public final void bindDatePicker(Composite editArea, String label, String property) {
    Label l = new Label(editArea, SWT.NONE);
    l.setText(label);
    DatePicker boxDate = new DatePicker(editArea);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(boxDate.getControl());
    context.bindValue(new SimpleDateTimeDateSelectionProperty().observe(boxDate.getControl()), BeanProperties.value(property).observe(model), // 
    new UpdateValueStrategy().setAfterConvertValidator(value -> {
        return value != null ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, label));
    }), null);
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) FontMetrics(org.eclipse.swt.graphics.FontMetrics) IValidator(org.eclipse.core.databinding.validation.IValidator) ISWTObservableValue(org.eclipse.jface.databinding.swt.ISWTObservableValue) Spinner(org.eclipse.swt.widgets.Spinner) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) FocusEvent(org.eclipse.swt.events.FocusEvent) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GC(org.eclipse.swt.graphics.GC) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Isin(name.abuchen.portfolio.util.Isin) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) IConverter(org.eclipse.core.databinding.conversion.IConverter) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) AggregateValidationStatus(org.eclipse.core.databinding.AggregateValidationStatus) Text(org.eclipse.swt.widgets.Text) Button(org.eclipse.swt.widgets.Button) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Collectors(java.util.stream.Collectors) List(java.util.List) PropertyChangeListener(java.beans.PropertyChangeListener) ViewersObservables(org.eclipse.jface.databinding.viewers.ViewersObservables) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) SWT(org.eclipse.swt.SWT) PropertyChangeSupport(java.beans.PropertyChangeSupport) FocusAdapter(org.eclipse.swt.events.FocusAdapter) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Control(org.eclipse.swt.widgets.Control) PojoProperties(org.eclipse.core.databinding.beans.PojoProperties) Label(org.eclipse.swt.widgets.Label)

Example 9 with UpdateValueStrategy

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

the class BindingHelper method bindComboViewer.

public final ComboViewer bindComboViewer(Composite editArea, String label, String property, IBaseLabelProvider labelProvider, IValidator validator, Object input) {
    Label l = new Label(editArea, SWT.NONE);
    l.setText(label);
    ComboViewer combo = new ComboViewer(editArea, SWT.READ_ONLY);
    combo.setContentProvider(ArrayContentProvider.getInstance());
    combo.setLabelProvider(labelProvider);
    combo.setInput(input);
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(combo.getControl());
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    if (validator != null)
        strategy.setAfterConvertValidator(validator);
    // 
    context.bindValue(// 
    ViewersObservables.observeSingleSelection(combo), BeanProperties.value(property).observe(model), strategy, null);
    return combo;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Label(org.eclipse.swt.widgets.Label)

Example 10 with UpdateValueStrategy

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

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