Multi-level data binding / granularity with EMF and RCP

I created a model with EMF that represents device settings and the RCP GUI. In the GUI, I have a list for choosing different devices like model (Master).

The model has a list of objects of a small class, which should be displayed in the table (Detail).

The tables themselves must be edited, so to change the settings I have a small part of the GUI with checkboxes, etc. Here the tableitem is a wizard, and all the fields shown in the GUI are details.

Observed for device list:

IObservableValue selection = ViewersObservables.observeSingleSelection(availableDevicesList); 

Table:

 IObservableList list = EMFObservables.observeDetailList(Realm.getDefault(), selection,DevicePackage.Literals.LIST); TableViewer tableViewer = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION); tableViewer.setInput(list); IObservableValue tableSelection = ViewersObservables.observeSingleSelection(tableViewer); 

Editing:

 Spinner field1 = new Spinner(parent, SWT.BORDER); dbc.bindValue(SWTObservables.observeSelection(field1), EMFObservables.observeDetailValue(Realm.getDefault(), tableSelection, DevicePackage.Literals.Value1)); 

When you change the device selection, tables are replaced. But tableSelection has a problem with this. Sometimes it still contains a tableitem value from another device, and sometimes it just contains null. I also have a button that turns on / off according to the check state of all fields. When tableSelection puts null in these fields, the check does not work, and the button is disabled until a record in the table is selected.

I tried to manually set the selection to empty using the listener in the list and:

 tableViewer.setSelection(StructuredSelection.EMPTY, true); 

but that does not do all the work. At least all the "old" values ​​are replaced, but the problem with zero is still encountered.

All I need to do is set tableSelection to an empty state, as after starting the application, when the table element has not yet been selected.

+4
source share
1 answer

I found a solution myself. The problem was actually the spinner herself. He chose the null pointer when the selection was empty and there was no value.

I solved it by providing it with my own converter (from int to int ...), where I return the default if the source is null. Now, checking the correct operation and the correct state of the button on is set correctly.

+2
source

All Articles