我有一個AggregateValidationStatus
與IChangeListener
。每次我選擇/更改時都會調用監聽器,而這正是我需要的組件。我唯一的問題是我必須在ChangeListener
的開頭觸發我的MultiValidator
的validate()
方法。可悲的是有很低的文件,我發現沒有幫助我。AggregateValidationStatus的ChangeListener中的JFace/Eclipse數據綁定觸發器多值器
我ChangeListener
final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
dataBindingContext.getBindings(), AggregateValidationStatus.MAX_SEVERITY);
aggregateValidationStatus.addChangeListener(new IChangeListener() {
public void handleChange(ChangeEvent event) {
//Here I have to trigger the MultiValidator to return either OK or ERROR
boolean formIsValid = true;
aggregateValidationStatus.getValue();
for (Object o : dataBindingContext.getBindings()) {
Binding binding = (Binding) o;
IStatus status = (IStatus) binding.getValidationStatus().getValue();
if (!status.isOK()) {
formIsValid = false;
}
Control control = null;
if (binding.getTarget() instanceof ISWTObservable) {
ISWTObservable swtObservable = (ISWTObservable) binding.getTarget();
control = (Control) swtObservable.getWidget();
}
if (binding.getTarget() instanceof CalendarComboObservableValue) {
CalendarComboObservableValue observable = (CalendarComboObservableValue) binding.getTarget();
control = (Control) observable.getControl();
}
if (binding.getTarget() instanceof IViewerObservable) {
IViewerObservable observable = (IViewerObservable) binding.getTarget();
control = observable.getViewer().getControl();
}
ControlDecoration decoration = decoratorMap.get(control);
if (decoration != null) {
if (status.isOK() || status.matches(Status.WARNING)) {
decoration.hide();
} else {
decoration.setDescriptionText(status.getMessage());
decoration.show();
}
}
}
if (saveBtn != null)
saveBtn.setEnabled(formIsValid);
}
});
您可以添加代碼如何創建aggregateValidationStatus? –
@TillmannSeidel更新了代碼 – XtremeBaumer