Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Databinding] EMF and JFace Master/Detail Databinding going in the wrong direction(Master gets updated with previous seleted Objects)
[Databinding] EMF and JFace Master/Detail Databinding going in the wrong direction [message #1050697] Sat, 27 April 2013 15:56 Go to next message
Marina Knieling is currently offline Marina Knieling
Messages: 78
Registered: February 2013
Member
Hi community,

ok, how do I explain this in an easy way?
I am in a e4/OSGi environment with EMF models.

I have a JFace TableViewer that displays a list of customers (master). This table is populated by an OSGi service that provides the customer list. I've set up an EMFDatabindingContext in order to listen for changes in the list (customers added).

EMFDataBindingContext bindingContext = new EMFDataBindingContext();
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
		
// define label provider for databinding
[ some IObservableMaps with EMFProperties here ]
		
IObservableMap[] observeMaps = {customerID, familyName, firstName, birthDate, accountStatus};

tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
tableViewer.setContentProvider(listContentProvider);
WritableList allCustomersCustServiceObserveList = new WritableList(custService.getAllCustomers(), Customer.class);
tableViewer.setInput(allCustomersCustServiceObserveList);


Quote:
A side question: Do I actually need the DatabindingContext for the JFace viewer bindings? In fact, I didn't use it and it works for this table. So I presume not. But another one in the details view doesn't work. But that might be another problem.


This table viewer has a selection changed listener that changes the active Customer in my OSGi-Service so I have access to that object in my CustomerDetailsView.

In my details view (in another part) there are 4 tabs in a tabfolder that show different properties of the Customer object. I've setup a Databinding for all those parts as well. The watched object is the active Customer which is again provided by the OSGi-Service. I don't know whether this is the problem, that I share one object between the master and the detail for all objects in the list.

Well, what now happens is:
When I click on any Customer A the first time in the table viewer, the details get displayed in the details view (text fields with name, address etc.). When I now click on another Customer B the details of Customer A get overwritten by Customer B (same name and address appear now on both Customers). The details of Customer B are correctly displayed in the details view. When I now click on a third Customer C, both Customer A and B get overwritten by the details of Customer C. This goes on for every further Customer.

At first I thought the objects get somehow overwritten, so I printed them out on the console, but I still get different Customer objects (indicated by the memory address of each object).

Here is a snippet from my databinding in the details view:

EMFDataBindingContext bindingContext = new EMFDataBindingContext();
activeCustomer = custService.getActiveCustomer(); // this is my OSGi-Service
System.out.println("activeCustomer: " + activeCustomer);
IObservableValue observeTextTextFirstNamesObserveWidget = WidgetProperties.text(SWT.Modify).observe(textFirstNames);
IObservableValue activeCustomernameCustServiceObserveValue = EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__NAME).observe(activeCustomer);
bindingContext.bindValue(observeTextTextFirstNamesObserveWidget, activeCustomernameCustServiceObserveValue, null, null);
//
IObservableValue observeTextTextFamilyNameObserveWidget = WidgetProperties.text(SWT.Modify).observe(textFamilyName);
IObservableValue activeCustomerfamilyNameCustServiceObserveValue = EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__FAMILY_NAME).observe(activeCustomer);
bindingContext.bindValue(observeTextTextFamilyNameObserveWidget, activeCustomerfamilyNameCustServiceObserveValue, null, null);
//
IObservableValue observeTextTextFlatPropertyObserveWidget = WidgetProperties.text(SWT.Modify).observe(textFlatProperty);
IObservableValue activeCustomerpropertyNameCustServiceObserveValue = EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__PROPERTY_NAME).observe(activeCustomer);
bindingContext.bindValue(observeTextTextFlatPropertyObserveWidget, activeCustomerpropertyNameCustServiceObserveValue, null, null);
		


There are some more for the rest of the text fields.

I have no idea what is happening here. Maybe the objects get overwritten anyway or I've messed it up somewhere else. If you need some more code, let me know. I'm at my wits' end with this. All I want to do is display the details of the Customer the user clicks in the table and update the table if the user edits the selected Customer in the details view.

Please help.

Thanks in advance.
Marina
Re: [Databinding] EMF and JFace Master/Detail Databinding going in the wrong direction [message #1051731 is a reply to message #1050697] Mon, 29 April 2013 06:52 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5422
Registered: July 2009
Senior Member
You are using Master-Detail wrong! It looks like you are creating new
bindings whenever the customer changes (without removing the old ones -
which is why you are overwriting the values in previous bound objects).

What happens is the following:
* Start:
Text-Field bound to "Customer A".name (new)
* Change to "Customer B"
Text-Field bound to "Customer A".name (old)
Text-Field bound to "Customer B".name (new)
* Change to "Customer C"
Text-Field bound to "Customer A".name (old)
Text-Field bound to "Customer B".name (old)
Text-Field bound to "Customer C".name (new)
* ...

What you should have done really is to:
a) Create a WritableValue
b) Bind this value to the Text-Field (...observeDetail)
c) On change simply call WritableValue#setValue()

