Search in sources :

Example 26 with UpdateValueStrategy

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

the class BindingHelper method bindMandatoryLongInput.

public final Control bindMandatoryLongInput(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) {
            Long v = (Long) value;
            return v != null && v.longValue() > 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)

Example 27 with UpdateValueStrategy

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

the class InvestmentPlanDialog method createFormElements.

@Override
protected void createFormElements(Composite editArea) {
    // 
    // input elements
    // 
    // name
    Label lblName = new Label(editArea, SWT.RIGHT);
    lblName.setText(Messages.ColumnName);
    Text valueName = new Text(editArea, SWT.BORDER);
    IValidator validator = value -> {
        String v = (String) value;
        return v != null && v.trim().length() > 0 ? ValidationStatus.ok() : ValidationStatus.error(MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnName));
    };
    context.bindValue(WidgetProperties.text(SWT.Modify).observe(valueName), BeanProperties.value(Properties.name.name()).observe(model), new UpdateValueStrategy().setAfterConvertValidator(validator), null);
    // security
    ComboInput securities = new ComboInput(editArea, Messages.ColumnSecurity);
    securities.value.setInput(including(client.getActiveSecurities(), model().getSecurity()));
    securities.bindValue(Properties.security.name(), Messages.MsgMissingSecurity);
    securities.bindCurrency(Properties.securityCurrencyCode.name());
    // portfolio
    ComboInput portfolio = new ComboInput(editArea, Messages.ColumnPortfolio);
    portfolio.value.setInput(including(client.getActivePortfolios(), model().getPortfolio()));
    portfolio.bindValue(Properties.portfolio.name(), Messages.MsgMissingPortfolio);
    // account
    ComboInput account = new ComboInput(editArea, Messages.ColumnAccount);
    List<Account> accounts = including(client.getActiveAccounts(), model().getAccount());
    accounts.add(0, InvestmentPlanModel.DELIVERY);
    account.value.setInput(accounts);
    account.bindValue(Properties.account.name(), Messages.MsgMissingAccount);
    account.bindCurrency(Properties.accountCurrencyCode.name());
    // auto-generate
    Label labelAutoGenerate = new Label(editArea, SWT.NONE);
    labelAutoGenerate.setText(Messages.MsgCreateTransactionsAutomaticallyUponOpening);
    Button buttonAutoGenerate = new Button(editArea, SWT.CHECK);
    // 
    context.bindValue(// 
    WidgetProperties.selection().observe(buttonAutoGenerate), BeanProperties.value(Properties.autoGenerate.name()).observe(model));
    // date
    Label lblDate = new Label(editArea, SWT.RIGHT);
    lblDate.setText(Messages.ColumnDate);
    DatePicker valueDate = new DatePicker(editArea);
    context.bindValue(new SimpleDateTimeDateSelectionProperty().observe(valueDate.getControl()), BeanProperties.value(Properties.start.name()).observe(model));
    // interval
    List<Integer> available = new ArrayList<>();
    for (int ii = 1; ii <= 12; ii++) available.add(ii);
    ComboInput interval = new ComboInput(editArea, Messages.ColumnInterval);
    interval.value.setInput(available);
    interval.value.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            int interval = (Integer) element;
            return MessageFormat.format(Messages.InvestmentPlanIntervalLabel, interval);
        }
    });
    interval.bindValue(Properties.interval.name(), MessageFormat.format(Messages.MsgDialogInputRequired, Messages.ColumnInterval));
    // amount
    Input amount = new Input(editArea, Messages.ColumnAmount);
    amount.bindValue(Properties.amount.name(), Messages.ColumnAmount, Values.Amount, true);
    amount.bindCurrency(Properties.transactionCurrencyCode.name());
    // fees
    Input fees = new Input(editArea, Messages.ColumnFees);
    fees.bindValue(Properties.fees.name(), Messages.ColumnAmount, Values.Amount, false);
    fees.bindCurrency(Properties.transactionCurrencyCode.name());
    // 
    // form layout
    // 
    int amountWidth = amountWidth(amount.value);
    int currencyWidth = currencyWidth(amount.currency);
    startingWith(valueName, lblName).width(3 * amountWidth).thenBelow(securities.value.getControl()).label(securities.label).suffix(securities.currency, // 
    currencyWidth).thenBelow(portfolio.value.getControl()).label(// 
    portfolio.label).thenBelow(account.value.getControl()).label(account.label).suffix(account.currency, // 
    currencyWidth).thenBelow(labelAutoGenerate, // 
    10).thenBelow(valueDate.getControl(), 10).label(// 
    lblDate).thenBelow(amount.value, 10).width(amountWidth).label(amount.label).suffix(amount.currency, // 
    currencyWidth).thenBelow(fees.value).width(amountWidth).label(fees.label).suffix(fees.currency, // 
    currencyWidth);
    startingWith(labelAutoGenerate).thenLeft(buttonAutoGenerate);
    startingWith(valueDate.getControl()).thenRight(interval.label).thenRight(interval.value.getControl());
    int widest = widest(lblName, securities.label, portfolio.label, account.label, lblDate, interval.label, amount.label, fees.label);
    startingWith(lblName).width(widest);
    WarningMessages warnings = new WarningMessages(this);
    warnings.add(() -> model().getStart().isAfter(LocalDate.now()) ? Messages.MsgDateIsInTheFuture : null);
    model.addPropertyChangeListener(Properties.start.name(), e -> warnings.check());
}
Also used : FormDataFactory.startingWith(name.abuchen.portfolio.ui.util.FormDataFactory.startingWith) Values(name.abuchen.portfolio.money.Values) Client(name.abuchen.portfolio.model.Client) IServiceConstants(org.eclipse.e4.ui.services.IServiceConstants) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) IValidator(org.eclipse.core.databinding.validation.IValidator) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ValidationStatus(org.eclipse.core.databinding.validation.ValidationStatus) WidgetProperties(org.eclipse.jface.databinding.swt.WidgetProperties) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Named(javax.inject.Named) SWTHelper.currencyWidth(name.abuchen.portfolio.ui.util.SWTHelper.currencyWidth) Properties(name.abuchen.portfolio.ui.dialogs.transactions.InvestmentPlanModel.Properties) Text(org.eclipse.swt.widgets.Text) Shell(org.eclipse.swt.widgets.Shell) SWTHelper.widest(name.abuchen.portfolio.ui.util.SWTHelper.widest) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) SWTHelper.amountWidth(name.abuchen.portfolio.ui.util.SWTHelper.amountWidth) InvestmentPlan(name.abuchen.portfolio.model.InvestmentPlan) List(java.util.List) BeanProperties(org.eclipse.core.databinding.beans.BeanProperties) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) Label(org.eclipse.swt.widgets.Label) LabelProvider(org.eclipse.jface.viewers.LabelProvider) UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) Account(name.abuchen.portfolio.model.Account) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) IValidator(org.eclipse.core.databinding.validation.IValidator) Button(org.eclipse.swt.widgets.Button) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 28 with UpdateValueStrategy

