Search in sources :

Example 1 with SimpleDateTimeDateSelectionProperty

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

the class SecurityTransactionDialog method createFormElements.

@Override
protected void createFormElements(Composite editArea) {
    // 
    // input elements
    // 
    // 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 + reference account
    ComboInput portfolio = new ComboInput(editArea, Messages.ColumnPortfolio);
    portfolio.value.setInput(including(client.getActivePortfolios(), model().getPortfolio()));
    portfolio.bindValue(Properties.portfolio.name(), Messages.MsgMissingPortfolio);
    ComboInput comboInput = new ComboInput(editArea, null);
    if (model() instanceof BuySellModel) {
        comboInput.value.setInput(including(client.getActiveAccounts(), ((BuySellModel) model()).getAccount()));
        comboInput.bindValue(Properties.account.name(), Messages.MsgMissingAccount);
    } else {
        List<CurrencyUnit> availableCurrencies = CurrencyUnit.getAvailableCurrencyUnits();
        Collections.sort(availableCurrencies);
        comboInput.value.setInput(availableCurrencies);
        comboInput.bindValue(Properties.transactionCurrency.name(), Messages.MsgMissingAccount);
    }
    // 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));
    DateTime valueTime = new DateTime(editArea, SWT.TIME | SWT.SHORT | SWT.DROP_DOWN | SWT.BORDER);
    context.bindValue(new SimpleDateTimeTimeSelectionProperty().observe(valueTime), BeanProperties.value(Properties.time.name()).observe(model));
    // other input fields
    Input shares = new Input(editArea, Messages.ColumnShares);
    shares.bindValue(Properties.shares.name(), Messages.ColumnShares, Values.Share, true);
    // $NON-NLS-1$
    Input quote = new Input(editArea, "x " + Messages.ColumnQuote);
    quote.bindBigDecimal(Properties.quote.name(), Values.Quote.pattern());
    quote.bindCurrency(Properties.securityCurrencyCode.name());
    // $NON-NLS-1$
    Input grossValue = new Input(editArea, "=");
    grossValue.bindValue(Properties.grossValue.name(), Messages.ColumnSubTotal, Values.Amount, true);
    grossValue.bindCurrency(Properties.securityCurrencyCode.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().getTransactionCurrencyCode(), model().getSecurityCurrencyCode())));
    // $NON-NLS-1$
    final Input convertedGrossValue = new Input(editArea, "=");
    convertedGrossValue.bindValue(Properties.convertedGrossValue.name(), Messages.ColumnSubTotal, Values.Amount, true);
    convertedGrossValue.bindCurrency(Properties.transactionCurrencyCode.name());
    // fees
    Label plusForexFees = new Label(editArea, SWT.NONE);
    // $NON-NLS-1$
    plusForexFees.setText("+");
    Input forexFees = new Input(editArea, sign() + Messages.ColumnFees);
    forexFees.bindValue(Properties.forexFees.name(), Messages.ColumnFees, Values.Amount, false);
    forexFees.bindCurrency(Properties.securityCurrencyCode.name());
    Input fees = new Input(editArea, sign() + Messages.ColumnFees);
    fees.bindValue(Properties.fees.name(), Messages.ColumnFees, Values.Amount, false);
    fees.bindCurrency(Properties.transactionCurrencyCode.name());
    // taxes
    Label plusForexTaxes = new Label(editArea, SWT.NONE);
    // $NON-NLS-1$
    plusForexTaxes.setText("+");
    Input forexTaxes = new Input(editArea, sign() + Messages.ColumnTaxes);
    forexTaxes.bindValue(Properties.forexTaxes.name(), Messages.ColumnTaxes, Values.Amount, false);
    forexTaxes.bindCurrency(Properties.securityCurrencyCode.name());
    Input taxes = new Input(editArea, sign() + Messages.ColumnTaxes);
    taxes.bindValue(Properties.taxes.name(), Messages.ColumnTaxes, Values.Amount, false);
    taxes.bindCurrency(Properties.transactionCurrencyCode.name());
    // total
    String label = getTotalLabel();
    // $NON-NLS-1$
    Input total = new Input(editArea, "= " + label);
    total.bindValue(Properties.total.name(), label, Values.Amount, model().getType() != PortfolioTransaction.Type.DELIVERY_OUTBOUND);
    total.bindCurrency(Properties.transactionCurrencyCode.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 width = amountWidth(grossValue.value);
    int currencyWidth = currencyWidth(grossValue.currency);
    int labelWidth = widest(securities.label, portfolio.label, lblDate, shares.label, lblNote);
    startingWith(securities.value.getControl(), securities.label).suffix(securities.currency).thenBelow(portfolio.value.getControl()).label(portfolio.label).suffix(// 
    comboInput.value.getControl()).thenBelow(valueDate.getControl()).label(lblDate).thenRight(valueTime);
    startingWith(securities.label).width(labelWidth);
    // shares - quote - gross value
    startingWith(valueDate.getControl()).thenBelow(shares.value).width(width).label(shares.label).thenRight(quote.label).thenRight(quote.value).width(width).thenRight(quote.currency).width(width).thenRight(grossValue.label).thenRight(grossValue.value).width(width).thenRight(grossValue.currency);
    startingWith(quote.value).thenBelow(exchangeRate.value).width(width).label(exchangeRate.label).thenRight(exchangeRate.currency).width(width);
    startingWith(grossValue.value).thenBelow(convertedGrossValue.value).width(width).label(convertedGrossValue.label).suffix(convertedGrossValue.currency).thenBelow(fees.value).width(width).label(fees.label).suffix(fees.currency).thenBelow(taxes.value).width(width).label(taxes.label).suffix(taxes.currency).thenBelow(total.value).width(width).label(total.label).suffix(total.currency).thenBelow(valueNote).left(securities.value.getControl()).right(total.value).label(lblNote);
    startingWith(fees.value).thenLeft(plusForexFees).thenLeft(forexFees.currency).width(currencyWidth).thenLeft(forexFees.value).width(width).thenLeft(forexFees.label);
    startingWith(taxes.value).thenLeft(plusForexTaxes).thenLeft(forexTaxes.currency).width(currencyWidth).thenLeft(forexTaxes.value).width(width).thenLeft(forexTaxes.label);
    // 
    // hide / show exchange rate if necessary
    // 
    model.addPropertyChangeListener(Properties.exchangeRateCurrencies.name(), event -> {
        // NOSONAR
        String securityCurrency = model().getSecurityCurrencyCode();
        String accountCurrency = model().getTransactionCurrencyCode();
        // make exchange rate visible if both are set but different
        boolean visible = securityCurrency.length() > 0 && accountCurrency.length() > 0 && !securityCurrency.equals(accountCurrency);
        exchangeRate.setVisible(visible);
        convertedGrossValue.setVisible(visible);
        forexFees.setVisible(visible);
        plusForexFees.setVisible(visible);
        fees.label.setVisible(!visible);
        forexTaxes.setVisible(visible);
        plusForexTaxes.setVisible(visible);
        taxes.label.setVisible(!visible);
        // set fx taxes and tx fees to 0 if not visible
        if (!visible) {
            model().setForexFees(0);
            model().setForexTaxes(0);
        }
    });
    WarningMessages warnings = new WarningMessages(this);
    warnings.add(() -> model().getDate().isAfter(LocalDate.now()) ? Messages.MsgDateIsInTheFuture : null);
    warnings.add(() -> new StockSplitWarning().check(model().getSecurity(), model().getDate()));
    model.addPropertyChangeListener(Properties.security.name(), e -> warnings.check());
    model.addPropertyChangeListener(Properties.date.name(), e -> warnings.check());
    // $NON-NLS-1$
    model.firePropertyChange(Properties.exchangeRateCurrencies.name(), "", model().getExchangeRateCurrencies());
}
Also used : CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) SimpleDateTimeDateSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) DateTime(org.eclipse.swt.widgets.DateTime) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) SimpleDateTimeTimeSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeTimeSelectionProperty)

