Search in sources :

Example 21 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project egit by eclipse.

the class InitDialog method initDataBinding.

private DataBindingContext initDataBinding() {
    DataBindingContext context = new DataBindingContext();
    UpdateValueStrategy noModelToTarget = new UpdateValueStrategy(false, POLICY_ON_REQUEST);
    UpdateValueStrategy developUpdateStrategy = new UpdateValueStrategy();
    developUpdateStrategy.setBeforeSetValidator(new BranchValidator());
    bind(context, noModelToTarget, developUpdateStrategy, DEVELOP_BRANCH_PROPERTY, developText);
    UpdateValueStrategy masterUpdateStrategy = new UpdateValueStrategy();
    masterUpdateStrategy.setBeforeSetValidator(new BranchValidator());
    masterUpdateStrategy.setAfterConvertValidator(new BranchExistsValidator(branchList));
    bind(context, noModelToTarget, masterUpdateStrategy, MASTER_BRANCH_PROPERTY, masterText);
    UpdateValueStrategy prefixTargetToModel = new UpdateValueStrategy();
    prefixTargetToModel.setBeforeSetValidator(new IValidator() {

        @Override
        public IStatus validate(Object value) {
            if (value == null || !isValidRefName(R_HEADS + value + DUMMY_POSTFIX)) {
                return error(NLS.bind(InitDialog_invalidPrefix, value));
            }
            return Status.OK_STATUS;
        }
    });
    bind(context, noModelToTarget, prefixTargetToModel, FEATURE_BRANCH_PREFIX_PROPERTY, featureText);
    bind(context, noModelToTarget, prefixTargetToModel, RELEASE_BRANCH_PREFIX_PROPERTY, releaseText);
    bind(context, noModelToTarget, prefixTargetToModel, HOTFIX_BRANCH_PREFIX_PROPERTY, hotfixText);
    bind(context, noModelToTarget, prefixTargetToModel, VERSION_TAG_PROPERTY, versionTagText);
    context.updateTargets();
    return context;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) IStatus(org.eclipse.core.runtime.IStatus) IValidator(org.eclipse.core.databinding.validation.IValidator) DataBindingContext(org.eclipse.core.databinding.DataBindingContext)

Example 22 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project mylyn.docs by eclipse.

the class MainPage method initDataBindings.

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    // 
    IObservableValue textObserveTextObserveWidget = SWTObservables.observeText(titleText, SWT.Modify);
    // $NON-NLS-1$
    final IObservableValue beanTitleObserveValue = PojoObservables.observeValue(bean, "title");
    UpdateValueStrategy titleStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    titleStrategy.setBeforeSetValidator(new StringValidator("A title must be specified", titleText));
    bindingContext.bindValue(textObserveTextObserveWidget, beanTitleObserveValue, titleStrategy, null);
    // 
    IObservableValue text_3ObserveTextObserveWidget = SWTObservables.observeText(authorText, SWT.Modify);
    // $NON-NLS-1$
    final IObservableValue beanCreatorObserveValue = PojoObservables.observeValue(bean, "creator");
    UpdateValueStrategy authorStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    authorStrategy.setBeforeSetValidator(new StringValidator("An author must be specified", authorText));
    bindingContext.bindValue(text_3ObserveTextObserveWidget, beanCreatorObserveValue, authorStrategy, null);
    // 
    IObservableValue dateTimeObserveSelectionObserveWidget = SWTObservables.observeSelection(dateTime);
    // $NON-NLS-1$
    final IObservableValue beanPublicationDateObserveValue = PojoObservables.observeValue(bean, "publicationDate");
    bindingContext.bindValue(dateTimeObserveSelectionObserveWidget, beanPublicationDateObserveValue, null, null);
    // 
    IObservableValue text_4ObserveTextObserveWidget = SWTObservables.observeText(identifierText, SWT.Modify);
    // $NON-NLS-1$
    final IObservableValue beanIdentifierObserveValue = PojoObservables.observeValue(bean, "identifier");
    UpdateValueStrategy identifierStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    identifierStrategy.setBeforeSetValidator(new StringValidator("An identifier must be specified", identifierText));
    bindingContext.bindValue(text_4ObserveTextObserveWidget, beanIdentifierObserveValue, identifierStrategy, null);
    // 
    IObservableValue schemeTextObserveTextObserveWidget = SWTObservables.observeText(schemeText);
    // $NON-NLS-1$
    final IObservableValue beanIdSchemeObserveValue = PojoObservables.observeValue(bean, "scheme");
    UpdateValueStrategy schemeStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    schemeStrategy.setBeforeSetValidator(new StringValidator("An identifier scheme must be specified", schemeText));
    bindingContext.bindValue(schemeTextObserveTextObserveWidget, beanIdSchemeObserveValue, schemeStrategy, null);
    // 
    IObservableValue text_1ObserveTextObserveWidget = SWTObservables.observeText(copyrightText, SWT.Modify);
    // $NON-NLS-1$
    final IObservableValue beanRightsObserveValue = PojoObservables.observeValue(bean, "rights");
    UpdateValueStrategy rightsStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    rightsStrategy.setBeforeSetValidator(new StringValidator("Rights must be specified", copyrightText));
    bindingContext.bindValue(text_1ObserveTextObserveWidget, beanRightsObserveValue, rightsStrategy, null);
    // 
    IObservableValue comboObserveTextObserveWidget = SWTObservables.observeText(combo);
    // $NON-NLS-1$
    final IObservableValue beanLanguageObserveValue = PojoObservables.observeValue(bean, "language");
    UpdateValueStrategy languageStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    languageStrategy.setBeforeSetValidator(new StringValidator("A language must be specified", combo));
    bindingContext.bindValue(comboObserveTextObserveWidget, beanLanguageObserveValue, languageStrategy, null);
    // 
    IObservableValue subjectTextObserveTextObserveWidget = SWTObservables.observeText(subjectText, SWT.Modify);
    // $NON-NLS-1$
    final IObservableValue beanSubjectObserveValue = PojoObservables.observeValue(bean, "subject");
    UpdateValueStrategy subjectStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    // $NON-NLS-1$
    subjectStrategy.setBeforeSetValidator(new StringValidator("A subject must be specified", subjectText));
    bindingContext.bindValue(subjectTextObserveTextObserveWidget, beanSubjectObserveValue, subjectStrategy, null);
    // 
    IObservableValue coverObserveTextObserveWidget = SWTObservables.observeText(coverText, SWT.Modify);
    // $NON-NLS-1$
    IObservableValue beanCoverObserveValue = PojoObservables.observeValue(bean, "cover");
    UpdateValueStrategy coverStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    coverStrategy.setBeforeSetValidator(new FileValidator("The cover image must be a valid image file of type PNG, SVG or JPEG.", coverText, new String[] { // $NON-NLS-1$
    ".png", ".svg", ".jpeg", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    ".jpg" }));
    bindingContext.bindValue(coverObserveTextObserveWidget, beanCoverObserveValue, coverStrategy, null);
    // 
    IObservableValue styleSheetTextObserveTextObserveWidget = SWTObservables.observeText(styleSheetText, SWT.Modify);
    // $NON-NLS-1$
    IObservableValue beanStyleSheetObserveValue = PojoObservables.observeValue(bean, "styleSheet");
    UpdateValueStrategy styleSheetStrategy = new UpdateValueStrategy(UpdateValueStrategy.POLICY_UPDATE);
    styleSheetStrategy.setBeforeSetValidator(new // $NON-NLS-1$
    FileValidator(// $NON-NLS-1$
    "The style sheet must be a valid CSS file.", styleSheetText, // $NON-NLS-1$
    new String[] { ".css" }));
    bindingContext.bindValue(styleSheetTextObserveTextObserveWidget, beanStyleSheetObserveValue, styleSheetStrategy, null);
    // 
    return bindingContext;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) DataBindingContext(org.eclipse.core.databinding.DataBindingContext) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue)