use of org.eclipse.core.databinding.UpdateValueStrategy in project InformationSystem by ObeoNetwork.

the class ImportXMLSnapshotWizardPage method initDataBindings.

protected DataBindingContext initDataBindings() {
    DataBindingContext bindingContext = new DataBindingContext();
    // 
    IObservableValue observeTextTxtXmlFileObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtXmlFile);
    IObservableValue xmlFileInputDataObserveValue = PojoProperties.value("xmlFile").observe(inputData);
    bindingContext.bindValue(observeTextTxtXmlFileObserveWidget, xmlFileInputDataObserveValue, null, null);
    // 
    IObservableValue observeTextTxtLocalProjectObserveWidget = WidgetProperties.text(SWT.Modify).observe(txtLocalProject);
    IObservableValue localProjectNameInputDataObserveValue = PojoProperties.value("localProjectName").observe(inputData);
    bindingContext.bindValue(observeTextTxtLocalProjectObserveWidget, localProjectNameInputDataObserveValue, null, null);
    // 
    IObservableValue observeSingleSelectionComboRemoteProjectViewer = ViewerProperties.singleSelection().observe(comboRemoteProjectViewer);
    IObservableValue remoteProjectURIInputDataObserveValue = PojoProperties.value("remoteProjectURI").observe(inputData);
    UpdateValueStrategy strategy_1 = new UpdateValueStrategy();
    UpdateValueStrategy strategy = new UpdateValueStrategy();
    bindingContext.bindValue(observeSingleSelectionComboRemoteProjectViewer, remoteProjectURIInputDataObserveValue, strategy_1, strategy);
    // 
    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 29 with UpdateValueStrategy

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

the class SecurityTaxonomyPage method setupWeightMultiValidator.

private void setupWeightMultiValidator(Label sumOfWeights, TaxonomyDesignation designation, final List<IObservableValue> weightObservables) {
    MultiValidator multiValidator = new WeightsAreGreaterThan100Validator(sumOfWeights, designation.getTaxonomy(), weightObservables);
    bindings.getBindingContext().addValidationStatusProvider(multiValidator);
    validators.add(multiValidator);
    for (int ii = 0; ii < weightObservables.size(); ii++) {
        IObservableValue observable = weightObservables.get(ii);
        ClassificationLink link = designation.getLinks().get(ii);
        UpdateValueStrategy strategy = new UpdateValueStrategy();
        strategy.setAfterConvertValidator(new GreaterThanZeroValidator());
        validators.add(bindings.getBindingContext().bindValue(multiValidator.observeValidatedValue(observable), BeanProperties.value("weight").observe(link), strategy, // $NON-NLS-1$
        null));
    }
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

Example 30 with UpdateValueStrategy

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

the class SecurityTaxonomyPage method setupClassificationMultiValidator.

private void setupClassificationMultiValidator(TaxonomyDesignation designation, final List<IObservableValue> classificationObservables) {
    MultiValidator multiValidator = new ClassificationNotTwiceValidator(classificationObservables);
    bindings.getBindingContext().addValidationStatusProvider(multiValidator);
    validators.add(multiValidator);
    for (int ii = 0; ii < classificationObservables.size(); ii++) {
        IObservableValue observable = classificationObservables.get(ii);
        ClassificationLink link = designation.getLinks().get(ii);
        UpdateValueStrategy strategy = new UpdateValueStrategy();
        strategy.setAfterConvertValidator(new NotNullValidator());
        validators.add(bindings.getBindingContext().bindValue(multiValidator.observeValidatedValue(observable), BeanProperties.value("classification").observe(link), strategy, // $NON-NLS-1$
        null));
    }
}
Also used : UpdateValueStrategy(org.eclipse.core.databinding.UpdateValueStrategy) ClassificationLink(name.abuchen.portfolio.ui.wizards.security.EditSecurityModel.ClassificationLink) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator)

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