[英]SWT/JFace databinding change background
使用DataBinding進行驗證時,我必須實現更改后台行為,該怎么做? 我有兩個DateChooserCombo(nebula),我想防止重疊,例如在dateBegin> dateEnd時將顏色更改為紅色,這是我到目前為止所做的。 謝謝
IObservableValue textObservable = new DateChooserComboObservableValue(
dateChooser, SWT.Modify);
UpdateValueStrategy strategy = new UpdateValueStrategy();
strategy.setBeforeSetValidator(new IValidator() {
@Override
public IStatus validate(Object value) {
//for testing purpose make it fail
return ValidationStatus.error("this is not permitted");
}
});
Realm realm = SWTObservables.getRealm(dateChooser.getDisplay());
DataBindingContext context = new DataBindingContext(realm);
org.eclipse.core.databinding.Binding binding = context.bindValue(
textObservable, PojoProperties.value(Model.class, "dateEnd")
.observe(realm, model.dateEnd), strategy,
strategy);
//didn't show the control decoration as expected
ControlDecorationSupport.create(binding, SWT.TOP | SWT.LEFT);
我認為類似的方法會起作用。
new IValidator() {
@Override
public IStatus validate(Object value) {
// change background goes could here
//myControl.setBackground (new Color (display, new RGB (230,230,230));
//for testing purpose make it fail
return ValidationStatus.error("this is not permitted");
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.