EMF Validation called 4 times for each binding [message #898398] |
Thu, 26 July 2012 06:27  |
Eclipse User |
|
|
|
Hi,
I've set up EMF validation along with an AggregateValidationStatus whose binding context is used to bind several text fields in the UI to the model.
However, when I first open the UI, each bound field causes the validation to be run 4 times. I've got 8 fields on my form at the moment which means the model is validated 32 times which really slows down the page processing!
Any ideas on how to reduce this to just one per field? Or less even!
Here is my code:-
final EMFUpdateValueStrategy updateValueStrategy = new EMFUpdateValueStrategy();
updateValueStrategy.setAfterGetValidator(new IValidator() {
@Override
public IStatus validate(Object value) {
/* validate the model */
Diagnostic diagnostic = Diagnostician.INSTANCE.validate(model);
return BasicDiagnostic.toIStatus(diagnostic);
}
});
final AggregateValidationStatus aggregateValidationStatus = new AggregateValidationStatus(
bindingCtxt, AggregateValidationStatus.MAX_SEVERITY);
aggregateValidationStatus
.addValueChangeListener(new IValueChangeListener() {
@Override
public void handleValueChange(ValueChangeEvent event) {
Diagnostic diagnostics = BasicDiagnostic.toDiagnostic(
updateValueStrategy.validateAfterGet(model))
.getChildren());
/*
* this is needed or the validation only gets called once
*/
aggregateValidationStatus.getValue();
}
});
|
|
|
|
|
|
|
|
Re: EMF Validation called 4 times for each binding [message #899475 is a reply to message #899305] |
Wed, 01 August 2012 01:44   |
Eclipse User |
|
|
|
Not really. bindValue will initially force an model => target update I
guess to work around the problem you should create your
aggregateValidationStatus after the initial binding is done.
Tom
Am 31.07.12 14:33, schrieb Simon Barnett:
> OK, I figured out that it wasn't the dependencies after all - it's
> related to the initial bindings.
>
> I have a table in the master section which lists items and when the
> editor first fires up, it binds the fields (mainly text fields) in the
> details section to the selected item in the master table.
> This binding is done like this:-
>
>
> IWidgetValueProperty textProp = WidgetProperties.text(SWT.Modify);
>
> IObservableValue uiObs = textProp.observeDelayed(400, textField);
> IObservableValue modelObs;
>
> if (object instanceof IObservableValue) {
> modelObs = EMFEditProperties.value(domain,
> feature).observeDetail(
> (IObservableValue) object);
> } else {
> modelObs = EMFEditProperties.value(domain,
> feature).observe(object);
> }
>
> binding = bindingCtxt.bindValue(uiObs, modelObs);
>
>
> This binding causes the ValueChange event to be fired 4 times - so if I
> have 6 text fields bound then I get 24 ValueChangeEvents.
>
> Once the initial binding has been done, if i then change the value of
> any one of those text fields in the details section, I only get one
> ValueChangeEvent.
>
> So it's that first binding that's causing the extra change events. Any
> idea why that might be?
|
|
|
|
|
|
|
|
Re: EMF Validation called 4 times for each binding [message #899637 is a reply to message #899591] |
Wed, 01 August 2012 11:59   |
Eclipse User |
|
|
|
Argh, I've nearly got it all working now - except I can't get a table to bind properly.
So as well as some text fields and combos, I have a table in the details section which should be bound to a collection within the selected item in the master table.
I've currently got the binding written like this:-
IObservableList list = EMFObservables.observeDetailList(
Realm.getDefault(),
EMFProperties.value(ModelPackage.Literals.MODEL__ITEMS).observeDetail(sel),
detailsTableFeature);
ViewerSupport.bind(detailsTableViewer, list,
EMFProperties.values(columnFeatures));
But that doesn't work - the details table is empty.
However, if I use the following code:-
IObservableList list = EMFObservables.observeList(Realm.getDefault(),
model.getItems().get(1),
detailsTableFeature);*/
it will show the correct list of sub-items for item 1 in the model.
So I'm close - I just need to know what the 2nd argument to observeDetailList() should look like.
|
|
|
Re: EMF Validation called 4 times for each binding [message #899725 is a reply to message #899637] |
Thu, 02 August 2012 02:29   |
Eclipse User |
|
|
|
Am 01.08.12 17:59, schrieb Simon Barnett:
> Argh, I've nearly got it all working now - except I can't get a table to
> bind properly.
>
> So as well as some text fields and combos, I have a table in the details
> section which should be bound to a collection within the selected item
> in the master table.
>
> I've currently got the binding written like this:-
>
> IObservableList list = EMFObservables.observeDetailList(
> Realm.getDefault(),
>
> EMFProperties.value(ModelPackage.Literals.MODEL__ITEMS).observeDetail(sel),
> detailsTableFeature);
>
> ViewerSupport.bind(detailsTableViewer, list,
> EMFProperties.values(columnFeatures));
>
IObservableList list =
EMFProperties.list(ModelPackage.Literals.MODEL__ITEMS).observeDetail(sel);
ViewerSupport.bind(detailsTableViewer,
list,EMFProperties.values(columnFeatures));
*You don't use EMFObservables any more at all*
Tom
|
|
|
Re: EMF Validation called 4 times for each binding [message #899751 is a reply to message #899725] |
Thu, 02 August 2012 04:18  |
Eclipse User |
|
|
|
Ah, thanks Tom - it turns out I'd tried that earlier but it just caused an error about the columns not having a label provider. But when I looked at the code again this morning, I'd accidentally moved the column setup code to below the bind code - doh!
Thanks a lot for your invaluable help on this one. Much appreciated!
|
|
|
Powered by
FUDForum. Page generated in 0.09775 seconds