2017-09-27 66 views
0

我有一個AggregateValidationStatusIChangeListener。每次我選擇/更改時都會調用監聽器,而這正是我需要的組件。我唯一的問題是我必須在ChangeListener的開頭觸發我的MultiValidatorvalidate()方法。可悲的是有很低的文件,我發現沒有幫助我。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); 
    } 
}); 
+0

您可以添加代碼如何創建aggregateValidationStatus? –

+0

@TillmannSeidel更新了代碼 – XtremeBaumer

回答

1

AggregateValidationStatus只聚集在datBindingContext的綁定:

final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
    dataBindingContext.getBindings(), AggregateValidationStatus.MAX_SEVERITY); 

MultiValidator沒有連接到一個單一的結合,但是整個環境。所以,如果你希望你的AggregateValidationStatus監控MultiValidator S以及,你應該使用不同的構造函數:

final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
    dataBindingContext, AggregateValidationStatus.MAX_SEVERITY); 

這應該使MultiValidator的手動觸發在handleChanged superfluent。

+0

感謝您的答覆,一旦我達到它將嘗試它。如果它有效,我會接受答案 – XtremeBaumer