Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [DataBinding] Avoid setting a feature of previously selected element when viewer selection changes
[DataBinding] Avoid setting a feature of previously selected element when viewer selection changes [message #1734465] Wed, 08 June 2016 14:33
Stephan Hildebrandt is currently offline Stephan HildebrandtFriend
Messages: 25
Registered: July 2015
Junior Member
Hi all,

I have the following Xtend code, which sets up a Jface editor:

/**
* The editor consists of a list viewer, which shows all elements in the model, and a combo viewer,
* which shows the current value of the feature "dummyEnum" of the model element selected in the list
* viewer. The items of the combo viewer are retrieved from the item property descriptor's getChoiceOfValue()
* method.
*/

//This is the feature, whose value is selected in the combo viewer. Its type is an enumeration.
val feature = EPackage.Registry.INSTANCE.getEPackage("http://dummydsl/1.0").eAllContents.filter(EAttribute).
findFirst [
name == "dummyEnum"
]

val listViewer = new ListViewer(composite)
GridDataFactory.fillDefaults.align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(listViewer.control)

listViewer.contentProvider = new ObservableListContentProvider

/*
* AllModelElementsObservableList returns all model elements in the editing domain.
*/
listViewer.input = new AllModelElementsObservableList(editingDomain)

/**
* create combo viewer
*/
val comboViewer = new ComboViewer(composite)
GridDataFactory.fillDefaults.align(SWT.FILL, SWT.CENTER).grab(true, false).applyTo(comboViewer.control)

comboViewer.contentProvider = new ObservableListContentProvider
/*
* FeatureChoiceOfValuesObservableList retrieves the item property descriptor for the "dummyEnum" feature of the currently selected model element
* in the list viewer, and returns the result of itemPropertyDescriptor.getChoiceOfValues().
*/
comboViewer.input = new FeatureChoiceOfValuesObservableList(
ViewerProperties.singleSelection.observe(listViewer),
editingDomain,
feature
)

/*
* Bind the selection of the combo viewer to the value of the "dummyEnum" feature of the model element selected in the list viewer.
*/
dataBindingContext.bindValue(
ViewerProperties.singleSelection.observe(comboViewer),
EMFEditProperties.value(jfaceGmcEditor.modelEditingDomain.transactionalEditingDomain, feature).
observeDetail(
ViewerProperties.singleSelection.observe(listViewer)
)
)

Now, the problem is that only model elements of type Dummy have the "dummyEnum" feature, all other elements do not. If the list viewer's selection changes from a Dummy element to another model element, a selection change event is fired, which causes FeatureChoiceOfValuesObservableList to retrieve the item property descriptor for the selected element. However, now there is no item property descriptor because the selected element does not have the dummyEnum feature. Therefore, FeatureChoiceOfValues returns an empty list and fires a list change event. Then, the combo viewer's list of selectable items is cleared and the combo viewer selection becomes "null". This causes another change event to be fired, which is processed by the value binding (last seven lines above), setting the value of the dummyEnum feature of the PREVIOUSLY selected element to null.

What is causing this behavior? I do not fully understand what is happening the data binding layer. How can keep the databinding framework from accidentally modifying the model?


Best regards

Stephan
Previous Topic:Loading models: Loading referenced models of "representations.aird" hangs forever
Next Topic:adding new action to submenu
Goto Forum:
  


Current Time: Sat Jul 24 15:20:52 GMT 2021

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

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

Back to the top