Example 2 with SimpleDateTimeDateSelectionProperty

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

the class SecurityTransferDialog method createFormElements.

@Override
protected void createFormElements(Composite editArea) {
    // 
    // input elements
    // 
    // 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());
    // source portfolio
    ComboInput source = new ComboInput(editArea, Messages.ColumnAccountFrom);
    source.value.setInput(including(client.getActivePortfolios(), model().getSourcePortfolio()));
    IObservableValue sourceObservable = source.bindValue(Properties.sourcePortfolio.name(), Messages.MsgPortfolioFromMissing);
    source.bindCurrency(Properties.sourcePortfolioLabel.name());
    // target portfolio
    ComboInput target = new ComboInput(editArea, Messages.ColumnAccountTo);
    target.value.setInput(including(client.getActivePortfolios(), model().getTargetPortfolio()));
    IObservableValue targetObservable = target.bindValue(Properties.targetPortfolio.name(), Messages.MsgPortfolioToMissing);
    target.bindCurrency(Properties.targetPortfolioLabel.name());
    MultiValidator validator = new PortfoliosMustBeDifferentValidator(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));
    DateTime valueTime = new DateTime(editArea, SWT.TIME | SWT.SHORT | SWT.DROP_DOWN | SWT.BORDER);
    context.bindValue(new SimpleDateTimeTimeSelectionProperty().observe(valueTime), BeanProperties.value(Properties.time.name()).observe(model));
    // amount
    Input shares = new Input(editArea, Messages.ColumnShares);
    shares.bindValue(Properties.shares.name(), Messages.ColumnShares, Values.Share, true);
    // $NON-NLS-1$
    Input quote = new Input(editArea, "x " + Messages.ColumnQuote);
    quote.bindBigDecimal(Properties.quote.name(), Values.Quote.pattern());
    quote.bindCurrency(Properties.securityCurrencyCode.name());
    // $NON-NLS-1$
    Input amount = new Input(editArea, "=");
    amount.bindValue(Properties.amount.name(), Messages.ColumnAmount, Values.Amount, true);
    amount.bindCurrency(Properties.securityCurrencyCode.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(amount.currency);
    startingWith(securities.value.getControl(), securities.label).suffix(securities.currency).thenBelow(source.value.getControl()).label(source.label).suffix(source.currency).thenBelow(target.value.getControl()).label(target.label).suffix(target.currency).thenBelow(valueDate.getControl()).label(lblDate).thenRight(valueTime);
    // shares - quote - amount
    startingWith(valueDate.getControl()).thenBelow(shares.value).width(amountWidth).label(shares.label).thenRight(quote.label).thenRight(quote.value).width(amountWidth).thenRight(quote.currency).width(currencyWidth).thenRight(amount.label).thenRight(amount.value).width(amountWidth).thenRight(amount.currency).width(currencyWidth);
    startingWith(shares.value).thenBelow(valueNote).left(securities.value.getControl()).right(amount.value).label(lblNote);
    int widest = widest(securities.label, source.label, target.label, lblDate, shares.label, lblNote);
    startingWith(securities.label).width(widest);
    WarningMessages warnings = new WarningMessages(this);
    warnings.add(() -> LocalDateTime.of(model().getDate(), model().getTime()).isAfter(LocalDateTime.now()) ? Messages.MsgDateIsInTheFuture : null);
    warnings.add(() -> new StockSplitWarning().check(model().getSecurity(), model().getDate()));
    model.addPropertyChangeListener(Properties.security.name(), e -> warnings.check());
    model.addPropertyChangeListener(Properties.date.name(), e -> warnings.check());
}
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) LocalDateTime(java.time.LocalDateTime) DateTime(org.eclipse.swt.widgets.DateTime) IObservableValue(org.eclipse.core.databinding.observable.value.IObservableValue) DatePicker(name.abuchen.portfolio.ui.util.DatePicker) SimpleDateTimeTimeSelectionProperty(name.abuchen.portfolio.ui.util.SimpleDateTimeTimeSelectionProperty)

