[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Re: DataBinding + Validation Framework

For me, my main target was to provide a decorator on the control based on the validation of the model.

After looking into the extended validation framework, i have to agree with Ed in that the core validation should still reside inside the model.

I played around with various UpdateValueStrategy attempts and hit a snag in most of them.

For each of these the databinding validation is called throughout the setting of the value. There is nothing that can be used for AFTER the value has been set onto the model. (that im aware of).

I tried overriding the doSet() method, however whenever undo / redo were applied, this method isn't called, and you end up with a stale validation. You can of course add another UpdateValueStrategy to the modelToTarget side of things, but you have no real direct reference to the emf model and you end up duplicating alot of things.

The only way i can successfully achieve my goal (and it may be different for others) was to add a ValuechangeListener to the EMFObservable/EMFEditObservable.

This gets called whenever undo/redo and set is invoked.

Im not entirely convinced ive done the correct thing (I'm sure Ed or Tom will probably tell me otherwise) but here is a copy of the listener that i add which in turn calls the standard EMF validation:


public class EMFValueChangeListener implements IValueChangeListener { private final int code; private final ControlDecoration decoration; public EMFValueChangeListener(int code, ControlDecoration decoration) { this.code = code; this.decoration = decoration; Assert.isNotNull(decoration, "ControlDecoration must not be null"); } @Override public void handleValueChange(ValueChangeEvent event) { final IObservable observable = event.getObservable(); if( observable instanceof IObserving ) { final IObserving observing = (IObserving)observable; if( observing.getObserved() instanceof EObject ) { final EObject eObject = (EObject) observing.getObserved();

final Diagnostic diagnostic = Diagnostician.INSTANCE.validate(eObject);
final Diagnostic child = DiagnosticHelper.getDiagnosticWithCode(diagnostic, code);
if( child != null && child.getCode() == code && child.getSeverity() == Diagnostic.WARNING ) {
this.decoration.setImage(DiagnosticHelper.WARNING_IMAGE);
this.decoration.setDescriptionText(child.getMessage());
this.decoration.show();
} else if ( child != null && child.getCode() == code && child.getSeverity() == Diagnostic.ERROR ) {
this.decoration.setImage(DiagnosticHelper.ERROR_IMAGE);
this.decoration.setDescriptionText(child.getMessage());
this.decoration.show();
} else {
this.decoration.hide();
}
}
}
}
}