Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » [Databinding/EMF] Double entries in TreeViewer ->MapChangeEvent result set incorrect.
[Databinding/EMF] Double entries in TreeViewer ->MapChangeEvent result set incorrect. [message #743203] Fri, 21 October 2011 04:11 Go to next message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 914
Registered: July 2009
Senior Member
Hi,

Sometimes (It's intermittent) I see double entries appear when adding an
item to a treeviewer which is "databinded". Sometime the entry simply
doesn't appear. A refresh usually solves the problem.

I notice the IMapChangeListener, MapChangeEvent
event.diff.getChangedKeys() returns an empty resultset, so the code to

fireLabelProviderChanged(newEvent) is never called.


In my code below, I add IObservableMap entries for which we add the
IMapChangeListener.


Why is the result set empty, while the listener is called?
Is there any relation to this issue, and the StrutureAdvisor or
TreeFactory ?

rgds Christophe


This is the databinding code. (EMF) to the viewer.
***************************************************

EMFDataBindingContext bindingContext = new EMFDataBindingContext();

ObservableListTreeContentProvider cp = new
ObservableListTreeContentProvider(
new NodeTypeTreeFactoryImpl(editingService.getEditingDomain()),
new NodeTypeTreeStructureAdvisorImpl());
nodeTypeTreeViewer.setContentProvider(cp);
IObservableSet set = cp.getKnownElements();

List<IObservableMap> mapList = Lists.newArrayList();

mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
LibraryPackage.Literals.NODE_TYPE__NAME).observeDetail(set));

mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
LibraryPackage.Literals.NODE_TYPE__EQUIPMENTS).observeDetail(set));

mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
LibraryPackage.Literals.NODE_TYPE__FUNCTIONS).observeDetail(set));

mapList.add(EMFProperties
.value(LibraryPackage.Literals.COMPONENT__NAME).observeDetail(
set));


mapList.add(EMFProperties.value(
LibraryPackage.Literals.EQUIPMENT__EQUIPMENT_CODE)
.observeDetail(set));

IObservableMap[] map = new IObservableMap[mapList.size()];
mapList.toArray(map);

nodeTypeTreeViewer.setLabelProvider(new NodeTypeTreeLabelProvider(map));
IEMFListProperty projects = EMFEditProperties.resource(editingService
.getEditingDomain());

IObservableList nodeTypeObservableList = projects
.observe(nodeTypeResource);
nodeTypeTreeViewer.setInput(nodeTypeObservableList);
Re: [Databinding/EMF] Double entries in TreeViewer -&gt;MapChangeEvent result set incorrect. [message #743218 is a reply to message #743203] Fri, 21 October 2011 04:24 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5281
Registered: July 2009
Senior Member
Entry doubleing must have it's reason in StructureAdvisor or the
underlying ObservableTreeContentProvider. The map stuff is only needed
for label-updateing.

Tom

Am 21.10.11 10:11, schrieb Christophe Bouhier:
> Hi,
>
> Sometimes (It's intermittent) I see double entries appear when adding an
> item to a treeviewer which is "databinded". Sometime the entry simply
> doesn't appear. A refresh usually solves the problem.
>
> I notice the IMapChangeListener, MapChangeEvent
> event.diff.getChangedKeys() returns an empty resultset, so the code to
>
> fireLabelProviderChanged(newEvent) is never called.
>
>
> In my code below, I add IObservableMap entries for which we add the
> IMapChangeListener.
>
>
> Why is the result set empty, while the listener is called?
> Is there any relation to this issue, and the StrutureAdvisor or
> TreeFactory ?
>
> rgds Christophe
>
>
> This is the databinding code. (EMF) to the viewer.
> ***************************************************
>
> EMFDataBindingContext bindingContext = new EMFDataBindingContext();
>
> ObservableListTreeContentProvider cp = new
> ObservableListTreeContentProvider(
> new
> NodeTypeTreeFactoryImpl(editingService.getEditingDomain()),
> new NodeTypeTreeStructureAdvisorImpl());
> nodeTypeTreeViewer.setContentProvider(cp);
> IObservableSet set = cp.getKnownElements();
>
> List<IObservableMap> mapList = Lists.newArrayList();
>
>
> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>
> LibraryPackage.Literals.NODE_TYPE__NAME).observeDetail(set));
>
>
> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>
> LibraryPackage.Literals.NODE_TYPE__EQUIPMENTS).observeDetail(set));
>
>
> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>
> LibraryPackage.Literals.NODE_TYPE__FUNCTIONS).observeDetail(set));
>
> mapList.add(EMFProperties
>
> .value(LibraryPackage.Literals.COMPONENT__NAME).observeDetail(
> set));
>
>
> mapList.add(EMFProperties.value(
> LibraryPackage.Literals.EQUIPMENT__EQUIPMENT_CODE)
> .observeDetail(set));
>
> IObservableMap[] map = new IObservableMap[mapList.size()];
> mapList.toArray(map);
>
> nodeTypeTreeViewer.setLabelProvider(new
> NodeTypeTreeLabelProvider(map));
> IEMFListProperty projects =
> EMFEditProperties.resource(editingService
> .getEditingDomain());
>
> IObservableList nodeTypeObservableList = projects
> .observe(nodeTypeResource);
> nodeTypeTreeViewer.setInput(nodeTypeObservableList);
Re: [Databinding/EMF] Double entries in TreeViewer -&gt;MapChangeEvent result set incorrect. [message #743234 is a reply to message #743218] Fri, 21 October 2011 04:46 Go to previous message
Christophe Bouhier is currently offline Christophe Bouhier
Messages: 914
Registered: July 2009
Senior Member
On 21-10-11 10:24, Tom Schindl wrote:
> Entry doubleing must have it's reason in StructureAdvisor or the
> underlying ObservableTreeContentProvider. The map stuff is only needed
> for label-updateing.
>
Thanks Tom, I spotted the problem. Actually it was two problems.

1) Double entries: My StructureAdvisor was not correct in returning
public Boolean hasChildren(Object element)

