2017-09-27 6 views
0

AggregateValidationStatusIChangeListener이 있습니다. 청취자는 내가 선택할/변경하고 구성 요소가 필요할 때마다 호출됩니다. 내가 가지고있는 유일한 문제는 ChangeListener의 시작 부분에 MultiValidator이라는 validate() 메서드를 트리거해야한다는 것입니다. 슬프게도 문서가 매우 적어서 내가 찾은 것이 나를 도와주지 못했습니다.AggregateValidationStatus의 ChangeListener에서 JFace/Eclipse 데이터 바인딩 트리거 multivalidator

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

귀하의 AggregateValidationStatusdatBindingContext의 바인딩을 통해 집계 :

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

가 하나의 바인딩에 있지만 전체 문맥에 연결되어 있지 않습니다. 그래서 당신은 당신의 AggregateValidationStatus 것은 물론 MultiValidator들, 다른 생성자를 사용해야 모니터링 할 경우 :

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

handleChanged superfluent에 MultiValidator의 수동 트리거를해야한다.

+0

을 답장 해주었습니다. 답장을 보내 주시면 사용해 보겠습니다. 작동하는 경우 대답을 수락합니다. – XtremeBaumer