Home » Modeling » EMF » EMF-TableViewer databinding Tutorial
() 1 Vote
| | | | |
Re: EMF-TableViewer databinding Tutorial [message #734378 is a reply to message #734355] |
Fri, 07 October 2011 15:10 |
Matteo Miraz Messages: 38 Registered: March 2011 |
Member |
|
|
Hi,
That's exactly what I've done... After a few attempts, I discovered that it was due to the simple environment I created for the example... maybe I forgot to register something, because in a normal environment, everything works smoothly.
However, I tried to insert a sorter (by name) in the JTable, and I simulate the insertion and the renaming of elements in the model.
The first case is ok: new elements are put in the right position of the table,
However, in case of a rename, elements are not re-sorted according to their new name (see the attachment)... Does there is a way to fix it?
Thanks again for the help and the great tutorial
Matteo
[Updated on: Fri, 07 October 2011 15:15] Report message to a moderator
|
|
| |
Re: EMF-TableViewer databinding Tutorial [message #734525 is a reply to message #734468] |
Sat, 08 October 2011 06:39 |
Matteo Miraz Messages: 38 Registered: March 2011 |
Member |
|
|
Hi,
yeah... sorry, I meant a TableViewer!
I did a similar thing for the comparator, and it works pretty well. It sorts the data already in the model and those inserted afterwards, even without a refresh. For what concern renames, the element's label is updated also without a refresh, but the item is only moved if the tableViewer.refresh() is invoked. This for me is an issue, because changes in the model are made by various part of my application, and some of them are not aware of the presence of that tableViewer (hence, they cannot issue a refresh).
To issue that refresh I thought of monitoring the elements shown in the table. In case of any change in the column being used for the ordering (or in those used by the filter), I can force an refresh of the tableViewer. Is this a good solution?
Thanks,
Matteo
|
|
|
Re: EMF-TableViewer databinding Tutorial [message #734534 is a reply to message #734525] |
Sat, 08 October 2011 08:09 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Hi,
You can fix this problem by creating a custom LabelProvider which
instead of fireing a LabelChangedEvent, call
TableViewer#update(elements, new String[] { ... }).
See the JavaDoc for TableViewer#update(), ViewerComparator#isSorterProperty
Tom
Am 08.10.11 08:39, schrieb Matteo:
> Hi,
>
> yeah... sorry, I meant a TableViewer!
>
> I did a similar thing for the comparator, and it works pretty well. It
> sorts the data already in the model and those inserted afterwards, even
> without a refresh. For what concern renames, the element's label is
> updated also without a refresh, but the item is only moved if the
> tableViewer.refresh() is invoked. This for me is an issue, because
> changes in the model are made by various part of my application, and
> some of them are not aware of the presence of that tableViewer (hence,
> they cannot issue a refresh).
>
> To issue that refresh I thought of monitoring the elements shown in the
> table. In case of any change in the column being used for the ordering
> (or in those used by the filter), I can force an refresh of the
> tableViewer. Is this a good solution?
> Thanks,
> Matteo
|
|
| |
Re: EMF-TableViewer databinding Tutorial [message #735081 is a reply to message #734534] |
Mon, 10 October 2011 21:35 |
Vincenzo Caselli Messages: 51 Registered: July 2009 |
Member |
|
|
Hi Tom and Matteo,
I tried update(), but did not sorted the item correctly, while refresh() did it right.
Here is my code, are there bad side-effects with it?
Vincenzo
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
tableViewer.setContentProvider(listContentProvider);
//
IObservableMap[] observeMaps = EMFObservables.observeMaps(
listContentProvider.getKnownElements(),
new EStructuralFeature[] { Literals.AUTHOR__NAME,
Literals.AUTHOR__SURNAME });
//*******************************************************************************//
//******** Changes on the code generated by WindowBuilder *********//
//*******************************************************************************//
ObservableMapLabelProvider labelProvider = new ObservableMapLabelProvider(observeMaps);
labelProvider.addListener(new ILabelProviderListener() {
@Override
public void labelProviderChanged(LabelProviderChangedEvent event) {
if (event.getElement()!=null) {
tableViewer.refresh();
}
}
});
tableViewer.setLabelProvider(labelProvider);
//*******************************************************************************//
//
IObservableList libraryListAuthorObserveList = EMFObservables
.observeList(Realm.getDefault(), library,
Literals.LIBRARY__LIST_AUTHOR);
tableViewer.setInput(libraryListAuthorObserveList);
//
return bindingContext;
}
[Updated on: Mon, 10 October 2011 22:05] Report message to a moderator
|
|
|
Re: EMF-TableViewer databinding Tutorial [message #735249 is a reply to message #735081] |
Tue, 11 October 2011 10:35 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
When calling update(element,new String[] {"authorSurname"}) you need to
specialize your ViewerComparator/ViewerFilter!
Tom
Am 10.10.11 23:35, schrieb Vincenzo Caselli:
> Hi Tom and Matteo,
> I tried update(), but did not sorted the item correctly, while refresh()
> did it right.
> Here is my code, are there bad side-effects with it?
>
>
> protected DataBindingContext initDataBindings() {
> DataBindingContext bindingContext = new DataBindingContext();
> //
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
> tableViewer.setContentProvider(listContentProvider);
> //
> IObservableMap[] observeMaps = EMFObservables.observeMaps(
> listContentProvider.getKnownElements(),
> new EStructuralFeature[] { Literals.AUTHOR__NAME,
> Literals.AUTHOR__SURNAME });
>
> //*******************************************************************************//
>
> ObservableMapLabelProvider labelProvider = new
> ObservableMapLabelProvider(observeMaps);
> labelProvider.addListener(new ILabelProviderListener() {
> @Override
> public void labelProviderChanged(LabelProviderChangedEvent
> event) {
> if (event.getElement()!=null) {
> tableViewer.refresh();
> }
> }
> });
> tableViewer
> .setLabelProvider(labelProvider);
>
> //*******************************************************************************//
>
> //
> IObservableList libraryListAuthorObserveList = EMFObservables
> .observeList(Realm.getDefault(), library,
> Literals.LIBRARY__LIST_AUTHOR);
> tableViewer.setInput(libraryListAuthorObserveList);
> //
> return bindingContext;
> }
>
>
>
|
|
|
Goto Forum:
Current Time: Fri Apr 26 06:06:24 GMT 2024
Powered by FUDForum. Page generated in 0.04642 seconds
|