use of org.eclipse.core.databinding.validation.MultiValidator in project portfolio by buchen.
the class PasswordDialog method createFormElements.
@Override
protected void createFormElements(Composite editArea) {
final IObservableValue password = bindings().bindStringInput(editArea, Messages.LabelPassword, "password", // $NON-NLS-1$
SWT.PASSWORD);
final IObservableValue repeat = bindings().bindStringInput(editArea, Messages.LabelPasswordRepeat, "repeat", // $NON-NLS-1$
SWT.PASSWORD);
// multi validator (passwords must be identical)
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
String pwd = (String) password.getValue();
String rpt = (String) repeat.getValue();
if (pwd.length() < 6)
return ValidationStatus.error(Messages.MsgPasswordMinCharacters);
return pwd.equals(rpt) ? ValidationStatus.ok() : ValidationStatus.error(Messages.MsgPasswordNotIdentical);
}
};
bindings().getBindingContext().addValidationStatusProvider(validator);
}
use of org.eclipse.core.databinding.validation.MultiValidator 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());
}
use of org.eclipse.core.databinding.validation.MultiValidator 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);
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorFactory method createBasicAuthenticationValidator.
/**
* Returns new validator that checks that there is no connection other than the selected one
* with host and username provided by the observable values.
* @param pageModel
* @param usernameObservable
* @param urlObservable
* @return
*/
public static MultiValidator createBasicAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue usernameObservable, IObservableValue<?> urlObservable) {
return new MultiValidator() {
@Override
protected IStatus validate() {
String user1 = (String) usernameObservable.getValue();
String mHost = (String) urlObservable.getValue();
IConnection current = pageModel.getSelectedConnection();
for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
if (c != current && IAuthorizationContext.AUTHSCHEME_BASIC.equals(c.getAuthScheme())) {
String host = c.getHost();
String user = c.getUsername();
if (host != null && host.equals(mHost) && user != null && user.equals(user1)) {
return ValidationStatus.error("Connection for the server with this username already exists.");
}
}
}
return ValidationStatus.ok();
}
};
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ConnectionValidatorFactory method createOAuthAuthenticationValidator.
/**
* Returns new validator that checks that there is no connection other than the selected one
* with host and token provided by the observable values.
* @param pageModel
* @param tokenObservable
* @param urlObservable
* @return
*/
public static MultiValidator createOAuthAuthenticationValidator(ConnectionWizardPageModel pageModel, IObservableValue tokenObservable, IObservableValue<?> urlObservable) {
return new MultiValidator() {
@Override
protected IStatus validate() {
String token1 = (String) tokenObservable.getValue();
String mHost = (String) urlObservable.getValue();
IConnection current = pageModel.getSelectedConnection();
for (Connection c : ConnectionsRegistrySingleton.getInstance().getAll(Connection.class)) {
if (c != current && IAuthorizationContext.AUTHSCHEME_OAUTH.equals(c.getAuthScheme())) {
String host = c.getHost();
String token = c.getToken();
if (host != null && host.equals(mHost) && token != null && token.equals(token1)) {
return ValidationStatus.error("Connection for the server with this token already exists.");
}
}
}
return ValidationStatus.ok();
}
};
}
Aggregations