label.setText(Messages.ColumnPortfolioFrom);
ComboViewer comboFrom = new ComboViewer(editArea, SWT.READ_ONLY);
comboFrom.setContentProvider(ArrayContentProvider.getInstance());
comboFrom.setInput(getModel().getClient().getActivePortfolios().toArray());
gdf.applyTo(comboFrom.getControl());
final IViewerObservableValue observableFrom = ViewersObservables.observeSingleSelection(comboFrom);
// portfolio to
label = new Label(editArea, SWT.NONE);
label.setText(Messages.ColumnPortfolioTo);
ComboViewer comboTo = new ComboViewer(editArea, SWT.READ_ONLY);
comboTo.setContentProvider(ArrayContentProvider.getInstance());
comboTo.setInput(getModel().getClient().getActivePortfolios().toArray());
gdf.applyTo(comboTo.getControl());
final IViewerObservableValue observableTo = ViewersObservables.observeSingleSelection(comboTo);
// security
List<Security> securities = new ArrayList<Security>();
securities.addAll(ClientSnapshot.create(getModel().getClient(), Dates.today()).getJointPortfolio()
.getPositionsBySecurity().keySet());
Collections.sort(securities, new Security.ByName());
bindings().bindComboViewer(editArea, Messages.ColumnSecurity, "security", new LabelProvider() //$NON-NLS-1$
{
@Override
public String getText(Object element)
{
return ((Security) element).getName();
}
}, securities.toArray());
// shares
bindings().bindMandatorySharesInput(editArea, Messages.ColumnShares, "shares").setFocus(); //$NON-NLS-1$
// price
label = new Label(editArea, SWT.NONE);
label.setText(Messages.ColumnPrice);
Label lblPrice = new Label(editArea, SWT.BORDER | SWT.READ_ONLY | SWT.NO_FOCUS);
GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(lblPrice);
getBindingContext().bindValue(
SWTObservables.observeText(lblPrice),
BeansObservables.observeValue(getModel(), "price"), //$NON-NLS-1$
new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_UPDATE)
.setConverter(new StringToCurrencyConverter(Values.Amount)), //
new UpdateValueStrategy(false, UpdateValueStrategy.POLICY_UPDATE)
.setConverter(new CurrencyToStringConverter(Values.Amount)));
// amount
bindings().bindMandatoryAmountInput(editArea, Messages.ColumnAmount, "amount"); //$NON-NLS-1$
// date
bindings().bindDatePicker(editArea, Messages.ColumnDate, "date"); //$NON-NLS-1$
//
// Bind UI
//
DataBindingContext context = getBindingContext();
// multi validator (to and from portfolio must not be identical)
MultiValidator validator = new MultiValidator()
{
@Override
protected IStatus validate()
{
Object from = observableFrom.getValue();
Object to = observableTo.getValue();
return from != null && to != null && from != to ? ValidationStatus.ok() : ValidationStatus
.error(Messages.MsgPortfolioMustBeDifferent);
}
};