2014-09-23 2 views
0

DataBinding을 사용하여 유효성을 검사 할 때 변경 배경 동작을 구현해야합니다. 어떻게해야합니까? 두 개의 DateChooserCombo (성운)이 있는데 겹치는 것을 방지하고 예를 들어 dateBegin> dateEnd 일 때 빨강으로 색을 변경합니다. 이것은 지금까지 내가 한 것입니다. 감사합니다.SWT/JFace 데이터 바인딩 변경 배경

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); 

답변

1

이런 식으로 생각합니다.

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"); 
    } 
} 
+0

새로운 '색상'개체를 만들려면 ** 작업을 마친 후에 처리해야합니다 **. –

+0

네, 맞습니다. 이것은 bg 색상을 변경하는 방법을 보여주는 일러스트레이션 일 뿐이지 만 모든 swt 자원을 폐기해야하거나 ColorRegistry o와 같은 자원 레지스트리를 사용해야 할 필요가 있습니다. –