Finally: No you don't need an EMFDatabindingContext to set up viewers.

Tom

On 27.04.13 17:56, Marina Knieling wrote:
> Hi community,
>
> ok, how do I explain this in an easy way?
> I am in a e4/OSGi environment with EMF models.
>
> I have a JFace TableViewer that displays a list of customers (master).
> This table is populated by an OSGi service that provides the customer
> list. I've set up an EMFDatabindingContext in order to listen for
> changes in the list (customers added).
>
> EMFDataBindingContext bindingContext = new EMFDataBindingContext();
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
>
> // define label provider for databinding
> [ some IObservableMaps with EMFProperties here ]
>
> IObservableMap[] observeMaps = {customerID, familyName, firstName,
> birthDate, accountStatus};
>
> tableViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
> tableViewer.setContentProvider(listContentProvider);
> WritableList allCustomersCustServiceObserveList = new
> WritableList(custService.getAllCustomers(), Customer.class);
> tableViewer.setInput(allCustomersCustServiceObserveList);
>
>
> Quote:
>> A side question: Do I actually need the DatabindingContext for the
>> JFace viewer bindings? In fact, I didn't use it and it works for this
>> table. So I presume not. But another one in the details view doesn't
>> work. But that might be another problem.
>
>
> This table viewer has a selection changed listener that changes the
> active Customer in my OSGi-Service so I have access to that object in my
> CustomerDetailsView.
>
> In my details view (in another part) there are 4 tabs in a tabfolder
> that show different properties of the Customer object. I've setup a
> Databinding for all those parts as well. The watched object is the
> active Customer which is again provided by the OSGi-Service. I don't
> know whether this is the problem, that I share one object between the
> master and the detail for all objects in the list.
>
> Well, what now happens is:
> When I click on any Customer A the first time in the table viewer, the
> details get displayed in the details view (text fields with name,
> address etc.). When I now click on another Customer B the details of
> Customer A get overwritten by Customer B (same name and address appear
> now on both Customers). The details of Customer B are correctly
> displayed in the details view. When I now click on a third Customer C,
> both Customer A and B get overwritten by the details of Customer C. This
> goes on for every further Customer.
>
> At first I thought the objects get somehow overwritten, so I printed
> them out on the console, but I still get different Customer objects
> (indicated by the memory address of each object).
>
> Here is a snippet from my databinding in the details view:
>
>
> EMFDataBindingContext bindingContext = new EMFDataBindingContext();
> activeCustomer = custService.getActiveCustomer(); // this is my
> OSGi-Service
> System.out.println("activeCustomer: " + activeCustomer);
> IObservableValue observeTextTextFirstNamesObserveWidget =
> WidgetProperties.text(SWT.Modify).observe(textFirstNames);
> IObservableValue activeCustomernameCustServiceObserveValue =
> EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__NAME).observe(activeCustomer);
>
> bindingContext.bindValue(observeTextTextFirstNamesObserveWidget,
> activeCustomernameCustServiceObserveValue, null, null);
> //
> IObservableValue observeTextTextFamilyNameObserveWidget =
> WidgetProperties.text(SWT.Modify).observe(textFamilyName);
> IObservableValue activeCustomerfamilyNameCustServiceObserveValue =
> EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__FAMILY_NAME).observe(activeCustomer);
>
> bindingContext.bindValue(observeTextTextFamilyNameObserveWidget,
> activeCustomerfamilyNameCustServiceObserveValue, null, null);
> //
> IObservableValue observeTextTextFlatPropertyObserveWidget =
> WidgetProperties.text(SWT.Modify).observe(textFlatProperty);
> IObservableValue activeCustomerpropertyNameCustServiceObserveValue =
> EMFProperties.value(TICDModelPackage.Literals.CUSTOMER__PROPERTY_NAME).observe(activeCustomer);
>
> bindingContext.bindValue(observeTextTextFlatPropertyObserveWidget,
> activeCustomerpropertyNameCustServiceObserveValue, null, null);
>
>
>
> There are some more for the rest of the text fields.
>
> I have no idea what is happening here. Maybe the objects get overwritten
> anyway or I've messed it up somewhere else. If you need some more code,
> let me know. I'm at my wits' end with this. All I want to do is display
> the details of the Customer the user clicks in the table and update the
> table if the user edits the selected Customer in the details view.
>
> Please help.
>
> Thanks in advance.
> Marina
Previous Topic:exporting cdo server feature product
Next Topic:[CDO] Tables in DB without Primary Key
Goto Forum:
  


Current Time: Sat Oct 25 09:01:28 GMT 2014

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

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