Example 23 with UpdateValueStrategy

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

the class BindingHelper method bindISINInput.

public final Control bindISINInput(Composite editArea, final String label, String property) {
    Text txtValue = createTextInput(editArea, label, SWT.NONE, 12);
    txtValue.setTextLimit(12);
    // 
    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 || Isin.isValid(v) ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogNotAValidISIN, 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 24 with UpdateValueStrategy

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

the class BindingHelper method bindCurrencyCodeCombo.

public final ComboViewer bindCurrencyCodeCombo(Composite editArea, String label, String property) {
    Label l = new Label(editArea, SWT.NONE);
    l.setText(label);
    ComboViewer combo = new ComboViewer(editArea, SWT.READ_ONLY);
    combo.setContentProvider(ArrayContentProvider.getInstance());
    combo.setLabelProvider(new LabelProvider());
    List<CurrencyUnit> currencies = new ArrayList<>();
    currencies.add(CurrencyUnit.EMPTY);
    currencies.addAll(CurrencyUnit.getAvailableCurrencyUnits().stream().sorted().collect(Collectors.toList()));
    combo.setInput(currencies);
    GridDataFactory.fillDefaults().align(SWT.BEGINNING, SWT.FILL).applyTo(combo.getControl());
    UpdateValueStrategy targetToModel = new UpdateValueStrategy();
    targetToModel.setConverter(new CurrencyUnitToStringConverter());
    UpdateValueStrategy modelToTarget = new UpdateValueStrategy();
    modelToTarget.setConverter(new StringToCurrencyUnitConverter());
    // 
    context.bindValue(// 
    ViewersObservables.observeSingleSelection(combo), BeanProperties.value(property).observe(model), targetToModel, modelToTarget);
    return combo;
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) IBaseLabelProvider(org.eclipse.jface.viewers.IBaseLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 25 with UpdateValueStrategy

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

the class BindingHelper method createErrorLabel.

public final void createErrorLabel(Composite editArea) {
    // error label
    Label errorLabel = new Label(editArea, SWT.NONE);
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(errorLabel);
    // error label
    // 
    context.bindValue(// 
    WidgetProperties.text().observe(errorLabel), // 
    new AggregateValidationStatus(context, AggregateValidationStatus.MAX_SEVERITY), // 
    null, new UpdateValueStrategy().setConverter(new StatusTextConverter()));
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Label(org.eclipse.swt.widgets.Label) AggregateValidationStatus(org.eclipse.core.databinding.AggregateValidationStatus)

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