Example 3 with SimpleDateTimeDateSelectionProperty

use of name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty 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 4 with SimpleDateTimeDateSelectionProperty

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

the class AccountTransactionDialog method createFormElements.

@Override
protected // NOSONAR
void createFormElements(// NOSONAR
Composite editArea) {
    // 
    // input elements
    // 
    // security
    ComboInput securities = null;
    if (model().supportsSecurity())
        securities = setupSecurities(editArea);
    // account
    ComboInput accounts = new ComboInput(editArea, Messages.ColumnAccount);
    accounts.value.setInput(including(client.getActiveAccounts(), model().getAccount()));
    accounts.bindValue(Properties.account.name(), Messages.MsgMissingAccount);
    accounts.bindCurrency(Properties.accountCurrencyCode.name());
    // date & time
    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));
    // shares
    Input shares = new Input(editArea, Messages.ColumnShares);
    shares.bindValue(Properties.shares.name(), Messages.ColumnShares, Values.Share, false);
    shares.setVisible(model().supportsShares());
    Button btnShares = new Button(editArea, SWT.ARROW | SWT.DOWN);
    btnShares.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            showSharesContextMenu();
        }
    });
    btnShares.setVisible(model().supportsShares());
    editArea.addDisposeListener(e -> AccountTransactionDialog.this.widgetDisposed());
    Input dividendAmount = new Input(editArea, Messages.LabelDividendPerShare);
    // $NON-NLS-1$
    dividendAmount.bindBigDecimal(Properties.dividendAmount.name(), "#,##0.0000");
    dividendAmount.bindCurrency(Properties.fxCurrencyCode.name());
    dividendAmount.setVisible(model().supportsShares());
    // other input fields
    String totalLabel = model().supportsTaxUnits() ? Messages.ColumnGrossValue : getTotalLabel();
    Input fxGrossAmount = new Input(editArea, totalLabel);
    fxGrossAmount.bindValue(Properties.fxGrossAmount.name(), totalLabel, Values.Amount, true);
    fxGrossAmount.bindCurrency(Properties.fxCurrencyCode.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().getAccountCurrencyCode(), model().getSecurityCurrencyCode())));
    // $NON-NLS-1$
    Input grossAmount = new Input(editArea, "=");
    grossAmount.bindValue(Properties.grossAmount.name(), totalLabel, Values.Amount, true);
    grossAmount.bindCurrency(Properties.accountCurrencyCode.name());
    // taxes
    Label plusForexTaxes = new Label(editArea, SWT.NONE);
    // $NON-NLS-1$
    plusForexTaxes.setText("+");
    plusForexTaxes.setVisible(model().supportsTaxUnits());
    Input forexTaxes = new Input(editArea, Messages.ColumnTaxes);
    forexTaxes.bindValue(Properties.fxTaxes.name(), Messages.ColumnTaxes, Values.Amount, false);
    forexTaxes.bindCurrency(Properties.fxCurrencyCode.name());
    forexTaxes.setVisible(model().supportsTaxUnits());
    Input taxes = new Input(editArea, Messages.ColumnTaxes);
    taxes.bindValue(Properties.taxes.name(), Messages.ColumnTaxes, Values.Amount, false);
    taxes.bindCurrency(Properties.accountCurrencyCode.name());
    taxes.setVisible(model().supportsTaxUnits());
    // will only show if no fx available
    taxes.label.setVisible(false);
    // total
    Input total = new Input(editArea, getTotalLabel());
    total.bindValue(Properties.total.name(), Messages.ColumnTotal, Values.Amount, false);
    total.bindCurrency(Properties.accountCurrencyCode.name());
    total.setVisible(model().supportsTaxUnits());
    // 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 widest = widest(securities != null ? securities.label : null, accounts.label, lblDate, shares.label, taxes.label, total.label, lblNote);
    FormDataFactory forms;
    if (securities != null) {
        forms = startingWith(securities.value.getControl(), securities.label).suffix(securities.currency).thenBelow(accounts.value.getControl()).label(accounts.label).suffix(accounts.currency);
        startingWith(securities.label).width(widest);
    } else {
        forms = startingWith(accounts.value.getControl(), accounts.label).suffix(accounts.currency);
        startingWith(accounts.label).width(widest);
    }
    int amountWidth = amountWidth(grossAmount.value);
    int currencyWidth = currencyWidth(fxGrossAmount.currency);
    // date
    // shares
    forms = forms.thenBelow(valueDate.getControl()).label(lblDate);
    // shares [- amount per share]
    forms = // 
    forms.thenBelow(shares.value).width(amountWidth).label(shares.label).suffix(btnShares).thenBelow(fxGrossAmount.value).width(amountWidth).label(// 
    fxGrossAmount.label).thenRight(fxGrossAmount.currency).width(// 
    currencyWidth).thenRight(// 
    exchangeRate.label).thenRight(exchangeRate.value).width(// 
    amountWidth).thenRight(exchangeRate.currency).width(// 
    amountWidth).thenRight(// 
    grossAmount.label).thenRight(grossAmount.value).width(// 
    amountWidth).thenRight(grossAmount.currency).width(currencyWidth);
    if (model().supportsShares()) {
        // shares [- amount per share]
        // 
        startingWith(btnShares).thenRight(dividendAmount.label).thenRight(dividendAmount.value).width(// 
        amountWidth).thenRight(dividendAmount.currency).width(// 
        currencyWidth);
    }
    // forexTaxes - taxes
    if (model().supportsTaxUnits()) {
        // 
        startingWith(grossAmount.value).thenBelow(taxes.value).width(amountWidth).label(taxes.label).suffix(// 
        taxes.currency).thenBelow(total.value).width(amountWidth).label(total.label).thenRight(total.currency).width(currencyWidth);
        startingWith(taxes.value).thenLeft(plusForexTaxes).thenLeft(forexTaxes.currency).width(currencyWidth).thenLeft(forexTaxes.value).width(amountWidth).thenLeft(forexTaxes.label);
        forms = startingWith(total.value);
    }
    // note
    forms.thenBelow(valueNote).left(accounts.value.getControl()).right(grossAmount.value).label(lblNote);
    // 
    // hide / show exchange rate if necessary
    // 
    model.addPropertyChangeListener(Properties.exchangeRateCurrencies.name(), event -> {
        // NOSONAR
        String securityCurrency = model().getSecurityCurrencyCode();
        String accountCurrency = model().getAccountCurrencyCode();
        // make exchange rate visible if both are set but different
        boolean isFxVisible = securityCurrency.length() > 0 && accountCurrency.length() > 0 && !securityCurrency.equals(accountCurrency);
        exchangeRate.setVisible(isFxVisible);
        grossAmount.setVisible(isFxVisible);
        forexTaxes.setVisible(isFxVisible && model().supportsShares());
        plusForexTaxes.setVisible(isFxVisible && model().supportsShares());
        taxes.label.setVisible(!isFxVisible && model().supportsShares());
        // in case fx taxes have been entered
        if (!isFxVisible)
            model().setFxTaxes(0);
        // move input fields to have a nicer layout
        if (isFxVisible)
            startingWith(grossAmount.value).thenBelow(taxes.value);
        else
            startingWith(fxGrossAmount.value).thenBelow(taxes.value);
        editArea.layout();
    });
    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) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DatePicker(name.abuchen.portfolio.ui.util.DatePicker)

Example 5 with SimpleDateTimeDateSelectionProperty

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

Aggregations

DatePicker (name.abuchen.portfolio.ui.util.DatePicker)6 SimpleDateTimeDateSelectionProperty (name.abuchen.portfolio.ui.util.SimpleDateTimeDateSelectionProperty)6 Label (org.eclipse.swt.widgets.Label)6 Text (org.eclipse.swt.widgets.Text)5 MultiValidator (org.eclipse.core.databinding.validation.MultiValidator)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 SWT (org.eclipse.swt.SWT)2 Button (org.eclipse.swt.widgets.Button)2