Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Empty Combo when EMF databinding to a combo in a table viewer
Empty Combo when EMF databinding to a combo in a table viewer [message #1009134] Thu, 14 February 2013 09:14 Go to next message
Eclipse User
Hello guys,
I have an EMF model and a table viewer to display it. The point is that
one column should display a combo box which is a cell editor. This
means, the selected value then should be set into my EMF model. The
problem is that the input of the combo box should be EMF data bound. I
have the following code:

TableViewer tableViewer = new TableViewer(composite, SWT.BORDER |
SWT.FULL_SELECTION);
Table table = tableViewer.getTable();
ComboBoxViewerCellEditor comboBoxCellEditor = new
ComboBoxViewerCellEditor(table, SWT.READ_ONLY);
TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer,
SWT.NONE);
tableViewerColumn.setEditingSupport(new EditingSupport(tableViewer){
@Override
protected CellEditor getCellEditor(Object element) {
return comboBoxCellEditor;
}
@Override
protected boolean canEdit(Object element) {
return true;
}
@Override
protected Object getValue(Object element) {
return element.toString();
}
@Override
protected void setValue(Object element, Object value) {
if(element instanceof MyObject1 && value instanceof MyObject2){
((MyObject1) element).setObject((MyObject2) value);
}
}
});

The binding then is realised as follows:

ObservableListContentProvider listContentProvider_2 = new
ObservableListContentProvider();
IObservableSet knownElements = listContentProvider_2.getKnownElements();
IObservableMap[] observeMaps_2 =
EMFObservables.observeMaps(knownElements, new
EStructuralFeature[]{Literals.MYOBJECT2__NAME});
comboBoxCellEditor.setLabelProvider(new
ObservableMapLabelProvider(observeMaps_2));
comboBoxCellEditor.setContentProvider(listContentProvider_2);

My problem is now that a combo box is displayed but it remains empty.
What am I doing wrong?

best regards,
Gilbert
Re: Empty Combo when EMF databinding to a combo in a table viewer [message #1009168 is a reply to message #1009134] Thu, 14 February 2013 10:25 Go to previous messageGo to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 866
Registered: July 2009
Senior Member
this is how I use combos with DataBinding:
The features are often enums. Not sure this would work for you?

cmbLevelViewer.setContentProvider(new ArrayContentProvider());
		cmbLevelViewer.setLabelProvider(new LabelProvider());
		cmbLevelViewer.setInput(LevelKind.VALUES);

		IEMFValueProperty toleranceLevelProperty = EMFEditProperties
				.value(editingService.getEditingDomain(), LibraryPackage.Literals.TOLERANCE__LEVEL);
		IValueProperty selectionProperty = ViewerProperties.singleSelection();
		
		context.bindValue(selectionProperty.observe(cmbLevelViewer),
				toleranceLevelProperty.observe(tolerance), null, null);
Re: Empty Combo when EMF databinding to a combo in a table viewer [message #1009532 is a reply to message #1009134] Fri, 15 February 2013 04:28 Go to previous message
Eclipse User
I found out that not only a content provider is needed but the input
must be set. Why is that?
But ,after I set the input (setInput(..)) I gout an exception that the
given input must be of type IObservableList and it was only an
IObservableSet. I solved this problem not with EMF databinding but with
"normal" databinding like this:

ObservableListContentProvider listContentProvider_2 = new
ObservableListContentProvider();
IObservableMap observeMap =
PojoObservables.observeMap(listContentProvider_2.getKnownElements(),
MyObject2.class, "name");
comboBoxCellEditor.setLabelProvider(new
ObservableMapLabelProvider(observeMap));
comboBoxCellEditor.setContentProvider(listContentProvider_2);
IObservableList selfList =
Properties.selfList(MyObject2.class).observe(myModel.getMyObjects());
comboBoxCellEditor.setInput(selfList);

This does exactly what I want. But one strange thing left is that
implementing a label provider for the specific column is ignored. So I
had to implement an anonymous lable provider for the table viewer in
which I have to determine distinguish between the different columns.
That's not so good because when columns are added or removed this label
provider must be adapted. Better, each column has its own label provider.

best regards,
Gilbert
Previous Topic:[EMF Edit] Accessing attributes of children containment references
Next Topic:Xcore - derived features and reflective feature delegation
Goto Forum:
  


Current Time: Mon Apr 21 00:44:53 EDT 2014

Powered by FUDForum. Page generated in 0.02963 seconds