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