Empty Combo when EMF databinding to a combo in a table viewer [message #1009134] |
Thu, 14 February 2013 14:14 |
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 #1009532 is a reply to message #1009134] |
Fri, 15 February 2013 09:28 |
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
|
|
|
Powered by
FUDForum. Page generated in 0.03352 seconds