use of name.abuchen.portfolio.ui.util.FormDataFactory 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());
}
use of name.abuchen.portfolio.ui.util.FormDataFactory 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());
}
Aggregations