Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Validation error while data binding
icon5.gif  Validation error while data binding [message #1760527] Fri, 28 April 2017 06:16 Go to next message
Muniraj K A is currently offline Muniraj K AFriend
Messages: 11
Registered: May 2016
Junior Member
I am developing an rcp application where I bind my UI widgets in the editor to the model objects. Whenever I modify the text box value in my UI, the bound model object's attribute is updated properly but it however shows a validation error message called "An error occurred while setting the value" in my control decorator. No idea why this validation error message is shown every time a character is entered into the text box.

My data binding code is as follows:



public void initDataBinding(EObject selectedObjectDef, EObject selectedObject, Widget widget) {
EMFDataBindingContext bindingContext = new EMFDataBindingContext();
IObservableValue modelObservableVal = EMFObservables.observeValue(selectedObject, selectedObject.eClass()
.getEStructuralFeature(EcucdescriptionPackage.ECUC_TEXTUAL_PARAM_VALUE__VALUE));
ISWTObservableValue targetObservableVal = WidgetProperties.text(SWT.Modify).observe(widget);
Binding bindValue = bindingContext.bindValue(targetObservableVal, modelObservableVal);
ControlDecorationSupport.create(bindValue, SWT.TOP | SWT.LEFT);
}

On further debugging I found this error is thrown by one of the super classes called BasicNotifierImpl#eNotify()

1 public void eNotify(Notification notification)
2 {
3 Adapter[] eAdapters = eBasicAdapterArray();
4 if (eAdapters != null && eDeliver())
5 {
6 for (int i = 0, size = eAdapters.length; i < size; ++i)
7 {
8 eAdapters[i].notifyChanged(notification);
9 }
10 }
11 }

at line no.8 when i == 1, giving java.lang.IllegalStateException: Cannot modify resource set without a write transaction. I tried using an editing domain but still I get the same exception. But in the UI, validation msg shown is "An error occurred while setting the value" even before I use an UpdateValueStrategy validator.

Any help is greatly appreciated. Thanks in anticipation.
Shocked
Re: Validation error while data binding [message #1760543 is a reply to message #1760527] Fri, 28 April 2017 08:05 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29122
Registered: July 2009
Senior Member
This is more of an EMF question. You don't mention it, but I can guess that you're using a transactional editing domain so it's perhaps a GMF application or something like that. You should use EMFEditObservables instead of EMFObservables so that commands are created such that the changes you make use the command stack and support Undo/Redo (and of course happen during a transaction).
Re: Validation error while data binding [message #1760563 is a reply to message #1760543] Fri, 28 April 2017 11:25 Go to previous messageGo to next message
Muniraj K A is currently offline Muniraj K AFriend
Messages: 11
Registered: May 2016
Junior Member
Thank you Mr Ed Merks.. It worked on replacing EMFObservables with EMFEditObservables Smile
Re: Validation error while data binding [message #1760825 is a reply to message #1760563] Wed, 03 May 2017 11:15 Go to previous messageGo to next message
Muniraj K A is currently offline Muniraj K AFriend
Messages: 11
Registered: May 2016
Junior Member
modifying initDataBinding() method as below does not work properly :

public void initDataBinding(EObject selectedObjectDef, EObject selectedObject, Widget widget) {
EMFDataBindingContext bindingContext = new EMFDataBindingContext();
IObservableValue modelObservableVal = EMFEditObservables.observeValue(editingDomain, selectedObject, selectedObject.eClass()
.getEStructuralFeature(EcucdescriptionPackage.ECUC_NUMERICAL_PARAM_VALUE__VALUE));
ISWTObservableValue targetObservableVal = WidgetProperties.text(SWT.Modify).observe(widget);
Binding bindValue = bindingContext.bindValue(targetObservableVal, modelObservableVal);
ControlDecorationSupport.create(bindValue, SWT.TOP | SWT.LEFT);
}

Data binding happens properly when IObservableValue is created for the attribute with id EcucdescriptionPackage.
ECUC_TEXTUAL_PARAM_VALUE__VALUE but does not when it is created for the attribute with id EcucdescriptionPackage.
ECUC_NUMERICAL_PARAM_VALUE__VALUE as in the above code. This is because in the earlier case the bound model object's
(Bean) Attribute TYPE is 'String' but in the latter case it is an 'Object'(binding does not happen). Should I add converter?

What is the mistake I am making? please help me.

[Updated on: Wed, 03 May 2017 11:17]

Report message to a moderator

Re: Validation error while data binding [message #1760833 is a reply to message #1760825] Wed, 03 May 2017 12:55 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29122
Registered: July 2009
Senior Member
It it a serializeable data type? I.e., when the model is serialized, is this value serialized properly as a string and it can be read back in again on deserialization? (You can't expect a non-serializeable data type of be useable in data binding.) What are the symptoms of "not work properly". I.e., what actually happens?
Re: Validation error while data binding [message #1760842 is a reply to message #1760833] Wed, 03 May 2017 14:35 Go to previous messageGo to next message
Muniraj K A is currently offline Muniraj K AFriend
Messages: 11
Registered: May 2016
Junior Member
Thank you for the info Mr Ed Merks. In the 1st case the attribute type 'String' is serializable(binding happens) but in the 2nd case the attribute type 'NumericalValueVariationPoint' , an Object, is non serializable(binding does not happen). That seems to be the problem. But how do I make it serializable because its a .class file . I will check if something can be done using Overriding concept. Is there any other solution to address this problem?
Re: Validation error while data binding [message #1760865 is a reply to message #1760842] Wed, 03 May 2017 18:30 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29122
Registered: July 2009
Senior Member
The question was about the EDataType's isSerializable attribute. If you set this to true, then there will be createAbcFromString/convertAbcToString methods in the XyzFactoryImpl. There you just implement the "serialization", i.e, the conversion to a string representation. And that's what you should expect a user will see and will have to enter. To me it sounds like you model design is poor and that you're likely to come back with many follow up questions. My main question to you is "What exactly are you expecting in terms of a UI where a user can enter/bind arbitrary Java objects?"
Re: Validation error while data binding [message #1760958 is a reply to message #1760865] Thu, 04 May 2017 14:58 Go to previous messageGo to next message
Muniraj K A is currently offline Muniraj K AFriend
Messages: 11
Registered: May 2016
Junior Member
Hi Mr Ed Merks, the Model design is not in my control actually. I am just binding my UI widgets to the existing model attributes provided by the artop. The user in my application enters numerical values(Integer or float), I am binding this value in the widget to the existing model object(EcucNumericalParamValue provided by artop)'s attribute called value. After realising that, this value attribute's EDataType is NumericalValueVariationPoint which is not serializable I changed my binding code as follows :

1 public void initDataBinding(EObject selectedObjectDef, EObject selectedObject, Widget widget) {
2 EMFDataBindingContext bindingContext = new EMFDataBindingContext();
3
4 NumericalValueVariationPoint numValueVP = ((EcucNumericalParamValue) selectedObject).getValue();
5 FeatureMap mixedFeatureMap = numValueVP.getMixed();
6 Entry entry = mixedFeatureMap.get(0);
7 EStructuralFeature feature = entry.getEStructuralFeature();
8 ISWTObservableValue modelObservableVal = EMFEditObservables.observeValue(editingDomain, entry, feature);
9
10 ISWTObservableValue targetObservableVal = WidgetProperties.text(SWT.Modify).observe(widget);
11 Binding bindValue = bindingContext.bindValue(targetObservableVal, modelObservableVal);
12 ControlDecorationSupport.create(bindValue, SWT.TOP | SWT.LEFT);
13 }

Now the EDataType of 'feature' is String which should support data binding. But in the above code, I get a compile time error at line no.8 saying "The method observeValue(EditingDomain, EObject, EStructuralFeature) in the type EMFEditObservables is not applicable for the arguments (TransactionalEditingDomain, FeatureMap.Entry, EStructuralFeature)". I am not getting the EObject to pass as the 2nd argument to EMFEditObservables.observeValue() method. I have attached the EcucNumericalParamValueImpl.class file which has the model Object attributes I am binding, for your reference(autosar40.ecucdescription.impl.EcucNumericalParamValueImpl). Or is there a way to bind the Object(NumericalValueVariationPoint) itself? It was difficult for me to implement as per your suggestion in the previous reply, So I did this way. Kindly help me in resolving this problem. Thank you.
Re: Validation error while data binding [message #1761002 is a reply to message #1760958] Fri, 05 May 2017 08:27 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 29122
Registered: July 2009
Senior Member
I can't do anything with a .class file. You can't observe an entry; an entry's value can never change. What features does NumericalValueVariationPoint have, other than the mixed feature? It might be the case that EMFEditObservables.observeValue(editingDomain, numValueVP , feature) works, but I don't know what kind of feature 'feature" is...
Previous Topic:Separate Projects for .genmodel and .ecore
Next Topic:CDO-MOngo OCL query support ?
Goto Forum:
  


Current Time: Fri Jan 19 06:04:39 GMT 2018

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

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