Home » Modeling » EMF » TableViewer data binding with EMF model - Problems syncing number columns
| TableViewer data binding with EMF model - Problems syncing number columns [message #756315] |
Fri, 11 November 2011 17:11  |
Stein Erik Messages: 9 Registered: September 2011 |
Junior Member |
|
|
Hi,
I have problems synchronizing table columns with non-String EMF attributes when the content of a column cell is updated interactively. Things runs smoothly for String (Target) to EString (EMF Model) sync.
I hoped the type conversion was either performed automatically, or an UpdateValueStrategy could be injected easily. But, cannot figure it out! Suspect there is something fundamental that I am missing...
EMFDataBindingContext and ObservableValueEditingSupport.create(....) are used (in my class ProjectInfoView.java).
Please find an attached test case w/a small EMF model. (The DEFAULT_PATH constant in CampliModelXMIResource.java needs to be updated by a user in order to read the EMF model from the included xmi file)
The Table appears when either the nodes "Pampas" or "Hurramegrundt" is selected in the Model Explorer View. Then you are ready to try interactively updating the model for different data types.
I have tried running this on Mac and Windows, same performance. Using Eclipse 3.7, Indigo.
Help appreciated! Thanks Stein Erik
[Updated on: Fri, 11 November 2011 17:13] Report message to a moderator
|
|
| |
| Re: TableViewer data binding with EMF model - Problems syncing number columns [message #756416 is a reply to message #756332] |
Sat, 12 November 2011 18:00   |
Stein Erik Messages: 9 Registered: September 2011 |
Junior Member |
|
|
Tom Schindl wrote on Sat, 12 November 2011 01:23Am 11.11.11 23:11, schrieb Stein Erik:
.....
So is the problem performance or that you don't get a conversion support
when it comes to none string values like float, Float, ... and if it the
conversion support which one is not working as expected?
Tom
Thanks for follow-up (and btw thx for all your nice tutorials and example codes).
I have not experienced any performance issues to date, it's a functionality issue. Summary at the bottom. Some details first:
(I) JFace TableViewer - EMF Databinding (test in my 'ProjectInfoView')
Using TableViewer/EMFDataBindingContext/ObservableValueEditingSupport/ TextCellEditor, the conversion String (Target) - EString (Model) works.
Not working: Automated conversion for String - EInt/EIntegerObject/EFloat/EFloatObject/EDouble/EDoubleObject/EBoolean/EBooleanObject
//Extract from text code
final TableViewer viewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);
...
ObservableListContentProvider cp = new ObservableListContentProvider();
viewer.setContentProvider(cp);
...
IValueProperty property = EMFEditProperties.value(editingDomain, CamplioPackage.Literals.VENDOR__VALUE_INTEGER_OBJECT);
TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEAD);
column.getColumn().setText("EIntegerObject");
column.getColumn().setWidth(100);
column.getColumn().setMoveable(true);
column.setLabelProvider(new ObservableMapCellLabelProvider(property.observeDetail(set)));
// make column editable
column.setEditingSupport(ObservableValueEditingSupport
.create(viewer,
dbc, // EMFDataBindingContext
new TextCellEditor(table),
CellEditorProperties.control().value(WidgetProperties.text(SWT.Modify)),
property));
(II) SWT Widget - EMF DataBinding (test in 'InformationFormView')
Works nicely, no problem for any of the data types listed above.
Summary of my concerns for TableViewer-EMF Databinding; (a) Automated data type conversion does not seem to work for most datatypes, and (b) I cannot find an easy way to inject an UpdateValueStrategy for customized conversion & validation (hints appreciated!).
Attached is updated & extended test code.
[Updated on: Sat, 12 November 2011 18:02] Report message to a moderator
|
|
|
| Re: TableViewer data binding with EMF model - Problems syncing number columns [message #756438 is a reply to message #756416] |
Sun, 13 November 2011 05:46   |
Thomas Schindl Messages: 4462 Registered: July 2009 |
Senior Member |
|
|
Hi,
Ok I think I see the problem.
The ObservableValueEditingSupport is creating a UpdateValueStrategy
which is a problem when used with am EMF-Observable because the target
type there is the EStructuraleFeature and the features type and so the
conversion between those is not working as expected.
I've attached you a specialized EditingSupport which fixes this by
creating an EMFUpdateValueStrategy.
Tom
Am 13.11.11 00:00, schrieb Stein Erik:
> Tom Schindl wrote on Sat, 12 November 2011 01:23
>> Am 11.11.11 23:11, schrieb Stein Erik:
>> .....
>> So is the problem performance or that you don't get a conversion support
>> when it comes to none string values like float, Float, ... and if it the
>> conversion support which one is not working as expected?
>>
>> Tom
>
> Thanks for follow-up (and btw thx for all your nice tutorials and example codes).
>
> I have not experienced any performance issues to date, it's a functionality issue. Summary at the bottom. Some details first:
>
> (I) JFace TableViewer - EMF Databinding (test in my 'ProjectInfoView')
> Using TableViewer, EMFDataBindingContext, ObservableValueEditingSupport, TextCellEditor the conversion from String (Target) - EString (Model) works.
>
> Not working: Automated conversion for String - EInt/EIntegerObject/EFloat/EFloatObject/EDouble/EDoubleObject/EBoolean/EBooleanObject
>
> //Extract from text code
> final TableViewer viewer = new TableViewer(composite, SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI | SWT.CHECK);
> ..
> ObservableListContentProvider cp = new ObservableListContentProvider();
> viewer.setContentProvider(cp);
> ..
> IValueProperty property = EMFEditProperties.value(editingDomain, CamplioPackage.Literals.VENDOR__VALUE_INTEGER_OBJECT);
> TableViewerColumn column = new TableViewerColumn(viewer, SWT.LEAD);
> column.getColumn().setText("EIntegerObject");
> column.getColumn().setWidth(100);
> column.getColumn().setMoveable(true);
> column.setLabelProvider(new ObservableMapCellLabelProvider(property.observeDetail(set)));
> // make column editable
> column.setEditingSupport(ObservableValueEditingSupport
> .create(viewer,
> dbc, // EMFDataBindingContext
> new TextCellEditor(table),
> CellEditorProperties.control().value(WidgetProperties.text(SWT.Modify)),
> property));
>
>
> (II) SWT Widget - EMF DataBinding (test in 'InformationFormView')
> Works nicely, no problem for any of the data types listed above.
>
> Summary of my concerns for TableViewer-EMF Databinding; (a) Automated data type conversion does not seem to work for most datatypes, and (b) I cannot find an easy way to inject an UpdateValueStrategy for customized conversion& validation (hints appreciated!).
>
> Attached is updated& extended test code.
package aa.camplio.viewexample.views.util;
import org.eclipse.core.databinding.Binding;
import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.property.value.IValueProperty;
import org.eclipse.emf.databinding.EMFDataBindingContext;
import org.eclipse.emf.databinding.EMFUpdateValueStrategy;
import org.eclipse.jface.databinding.viewers.ObservableValueEditingSupport;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.ViewerCell;
public abstract class EMFObservableValueEditingSupport extends ObservableValueEditingSupport {
private EMFDataBindingContext dbc;
public EMFObservableValueEditingSupport(ColumnViewer viewer,
EMFDataBindingContext dbc) {
super(viewer, dbc);
this.dbc = dbc;
}
public static EditingSupport create(ColumnViewer viewer,
EMFDataBindingContext dbc, final CellEditor cellEditor,
final IValueProperty cellEditorProperty,
final IValueProperty elementProperty) {
return new EMFObservableValueEditingSupport(viewer, dbc) {
protected IObservableValue doCreateCellEditorObservable(
CellEditor cellEditor) {
return cellEditorProperty.observe(cellEditor);
}
protected IObservableValue doCreateElementObservable(
Object element, ViewerCell cell) {
return elementProperty.observe(element);
}
protected CellEditor getCellEditor(Object element) {
return cellEditor;
}
};
}
protected Binding createBinding(IObservableValue target,
IObservableValue model) {
return dbc.bindValue(target, model, new EMFUpdateValueStrategy(
UpdateValueStrategy.POLICY_CONVERT), null);
}
}
|
|
|
| Re: TableViewer data binding with EMF model - Problems syncing number columns [message #756469 is a reply to message #756438] |
Sun, 13 November 2011 13:33   |
Stein Erik Messages: 9 Registered: September 2011 |
Junior Member |
|
|
Thx Tom, that made wonders!
I wish I had the skills to understand what's going on under the hood of the Databinding APIs so that I could make such improvements and contribute myself. And I will attempt that in the near future;
Approx one month from now I will revert to try injecting customized conversion & validation in the TableViewerColumn - EMF databinding pipeline. The idea is to use UpdateValueStrategy for two-way, on-the-fly unit conversion (e.g. 'length' displayed as km, metres, dm, cm, mm, inch, ft, etc. while the model always store the length value in SI metric metres).
[Updated on: Sun, 13 November 2011 13:34] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Wed May 22 19:31:35 EDT 2013
Powered by FUDForum. Page generated in 0.01766 seconds
|