use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createOCWarningControls.
@SuppressWarnings("unchecked")
private void createOCWarningControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
Composite composite = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return !((IStatus) fromObject).isOK();
}
}).in(dbc);
Label label = new Label(composite, SWT.NONE);
ValueBindingBuilder.bind(WidgetProperties.image().observe(label)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, Image.class) {
@Override
public Object convert(Object fromObject) {
switch(((IStatus) fromObject).getSeverity()) {
case IStatus.WARNING:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
case IStatus.ERROR:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_ERROR);
default:
return null;
}
}
}).in(dbc);
Link link = new Link(composite, SWT.WRAP);
ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model)).converting(new Converter(IStatus.class, String.class) {
@Override
public Object convert(Object fromObject) {
return ((IStatus) fromObject).getMessage();
}
}).in(dbc);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (DOWNLOAD_LINK_TEXT.equals(e.text)) {
new BrowserUtility().checkedCreateExternalBrowser(DOWNLOAD_INSTRUCTIONS_URL, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
} else {
int rc = PreferencesUtil.createPreferenceDialogOn(getShell(), OPEN_SHIFT_PREFERENCE_PAGE_ID, new String[] { OPEN_SHIFT_PREFERENCE_PAGE_ID }, null).open();
if (rc == Dialog.OK) {
new Job("Checking oc binary") {
@Override
protected IStatus run(IProgressMonitor monitor) {
IStatus stat = OCBinary.getInstance().getStatus(model.getConnection(), monitor);
model.setOCBinaryStatus(stat);
return stat;
}
}.schedule();
}
}
}
});
GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
IObservableValue<IStatus> observable = BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model);
Status status = (Status) observable.getValue();
switch(status.getSeverity()) {
case IStatus.ERROR:
return OpenShiftUIActivator.statusFactory().errorStatus(OpenShiftUIMessages.OCBinaryErrorMessage);
case IStatus.WARNING:
return OpenShiftUIActivator.statusFactory().warningStatus(OpenShiftUIMessages.OCBinaryWarningMessage);
}
return status;
}
};
dbc.addValidationStatusProvider(validator);
BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_OC_BINARY_STATUS).observe(model).addValueChangeListener(event -> getShell().pack());
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class ServerSettingsWizardPage method createRSyncControls.
private void createRSyncControls(Composite container, ServerSettingsWizardPageModel model, DataBindingContext dbc) {
final RSyncValidator rsyncValidator = RSyncValidator.get();
Composite composite = new Composite(container, SWT.NONE);
GridDataFactory.fillDefaults().applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
ValueBindingBuilder.bind(WidgetProperties.visible().observe(composite)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, Boolean.class) {
@Override
public Object convert(Object fromObject) {
return fromObject != RsyncStatus.OK;
}
}).in(dbc);
Label label = new Label(composite, SWT.NONE);
ValueBindingBuilder.bind(WidgetProperties.image().observe(label)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, Image.class) {
@Override
public Object convert(Object fromObject) {
switch((RsyncStatus) fromObject) {
case OK:
return null;
default:
return JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING);
}
}
}).in(dbc);
Link link = new Link(composite, SWT.WRAP);
ValueBindingBuilder.bind(WidgetProperties.text().observe(link)).to(BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model)).converting(new Converter(RsyncStatus.class, String.class) {
@Override
public Object convert(Object fromObject) {
switch((RsyncStatus) fromObject) {
case OK:
return null;
default:
return ((RsyncStatus) fromObject).getDetailedMessage(rsyncValidator.getBasePath());
}
}
}).in(dbc);
GridDataFactory.fillDefaults().hint(LINK_DEFAULT_WIDTH, SWT.DEFAULT).applyTo(link);
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (REFRESH_LINK_TEXT.equals(e.text)) {
new Job("Checking rsync environment") {
@Override
protected IStatus run(IProgressMonitor monitor) {
rsyncValidator.refresh();
model.setRsyncStatus(rsyncValidator.getStatus());
return Status.OK_STATUS;
}
}.schedule();
} else {
new BrowserUtility().checkedCreateExternalBrowser(e.text, OpenShiftUIActivator.PLUGIN_ID, OpenShiftUIActivator.getDefault().getLog());
}
}
});
MultiValidator validator = new MultiValidator() {
@Override
protected IStatus validate() {
RsyncStatus status = (RsyncStatus) BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model).getValue();
switch(status) {
case OK:
return ValidationStatus.ok();
default:
return OpenShiftUIActivator.statusFactory().warningStatus(status.getMessage());
}
}
};
dbc.addValidationStatusProvider(validator);
BeanProperties.value(ServerSettingsWizardPageModel.PROPERTY_RSYNC_STATUS).observe(model).addValueChangeListener(event -> getShell().pack());
}
use of org.eclipse.core.databinding.validation.MultiValidator in project jbosstools-openshift by jbosstools.
the class TemplateParametersPage method createTable.
public TableViewer createTable(final Composite tableContainer, IObservableList<IParameter> parametersObservable, DataBindingContext dbc) {
final Table table = new Table(tableContainer, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL);
table.setLinesVisible(true);
table.setHeaderVisible(true);
Image decorationImage = FieldDecorationRegistry.getDefault().getFieldDecoration(FieldDecorationRegistry.DEC_ERROR).getImage();
final ObservableMap<String, IStatus> cellsValidationStatusObservable = new WritableMap<>(String.class, IStatus.class);
final TableViewerCellDecorationManager decorations = new TableViewerCellDecorationManager(decorationImage, table);
DataBindingUtils.addDisposableListChangeListener(onParametersChanged(decorations, cellsValidationStatusObservable), parametersObservable, table);
TableViewer tableViewer = buildTableViewer(table, tableContainer, cellsValidationStatusObservable, decorations);
// cells validity
dbc.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
for (Iterator<IStatus> iterator = (Iterator<IStatus>) cellsValidationStatusObservable.values().iterator(); iterator.hasNext(); ) {
IStatus cellValidationStatus = iterator.next();
if (cellValidationStatus != null && !cellValidationStatus.isOK()) {
return cellValidationStatus;
}
}
return ValidationStatus.ok();
}
});
return tableViewer;
}
use of org.eclipse.core.databinding.validation.MultiValidator in project portfolio by buchen.
the class AbstractTransactionDialog method createDialogArea.
@Override
protected Control createDialogArea(Composite parent) {
Composite area = (Composite) super.createDialogArea(parent);
Composite editArea = new Composite(area, SWT.NONE);
FormLayout layout = new FormLayout();
layout.marginWidth = 5;
layout.marginHeight = 5;
editArea.setLayout(layout);
createFormElements(editArea);
// $NON-NLS-1$
IObservableValue<IStatus> calculationStatus = BeanProperties.value("calculationStatus").observe(model);
this.context.addValidationStatusProvider(new MultiValidator() {
@Override
protected IStatus validate() {
return calculationStatus.getValue();
}
});
// $NON-NLS-1$
context.bindValue(// $NON-NLS-1$
PojoProperties.value("status").observe(status), new AggregateValidationStatus(context, AggregateValidationStatus.MAX_SEVERITY));
return editArea;
}
use of org.eclipse.core.databinding.validation.MultiValidator 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