Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Binding details table to validation
Binding details table to validation [message #1060967] Wed, 29 May 2013 10:53 Go to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
Hi,

I've got a straight-forward Master-Details set-up which validates the details of the selected item in the Master table using the EMF model.

This is all working fine apart from one thing - I have a table in the Details section and the contents of this table are not validated when they are changed.

I've got the following code which makes sure that changes to this table are reflected in the model:-

ViewerSupport.bind(
				detailsTableViewer,
				EMFProperties.list(detailsTableFeature).observeDetail(sel),
				EMFProperties.values(columnFeatures.keySet().toArray(
						new EStructuralFeature[0])));


but it doesn't validate the changes until I save the model.

Any ideas?

Thanks,
Simon
Re: Binding details table to validation [message #1060997 is a reply to message #1060967] Wed, 29 May 2013 13:21 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Simon,

What's causing the validation to kick in at other times? Note that the
latest version of EMF supports generating an editor with live validation:

http://ed-merks.blogspot.de/2013/01/decorating-with-emf.html


On 29/05/2013 12:53 PM, Simon Barnett wrote:
> Hi,
>
> I've got a straight-forward Master-Details set-up which validates the
> details of the selected item in the Master table using the EMF model.
>
> This is all working fine apart from one thing - I have a table in the
> Details section and the contents of this table are not validated when
> they are changed.
>
> I've got the following code which makes sure that changes to this
> table are reflected in the model:-
>
> ViewerSupport.bind(
> detailsTableViewer,
> EMFProperties.list(detailsTableFeature).observeDetail(sel),
> EMFProperties.values(columnFeatures.keySet().toArray(
> new EStructuralFeature[0])));
>
> but it doesn't validate the changes until I save the model.
>
> Any ideas?
>
> Thanks,
> Simon


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Binding details table to validation [message #1061031 is a reply to message #1060997] Wed, 29 May 2013 15:23 Go to previous messageGo to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
That's a very good question. I'm not sure.

When we create text fields in the details section, we do it like this:-

/* create the label */
FormHelper.createTitleColorLabel(detailsClient, label + ":");

/* create the text field */
Text text = FormHelper.createTextField(detailsClient);
GridData data = new GridData(GridData.FILL_HORIZONTAL);
data.horizontalSpan = 2;
text.setLayoutData(data);

bindingCtxt.bindValue(
	WidgetProperties.text(SWT.Modify).observeDelayed(400, text),
	EMFEditProperties.value(domain, feature).observeDetail(sel));


and I thought it was that that triggered the validation to run?

We are not using the editor that is generated automatically, so we can't use the tree-based validation thing mentioned in that link. Our UI looks more like the UI for editing plugins.xml in many respects.
Re: Binding details table to validation [message #1061052 is a reply to message #1061031] Wed, 29 May 2013 16:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Simon,

Comments below.

On 29/05/2013 5:23 PM, Simon Barnett wrote:
> That's a very good question. I'm not sure.
>
> When we create text fields in the details section, we do it like this:-
>
>
> /* create the label */
> FormHelper.createTitleColorLabel(detailsClient, label + ":");
>
> /* create the text field */
> Text text = FormHelper.createTextField(detailsClient);
> GridData data = new GridData(GridData.FILL_HORIZONTAL);
> data.horizontalSpan = 2;
> text.setLayoutData(data);
>
> bindingCtxt.bindValue(
> WidgetProperties.text(SWT.Modify).observeDelayed(400, text),
> EMFEditProperties.value(domain, feature).observeDetail(sel));
>
>
> and I thought it was that that triggered the validation to run?
The data binding integration doesn't generally invoke a full model
validation; perhaps Tom will comment...
>
> We are not using the editor that is generated automatically, so we
> can't use the tree-based validation thing mentioned in that link.
It works with Eclipse's LabelProvider (decorating the icons) so can work
with any JFace view..
> Our UI looks more like the UI for editing plugins.xml in many respects.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Binding details table to validation [message #1061190 is a reply to message #1061052] Thu, 30 May 2013 13:14 Go to previous messageGo to next message
Simon Barnett is currently offline Simon BarnettFriend
Messages: 28
Registered: July 2012
Junior Member
Ah, you're right.

The validation is actually initiated by a validation status provider which has been added to the binding context, as follows:-

bindingCtxt.addValidationStatusProvider(new ValidationStatusProvider() {

	@Override
	public IObservableValue getValidationStatus() {
		/* validate the model */
		return new ComputedValue() {

			@Override
			protected Object calculate() {
				return BasicDiagnostic.toIStatus(Diagnostician.INSTANCE.validate((Impl) (editingDomain.getResourceSet().getResources().get(0).getContents().get(0))));
			}
		};
	}

	@Override
	public IObservableList getTargets() {
		return null;
	}

	@Override
	public IObservableList getModels() {
		return null;
	};
});


When I add a text field to the details part of the form, I use the following code:-

bindingCtxt.bindValue(
	WidgetProperties.text(SWT.Modify).observeDelayed(400, text),
	EMFEditProperties.value(domain, feature).observeDetail(sel));


but when I add a table, I use:-

ViewerSupport.bind(
	detailsTableViewer,
	EMFProperties.list(detailsTableFeature).observeDetail(sel),
	EMFProperties.values(columnFeatures.keySet().toArray(
			new EStructuralFeature[0])));


As the table version has no connection to the binding context, my guess would be that changes to it don't invoke the validation through the validation status provider.

Does that sound sensible? And if so, how would I fix that?
Re: Binding details table to validation [message #1061194 is a reply to message #1061190] Thu, 30 May 2013 13:22 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Simon,

That's beyond skills in data binding. Perhaps is a general data binding
(JFace) question or perhaps someone with more knowledge will chime in
here...


On 30/05/2013 3:14 PM, Simon Barnett wrote:
> Ah, you're right.
>
> The validation is actually initiated by a validation status provider
> which has been added to the binding context, as follows:-
>
>
> bindingCtxt.addValidationStatusProvider(new ValidationStatusProvider() {
>
> @Override
> public IObservableValue getValidationStatus() {
> /* validate the model */
> return new ComputedValue() {
>
> @Override
> protected Object calculate() {
> return
> BasicDiagnostic.toIStatus(Diagnostician.INSTANCE.validate((Impl)
> (editingDomain.getResourceSet().getResources().get(0).getContents().get(0))));
> }
> };
> }
>
> @Override
> public IObservableList getTargets() {
> return null;
> }
>
> @Override
> public IObservableList getModels() {
> return null;
> };
> });
>
>
> When I add a text field to the details part of the form, I use the
> following code:-
>
>
> bindingCtxt.bindValue(
> WidgetProperties.text(SWT.Modify).observeDelayed(400, text),
> EMFEditProperties.value(domain, feature).observeDetail(sel));
>
>
> but when I add a table, I use:-
>
>
> ViewerSupport.bind(
> detailsTableViewer,
> EMFProperties.list(detailsTableFeature).observeDetail(sel),
> EMFProperties.values(columnFeatures.keySet().toArray(
> new EStructuralFeature[0])));
>
>
> As the table version has no connection to the binding context, my
> guess would be that changes to it don't invoke the validation through
> the validation status provider.
>
> Does that sound sensible? And if so, how would I fix that?


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:EMF based RAP Editor
Next Topic:[CDO] CDOServerExporter and DynamicValueHolder.NIL
Goto Forum:
  


Current Time: Thu Sep 19 14:02:12 GMT 2024

Powered by FUDForum. Page generated in 0.02871 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top