Search in sources :

Example 6 with DatePicker

use of name.abuchen.portfolio.ui.util.DatePicker in project portfolio by buchen.

the class AccountTransferDialog method createFormElements.

@Override
protected void createFormElements(Composite editArea) {
    // 
    // input elements
    // 
    // source account
    ComboInput source = new ComboInput(editArea, Messages.ColumnAccountFrom);
    source.value.setInput(including(client.getActiveAccounts(), model().getSourceAccount()));
    IObservableValue sourceObservable = source.bindValue(Properties.sourceAccount.name(), Messages.MsgAccountFromMissing);
    source.bindCurrency(Properties.sourceAccountCurrency.name());
    // target account
    ComboInput target = new ComboInput(editArea, Messages.ColumnAccountTo);
    target.value.setInput(including(client.getActiveAccounts(), model().getTargetAccount()));
    IObservableValue targetObservable = target.bindValue(Properties.targetAccount.name(), Messages.MsgAccountToMissing);
    target.bindCurrency(Properties.targetAccountCurrency.name());
    MultiValidator validator = new AccountsMustBeDifferentValidator(sourceObservable, targetObservable);
    context.addValidationStatusProvider(validator);
    // 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.date.name()).observe(model));
    // other input fields
    Input fxAmount = new Input(editArea, Messages.ColumnAmount);
    fxAmount.bindValue(Properties.fxAmount.name(), Messages.ColumnAmount, Values.Amount, true);
    fxAmount.bindCurrency(Properties.sourceAccountCurrency.name());
    // $NON-NLS-1$ //$NON-NLS-2$
    Input exchangeRate = new Input(editArea, useIndirectQuotation ? "/ " : "x ");
    exchangeRate.bindBigDecimal(useIndirectQuotation ? Properties.inverseExchangeRate.name() : Properties.exchangeRate.name(), Values.ExchangeRate.pattern());
    exchangeRate.bindCurrency(useIndirectQuotation ? Properties.inverseExchangeRateCurrencies.name() : Properties.exchangeRateCurrencies.name());
    model().addPropertyChangeListener(Properties.exchangeRate.name(), e -> exchangeRate.value.setToolTipText(AbstractModel.createCurrencyToolTip(model().getExchangeRate(), model().getTargetAccountCurrency(), model().getSourceAccountCurrency())));
    // $NON-NLS-1$
    Input amount = new Input(editArea, "=");
    amount.bindValue(Properties.amount.name(), Messages.ColumnAmount, Values.Amount, true);
    amount.bindCurrency(Properties.targetAccountCurrency.name());
    // note
    Label lblNote = new Label(editArea, SWT.LEFT);
    lblNote.setText(Messages.ColumnNote);
    Text valueNote = new Text(editArea, SWT.BORDER);
    context.bindValue(WidgetProperties.text(SWT.Modify).observe(valueNote), BeanProperties.value(Properties.note.name()).observe(model));
    // 
    // form layout
    // 
    int amountWidth = amountWidth(amount.value);
    int currencyWidth = currencyWidth(fxAmount.currency);
    FormDataFactory forms = startingWith(source.value.getControl(), source.label).suffix(source.currency).thenBelow(target.value.getControl()).label(target.label).suffix(target.currency).thenBelow(valueDate.getControl()).label(lblDate);
    // fxAmount - exchange rate - amount
    // 
    forms.thenBelow(fxAmount.value).width(amountWidth).label(fxAmount.label).thenRight(fxAmount.currency).width(// 
    currencyWidth).thenRight(// 
    exchangeRate.label).thenRight(exchangeRate.value).width(// 
    amountWidth).thenRight(exchangeRate.currency).width(// 
    amountWidth).thenRight(// 
    amount.label).thenRight(amount.value).width(// 
    amountWidth).suffix(amount.currency, // 
    currencyWidth).thenBelow(valueNote).left(target.value.getControl()).right(amount.value).label(lblNote);
    int widest = widest(source.label, target.label, lblDate, fxAmount.label, lblNote);
    startingWith(source.label).width(widest);
    // 
    // hide / show exchange rate if necessary
    // 
    model.addPropertyChangeListener(Properties.exchangeRateCurrencies.name(), event -> {
        String sourceCurrency = model().getSourceAccountCurrency();
        String targetCurrency = model().getTargetAccountCurrency();
        // make exchange rate visible if both are set but different
        boolean visible = sourceCurrency.length() > 0 && targetCurrency.length() > 0 && !sourceCurrency.equals(targetCurrency);
        exchangeRate.setVisible(visible);
        amount.setVisible(visible);
    });
    WarningMessages warnings = new WarningMessages(this);
    warnings.add(() -> model().getDate().isAfter(LocalDate.now()) ? Messages.MsgDateIsInTheFuture : null);
    model.addPropertyChangeListener(Properties.date.name(), e -> warnings.check());
    // $NON-NLS-1$
    model.firePropertyChange(Properties.exchangeRateCurrencies.name(), "", model().getExchangeRateCurrencies());
}
Also used : SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) MultiValidator(org.eclipse.core.databinding.validation.MultiValidator) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) DatePicker(name.abuchen.portfolio.ui.util.DatePicker)

Example 7 with DatePicker

use of name.abuchen.portfolio.ui.util.DatePicker 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)

Aggregations

DatePicker (name.abuchen.portfolio.ui.util.DatePicker)7 Label (org.eclipse.swt.widgets.Label)7 SimpleDateTimeDateSelectionProperty (name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty)6 Text (org.eclipse.swt.widgets.Text)5 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)3 Button (org.eclipse.swt.widgets.Button)3 Composite (org.eclipse.swt.widgets.Composite)3 MessageFormat (java.text.MessageFormat)2 List (java.util.List)2 Messages (name.abuchen.portfolio.ui.Messages)2 FormDataFactory (name.abuchen.portfolio.ui.util.FormDataFactory)2 FormDataFactory.startingWith (name.abuchen.portfolio.ui.util.FormDataFactory.startingWith)2 SWTHelper.widest (name.abuchen.portfolio.ui.util.SWTHelper.widest)2 SimpleDateTimeTimeSelectionProperty (name.abuchen.portfolio.ui.util.SimpleDateTimeTimeSelectionProperty)2 UpdateValueStrategy (org.eclipse.core.databinding.UpdateValueStrategy)2 BeanProperties (org.eclipse.core.databinding.beans.BeanProperties)2 IObservableValue (org.eclipse.core.databinding.observable.value.IObservableValue)2 ValidationStatus (org.eclipse.core.databinding.validation.ValidationStatus)2 WidgetProperties (org.eclipse.jface.databinding.swt.WidgetProperties)2 LabelProvider (org.eclipse.jface.viewers.LabelProvider)2