2) No entries:

A) When I add a new item, I right click on the parent, which gives me
the ChildCreator Menu. So when adding the child the parent is selected,
and the CreateChildCommand works.

B) If I right-click again, and select to create a new child item, the
CreateChildCommand can't execute as the selection is not set, as A)
caused the CreateChildAction to have no selection somehow. (Altough in
the viewer it seems selected). I get a similar misbehaviour with the
"Paste" command.


So I need to explicitly left click on the parent first, and then invoke
the right-click subsequently. Remembering correctly, I believe the
emf.edit command should cater for this, but in my case it doesn't work.
Did I accidently break something in emf.edit, or is this a known issue?

thank you.



> Tom
>
> Am 21.10.11 10:11, schrieb Christophe Bouhier:
>> Hi,
>>
>> Sometimes (It's intermittent) I see double entries appear when adding an
>> item to a treeviewer which is "databinded". Sometime the entry simply
>> doesn't appear. A refresh usually solves the problem.
>>
>> I notice the IMapChangeListener, MapChangeEvent
>> event.diff.getChangedKeys() returns an empty resultset, so the code to
>>
>> fireLabelProviderChanged(newEvent) is never called.
>>
>>
>> In my code below, I add IObservableMap entries for which we add the
>> IMapChangeListener.
>>
>>
>> Why is the result set empty, while the listener is called?
>> Is there any relation to this issue, and the StrutureAdvisor or
>> TreeFactory ?
>>
>> rgds Christophe
>>
>>
>> This is the databinding code. (EMF) to the viewer.
>> ***************************************************
>>
>> EMFDataBindingContext bindingContext = new EMFDataBindingContext();
>>
>> ObservableListTreeContentProvider cp = new
>> ObservableListTreeContentProvider(
>> new
>> NodeTypeTreeFactoryImpl(editingService.getEditingDomain()),
>> new NodeTypeTreeStructureAdvisorImpl());
>> nodeTypeTreeViewer.setContentProvider(cp);
>> IObservableSet set = cp.getKnownElements();
>>
>> List<IObservableMap> mapList = Lists.newArrayList();
>>
>>
>> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>>
>> LibraryPackage.Literals.NODE_TYPE__NAME).observeDetail(set));
>>
>>
>> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>>
>> LibraryPackage.Literals.NODE_TYPE__EQUIPMENTS).observeDetail(set));
>>
>>
>> mapList.add(EMFEditProperties.value(editingService.getEditingDomain(),
>>
>> LibraryPackage.Literals.NODE_TYPE__FUNCTIONS).observeDetail(set));
>>
>> mapList.add(EMFProperties
>>
>> .value(LibraryPackage.Literals.COMPONENT__NAME).observeDetail(
>> set));
>>
>>
>> mapList.add(EMFProperties.value(
>> LibraryPackage.Literals.EQUIPMENT__EQUIPMENT_CODE)
>> .observeDetail(set));
>>
>> IObservableMap[] map = new IObservableMap[mapList.size()];
>> mapList.toArray(map);
>>
>> nodeTypeTreeViewer.setLabelProvider(new
>> NodeTypeTreeLabelProvider(map));
>> IEMFListProperty projects =
>> EMFEditProperties.resource(editingService
>> .getEditingDomain());
>>
>> IObservableList nodeTypeObservableList = projects
>> .observe(nodeTypeResource);
>> nodeTypeTreeViewer.setInput(nodeTypeObservableList);
>
Previous Topic:Rebroadcast selection after TableViewer row changed
Next Topic:selection in CheckboxTableViewer doesnt work in win7/64
Goto Forum:
  


Current Time: Fri Aug 22 02:05:57 EDT 2014

Powered by FUDForum. Page generated in 0.01992 seconds