Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » model/TreeView synchronization problem.
model/TreeView synchronization problem. [message #514348] Sun, 14 February 2010 21:07 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Hi,
I have a TreeView that is the main selection provider for one page:
....
tree = toolkit.createTree(composite_2, SWT.BORDER);
toolkit.paintBordersFor(tree);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tViewer = new TreeViewer(tree);
page.getEditorSite().setSelectionProvider(tViewer);
....
I have a context menu attached to the TreeView which has provisions to
add new nodes to the Model.
The context is dynamically created and, in the end fires the handler of
a Command. The handler for one particular addition (Add Scene) is like this:

public class AddScene extends AbstractHandler {
static final String ID = "it.condarelli.wbtest.commands.AddScene";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ISelection is = HandlerUtil.getCurrentSelection(event);
if (is instanceof IStructuredSelection) {
IStructuredSelection iss = (IStructuredSelection) is;
Object o = iss.getFirstElement();
if (o instanceof Chapter) {
Chapter _c = (Chapter) o;
Scene sc = ModelFactory.eINSTANCE.createScene();
_c.getScene().add(0, sc);
System.out.println("AddScene: added new Scene at start
of Chapter '" + _c.getTitle()+"'");
} else if (o instanceof Scene) {
Scene _s = (Scene) o;
Scene sc = ModelFactory.eINSTANCE.createScene();
Chapter _c = _s.getChapter();
int i = _c.getScene().indexOf(_s);
_c.getScene().add(i+1, sc);
System.out.println("AddScene: added new Scene in
Chapter '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
}

} else
System.err.println("AddScene bad selection: " + is);
return null;
}

}

Up to here everything is Ok. There is a nice separation between the UI
and the Model, but now problems start:

1) the TreeView does not fully reflect the changes in the model; if I
add a Scene after another Scene (else if (o instanceof Scene) {...)
everything is ok, but if I add a Scene in an empty Chapter (if (o
instanceof Chapter) {...) the addition is *not* reflected by UI: I need
to reload the application (or otherwise reinitialize the TreeViewer to
see the newly created Scene.

2) I would like to automatically select the new Scene, but I simply do
not know how to do that at this point in the code.

I am aware of several documents explaining how to synchronize <ui with
Model (e.g.:
http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
but they all seem to require knowledge of the visual component (tViewer,
in this case).

I can think of several ways to let the Handler to get hold of tViewer,
but I strngly suspect there should be a better way than to pollute the
whole code with cross-knowledge between Model and UI.

Ideally I would like to be able to extract information about the Widget
(tViewer) from the Selection I get from the Selection Service, but I
didn't find a way to do that.

Can someone point me in the right direction, please?

Thanks in Advance
Mauro
Re: model/TreeView synchronization problem. [message #514413 is a reply to message #514348] Mon, 15 February 2010 09:11 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Mauro Condarelli wrote:
> Hi,
> I have a TreeView that is the main selection provider for one page:
> ...
> tree = toolkit.createTree(composite_2, SWT.BORDER);
> toolkit.paintBordersFor(tree);
> tree.setHeaderVisible(true);
> tree.setLinesVisible(true);
> tViewer = new TreeViewer(tree);
> page.getEditorSite().setSelectionProvider(tViewer);
> ...
> I have a context menu attached to the TreeView which has provisions to
> add new nodes to the Model.
> The context is dynamically created and, in the end fires the handler of
> a Command. The handler for one particular addition (Add Scene) is like
> this:
>
> public class AddScene extends AbstractHandler {
> static final String ID = "it.condarelli.wbtest.commands.AddScene";
>
> @Override
> public Object execute(ExecutionEvent event) throws ExecutionException {
> ISelection is = HandlerUtil.getCurrentSelection(event);
> if (is instanceof IStructuredSelection) {
> IStructuredSelection iss = (IStructuredSelection) is;
> Object o = iss.getFirstElement();
> if (o instanceof Chapter) {
> Chapter _c = (Chapter) o;
> Scene sc = ModelFactory.eINSTANCE.createScene();
> _c.getScene().add(0, sc);
> System.out.println("AddScene: added new Scene at start
> of Chapter '" + _c.getTitle()+"'");
> } else if (o instanceof Scene) {
> Scene _s = (Scene) o;
> Scene sc = ModelFactory.eINSTANCE.createScene();
> Chapter _c = _s.getChapter();
> int i = _c.getScene().indexOf(_s);
> _c.getScene().add(i+1, sc);
> System.out.println("AddScene: added new Scene in Chapter
> '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
> }
>
> } else
> System.err.println("AddScene bad selection: " + is);
> return null;
> }
>
> }
>
> Up to here everything is Ok. There is a nice separation between the UI
> and the Model, but now problems start:
>
> 1) the TreeView does not fully reflect the changes in the model; if I
> add a Scene after another Scene (else if (o instanceof Scene) {...)
> everything is ok, but if I add a Scene in an empty Chapter (if (o
> instanceof Chapter) {...) the addition is *not* reflected by UI: I need
> to reload the application (or otherwise reinitialize the TreeViewer to
> see the newly created Scene.
>
> 2) I would like to automatically select the new Scene, but I simply do
> not know how to do that at this point in the code.
>
> I am aware of several documents explaining how to synchronize <ui with
> Model (e.g.:
> http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
> but they all seem to require knowledge of the visual component (tViewer,
> in this case).
>
> I can think of several ways to let the Handler to get hold of tViewer,
> but I strngly suspect there should be a better way than to pollute the
> whole code with cross-knowledge between Model and UI.
>
> Ideally I would like to be able to extract information about the Widget
> (tViewer) from the Selection I get from the Selection Service, but I
> didn't find a way to do that.
>
> Can someone point me in the right direction, please?
>
> Thanks in Advance
> Mauro
Ok,
Answering to myself again ;)
For the record:
I solved the above problem by adding this to the AddScene Handler:

ISelectionProvider isp = HandlerUtil
.getActiveEditor(event)
.getSite()
.getSelectionProvider();
if (isp instanceof Viewer) {
Viewer tv = (Viewer) isp;
tv.refresh();
}
ISelection sel = new StructuredSelection(sc);
isp.setSelection(sel);
============================================================ =====
Now I have a similar problem involving EMF Databinding.
This is reason for crossposting.

My TreeViewer displays some data from the Model.
I have some master/detail pages that modify the model, possibly
including the data displayed in the master TreeViewer.
When this happens the TreeViewer is not automatically refreshed and I
couldn't guess how to do it manually.

TreeVieweris built like this:

tree = toolkit.createTree(composite_2, SWT.BORDER);
toolkit.paintBordersFor(tree);
tree.setHeaderVisible(true);
tree.setLinesVisible(true);
tViewer = new TreeViewer(tree);
bind();

The binding is:

protected void bindText(DataBindingContext dbc, Text t, EObject o,
EStructuralFeature sf) {
final IWidgetValueProperty wvp = WidgetProperties.text(SWT.Modify);
IObservableValue uiObs = wvp.observeDelayed(400, t);
IEMFValueProperty evp = EMFProperties.value(sf);
IObservableValue mObs = evp.observe(o);
dbc.bindValue(uiObs, mObs, null, null);
}

protected void bind() {
DataBindingContext dbc = new DataBindingContext();

bindText(dbc, textAuthor, world, Literals.WORLD__AUTHOR);
bindText(dbc, textName, world, Literals.WORLD__TITLE);
bindText(dbc, textDesc, world, Literals.WORLD__DESC);

IObservableFactory iof = new WorldObservableFactory();
TreeStructureAdvisor tsa = new WorldTreeStructureAdvisor();
ObservableListTreeContentProvider cp = new
ObservableListTreeContentProvider(iof, tsa);
tViewer.setContentProvider(cp);

WorldLabelProvider wlp = new WorldLabelProvider();
tViewer.setLabelProvider(wlp);

IEMFListProperty projects =
EMFProperties.list(ModelPackage.Literals.WORLD__BOOK);
tViewer.setInput(projects.observe(world));
}

This works, but tViewer is not updated when the Model changes.

I tried adding:

IObservableList w = projects.observe(world);
w.addChangeListener(new IChangeListener() {
@Override
public void handleChange(ChangeEvent event) {
tViewer.refresh();
}
});

But it is never called.
I can send any information needed. I just refrained from adding to an
already quite long post. Just ask.
What should I do?

TiA
Mauro
Re: model/TreeView synchronization problem. [message #514414 is a reply to message #514413] Mon, 15 February 2010 09:17 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
You need an ObservableMapLabelProvider (provided by JFace-Databinding) -
or a more special one like is show in my posts about EMF-Databinding.

A ColumnLabelProvider is in
http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/
and a CellLabelProvider in
http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-data binding-%e2%80%93-part-3/

All the code is in EMF-CVS so you can check it out copy it to your
project and your are done.


Tom

Am 15.02.10 10:11, schrieb Mauro Condarelli:
> Mauro Condarelli wrote:
>> Hi,
>> I have a TreeView that is the main selection provider for one page:
>> ...
>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>> toolkit.paintBordersFor(tree);
>> tree.setHeaderVisible(true);
>> tree.setLinesVisible(true);
>> tViewer = new TreeViewer(tree);
>> page.getEditorSite().setSelectionProvider(tViewer);
>> ...
>> I have a context menu attached to the TreeView which has provisions to
>> add new nodes to the Model.
>> The context is dynamically created and, in the end fires the handler
>> of a Command. The handler for one particular addition (Add Scene) is
>> like this:
>>
>> public class AddScene extends AbstractHandler {
>> static final String ID = "it.condarelli.wbtest.commands.AddScene";
>>
>> @Override
>> public Object execute(ExecutionEvent event) throws
>> ExecutionException {
>> ISelection is = HandlerUtil.getCurrentSelection(event);
>> if (is instanceof IStructuredSelection) {
>> IStructuredSelection iss = (IStructuredSelection) is;
>> Object o = iss.getFirstElement();
>> if (o instanceof Chapter) {
>> Chapter _c = (Chapter) o;
>> Scene sc = ModelFactory.eINSTANCE.createScene();
>> _c.getScene().add(0, sc);
>> System.out.println("AddScene: added new Scene at start
>> of Chapter '" + _c.getTitle()+"'");
>> } else if (o instanceof Scene) {
>> Scene _s = (Scene) o;
>> Scene sc = ModelFactory.eINSTANCE.createScene();
>> Chapter _c = _s.getChapter();
>> int i = _c.getScene().indexOf(_s);
>> _c.getScene().add(i+1, sc);
>> System.out.println("AddScene: added new Scene in
>> Chapter '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
>> }
>>
>> } else
>> System.err.println("AddScene bad selection: " + is);
>> return null;
>> }
>>
>> }
>>
>> Up to here everything is Ok. There is a nice separation between the UI
>> and the Model, but now problems start:
>>
>> 1) the TreeView does not fully reflect the changes in the model; if I
>> add a Scene after another Scene (else if (o instanceof Scene) {...)
>> everything is ok, but if I add a Scene in an empty Chapter (if (o
>> instanceof Chapter) {...) the addition is *not* reflected by UI: I
>> need to reload the application (or otherwise reinitialize the
>> TreeViewer to see the newly created Scene.
>>
>> 2) I would like to automatically select the new Scene, but I simply do
>> not know how to do that at this point in the code.
>>
>> I am aware of several documents explaining how to synchronize <ui with
>> Model (e.g.:
>> http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
>> but they all seem to require knowledge of the visual component
>> (tViewer, in this case).
>>
>> I can think of several ways to let the Handler to get hold of tViewer,
>> but I strngly suspect there should be a better way than to pollute the
>> whole code with cross-knowledge between Model and UI.
>>
>> Ideally I would like to be able to extract information about the
>> Widget (tViewer) from the Selection I get from the Selection Service,
>> but I didn't find a way to do that.
>>
>> Can someone point me in the right direction, please?
>>
>> Thanks in Advance
>> Mauro
> Ok,
> Answering to myself again ;)
> For the record:
> I solved the above problem by adding this to the AddScene Handler:
>
> ISelectionProvider isp = HandlerUtil
> .getActiveEditor(event)
> .getSite()
> .getSelectionProvider();
> if (isp instanceof Viewer) {
> Viewer tv = (Viewer) isp;
> tv.refresh();
> }
> ISelection sel = new StructuredSelection(sc);
> isp.setSelection(sel);
> ============================================================ =====
> Now I have a similar problem involving EMF Databinding.
> This is reason for crossposting.
>
> My TreeViewer displays some data from the Model.
> I have some master/detail pages that modify the model, possibly
> including the data displayed in the master TreeViewer.
> When this happens the TreeViewer is not automatically refreshed and I
> couldn't guess how to do it manually.
>
> TreeVieweris built like this:
>
> tree = toolkit.createTree(composite_2, SWT.BORDER);
> toolkit.paintBordersFor(tree);
> tree.setHeaderVisible(true);
> tree.setLinesVisible(true);
> tViewer = new TreeViewer(tree);
> bind();
>
> The binding is:
>
> protected void bindText(DataBindingContext dbc, Text t, EObject o,
> EStructuralFeature sf) {
> final IWidgetValueProperty wvp = WidgetProperties.text(SWT.Modify);
> IObservableValue uiObs = wvp.observeDelayed(400, t);
> IEMFValueProperty evp = EMFProperties.value(sf);
> IObservableValue mObs = evp.observe(o);
> dbc.bindValue(uiObs, mObs, null, null);
> }
>
> protected void bind() {
> DataBindingContext dbc = new DataBindingContext();
>
> bindText(dbc, textAuthor, world, Literals.WORLD__AUTHOR);
> bindText(dbc, textName, world, Literals.WORLD__TITLE);
> bindText(dbc, textDesc, world, Literals.WORLD__DESC);
>
> IObservableFactory iof = new WorldObservableFactory();
> TreeStructureAdvisor tsa = new WorldTreeStructureAdvisor();
> ObservableListTreeContentProvider cp = new
> ObservableListTreeContentProvider(iof, tsa);
> tViewer.setContentProvider(cp);
>
> WorldLabelProvider wlp = new WorldLabelProvider();
> tViewer.setLabelProvider(wlp);
>
> IEMFListProperty projects =
> EMFProperties.list(ModelPackage.Literals.WORLD__BOOK);
> tViewer.setInput(projects.observe(world));
> }
>
> This works, but tViewer is not updated when the Model changes.
>
> I tried adding:
>
> IObservableList w = projects.observe(world);
> w.addChangeListener(new IChangeListener() {
> @Override
> public void handleChange(ChangeEvent event) {
> tViewer.refresh();
> }
> });
>
> But it is never called.
> I can send any information needed. I just refrained from adding to an
> already quite long post. Just ask.
> What should I do?
>
> TiA
> Mauro
Re: model/TreeView synchronization problem. [message #514505 is a reply to message #514414] Mon, 15 February 2010 11:16 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Tom Schindl wrote:
> You need an ObservableMapLabelProvider (provided by JFace-Databinding) -
> or a more special one like is show in my posts about EMF-Databinding.
>
> A ColumnLabelProvider is in
> http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/
> and a CellLabelProvider in
> http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-data binding-%e2%80%93-part-3/
>
> All the code is in EMF-CVS so you can check it out copy it to your
> project and your are done.
>
Thanks a lot Tom.
I already saw Your tutorial, but (shame on me) I was not able to follow
exactly that part. I will try again.

In the meantime I modified my bindings as follows:

===============================================
IObservableSet set = cp.getKnownElements();
final IObservableMap[] map = new IObservableMap[4];
map[0] =
EMFProperties.value(Literals.SCENE__TITLE).observeDetail(set );
map[1] =
EMFProperties.value(Literals.CHAPTER__TITLE).observeDetail(s et);
map[2] =
EMFProperties.value(Literals.BOOK__TITLE).observeDetail(set) ;
map[3] =
EMFProperties.value(Literals.WORLD__TITLE).observeDetail(set );
ObservableMapLabelProvider omlp = new
ObservableMapLabelProvider(map) {
@Override
public Image getColumnImage(Object element, int columnIndex) {
// TODO Auto-generated method stub
return super.getColumnImage(element, columnIndex);
}

@Override
public String getColumnText(Object element, int columnIndex) {
if (columnIndex == 0) {
if (element instanceof Scene) {
Object o = map[0].get(element);
return (o != null) ? o.toString() : "(null)";
} else if (element instanceof Chapter) {
Object o = map[1].get(element);
return (o != null) ? o.toString() : "(null)";
} else if (element instanceof Book) {
Object o = map[2].get(element);
return (o != null) ? o.toString() : "(null)";
} else if (element instanceof World) {
Object o = map[3].get(element);
return (o != null) ? o.toString() : "(null)";
}
}
return super.getColumnText(element, columnIndex);
}

};

tViewer.setLabelProvider(omlp);

IEMFListProperty projects =
EMFProperties.list(Literals.WORLD__BOOK);
tViewer.setInput(projects.observe(world));
===============================================
.... and it WORKS!!
I still need to understand things better, but I can proceed.

Another thing I haven't found out how to do is:

The root of my model is World.

/**
* @model
*/
public interface World extends EObject {
/**
* @model
*/
public String getAuthor();

/**
* @model opposite="world" containment="true"
*/
public EList<Book> getBook();

/**
* @model containment="true"
*/
public EList<Actor> getActor();

/**
* @model containment="true"
*/
public EList<Location> getLocation();

...

} // World

So it is rather wrong to use:
IEMFListProperty projects = EMFProperties.list(Literals.WORLD__BOOK);
tViewer.setInput(projects.observe(world));

.... but I didn't find what I should use instead!
My ModelPackage doesn't seem to contain an EReference pointing to the
Model Root.

What should I use?

TiA
Mauro

>
> Tom
>
> Am 15.02.10 10:11, schrieb Mauro Condarelli:
>> Mauro Condarelli wrote:
>>> Hi,
>>> I have a TreeView that is the main selection provider for one page:
>>> ...
>>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>>> toolkit.paintBordersFor(tree);
>>> tree.setHeaderVisible(true);
>>> tree.setLinesVisible(true);
>>> tViewer = new TreeViewer(tree);
>>> page.getEditorSite().setSelectionProvider(tViewer);
>>> ...
>>> I have a context menu attached to the TreeView which has provisions to
>>> add new nodes to the Model.
>>> The context is dynamically created and, in the end fires the handler
>>> of a Command. The handler for one particular addition (Add Scene) is
>>> like this:
>>>
>>> public class AddScene extends AbstractHandler {
>>> static final String ID = "it.condarelli.wbtest.commands.AddScene";
>>>
>>> @Override
>>> public Object execute(ExecutionEvent event) throws
>>> ExecutionException {
>>> ISelection is = HandlerUtil.getCurrentSelection(event);
>>> if (is instanceof IStructuredSelection) {
>>> IStructuredSelection iss = (IStructuredSelection) is;
>>> Object o = iss.getFirstElement();
>>> if (o instanceof Chapter) {
>>> Chapter _c = (Chapter) o;
>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>> _c.getScene().add(0, sc);
>>> System.out.println("AddScene: added new Scene at start
>>> of Chapter '" + _c.getTitle()+"'");
>>> } else if (o instanceof Scene) {
>>> Scene _s = (Scene) o;
>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>> Chapter _c = _s.getChapter();
>>> int i = _c.getScene().indexOf(_s);
>>> _c.getScene().add(i+1, sc);
>>> System.out.println("AddScene: added new Scene in
>>> Chapter '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
>>> }
>>>
>>> } else
>>> System.err.println("AddScene bad selection: " + is);
>>> return null;
>>> }
>>>
>>> }
>>>
>>> Up to here everything is Ok. There is a nice separation between the UI
>>> and the Model, but now problems start:
>>>
>>> 1) the TreeView does not fully reflect the changes in the model; if I
>>> add a Scene after another Scene (else if (o instanceof Scene) {...)
>>> everything is ok, but if I add a Scene in an empty Chapter (if (o
>>> instanceof Chapter) {...) the addition is *not* reflected by UI: I
>>> need to reload the application (or otherwise reinitialize the
>>> TreeViewer to see the newly created Scene.
>>>
>>> 2) I would like to automatically select the new Scene, but I simply do
>>> not know how to do that at this point in the code.
>>>
>>> I am aware of several documents explaining how to synchronize <ui with
>>> Model (e.g.:
>>> http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
>>> but they all seem to require knowledge of the visual component
>>> (tViewer, in this case).
>>>
>>> I can think of several ways to let the Handler to get hold of tViewer,
>>> but I strngly suspect there should be a better way than to pollute the
>>> whole code with cross-knowledge between Model and UI.
>>>
>>> Ideally I would like to be able to extract information about the
>>> Widget (tViewer) from the Selection I get from the Selection Service,
>>> but I didn't find a way to do that.
>>>
>>> Can someone point me in the right direction, please?
>>>
>>> Thanks in Advance
>>> Mauro
>> Ok,
>> Answering to myself again ;)
>> For the record:
>> I solved the above problem by adding this to the AddScene Handler:
>>
>> ISelectionProvider isp = HandlerUtil
>> .getActiveEditor(event)
>> .getSite()
>> .getSelectionProvider();
>> if (isp instanceof Viewer) {
>> Viewer tv = (Viewer) isp;
>> tv.refresh();
>> }
>> ISelection sel = new StructuredSelection(sc);
>> isp.setSelection(sel);
>> ============================================================ =====
>> Now I have a similar problem involving EMF Databinding.
>> This is reason for crossposting.
>>
>> My TreeViewer displays some data from the Model.
>> I have some master/detail pages that modify the model, possibly
>> including the data displayed in the master TreeViewer.
>> When this happens the TreeViewer is not automatically refreshed and I
>> couldn't guess how to do it manually.
>>
>> TreeVieweris built like this:
>>
>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>> toolkit.paintBordersFor(tree);
>> tree.setHeaderVisible(true);
>> tree.setLinesVisible(true);
>> tViewer = new TreeViewer(tree);
>> bind();
>>
>> The binding is:
>>
>> protected void bindText(DataBindingContext dbc, Text t, EObject o,
>> EStructuralFeature sf) {
>> final IWidgetValueProperty wvp = WidgetProperties.text(SWT.Modify);
>> IObservableValue uiObs = wvp.observeDelayed(400, t);
>> IEMFValueProperty evp = EMFProperties.value(sf);
>> IObservableValue mObs = evp.observe(o);
>> dbc.bindValue(uiObs, mObs, null, null);
>> }
>>
>> protected void bind() {
>> DataBindingContext dbc = new DataBindingContext();
>>
>> bindText(dbc, textAuthor, world, Literals.WORLD__AUTHOR);
>> bindText(dbc, textName, world, Literals.WORLD__TITLE);
>> bindText(dbc, textDesc, world, Literals.WORLD__DESC);
>>
>> IObservableFactory iof = new WorldObservableFactory();
>> TreeStructureAdvisor tsa = new WorldTreeStructureAdvisor();
>> ObservableListTreeContentProvider cp = new
>> ObservableListTreeContentProvider(iof, tsa);
>> tViewer.setContentProvider(cp);
>>
>> WorldLabelProvider wlp = new WorldLabelProvider();
>> tViewer.setLabelProvider(wlp);
>>
>> IEMFListProperty projects =
>> EMFProperties.list(ModelPackage.Literals.WORLD__BOOK);
>> tViewer.setInput(projects.observe(world));
>> }
>>
>> This works, but tViewer is not updated when the Model changes.
>>
>> I tried adding:
>>
>> IObservableList w = projects.observe(world);
>> w.addChangeListener(new IChangeListener() {
>> @Override
>> public void handleChange(ChangeEvent event) {
>> tViewer.refresh();
>> }
>> });
>>
>> But it is never called.
>> I can send any information needed. I just refrained from adding to an
>> already quite long post. Just ask.
>> What should I do?
>>
>> TiA
>> Mauro
>
Re: model/TreeView synchronization problem. [message #514506 is a reply to message #514505] Mon, 15 February 2010 11:16 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

I'm not sure I follow this. Do you talk about observing the
Resource#getContent()? There's currently no properties support for this
and you need to use EMFObservables#observeResource().

There's a bug (and a 90% ready implementation) already to provide this
through the Properties-API but I can't remember the bug id.


Tom

Am 15.02.10 16:58, schrieb Mauro Condarelli:
> Tom Schindl wrote:
>> You need an ObservableMapLabelProvider (provided by JFace-Databinding) -
>> or a more special one like is show in my posts about EMF-Databinding.
>>
>> A ColumnLabelProvider is in
>> http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/
>>
>> and a CellLabelProvider in
>> http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-data binding-%e2%80%93-part-3/
>>
>>
>> All the code is in EMF-CVS so you can check it out copy it to your
>> project and your are done.
>>
> Thanks a lot Tom.
> I already saw Your tutorial, but (shame on me) I was not able to follow
> exactly that part. I will try again.
>
> In the meantime I modified my bindings as follows:
>
> ===============================================
> IObservableSet set = cp.getKnownElements();
> final IObservableMap[] map = new IObservableMap[4];
> map[0] =
> EMFProperties.value(Literals.SCENE__TITLE).observeDetail(set );
> map[1] =
> EMFProperties.value(Literals.CHAPTER__TITLE).observeDetail(s et);
> map[2] =
> EMFProperties.value(Literals.BOOK__TITLE).observeDetail(set) ;
> map[3] =
> EMFProperties.value(Literals.WORLD__TITLE).observeDetail(set );
> ObservableMapLabelProvider omlp = new
> ObservableMapLabelProvider(map) {
> @Override
> public Image getColumnImage(Object element, int columnIndex) {
> // TODO Auto-generated method stub
> return super.getColumnImage(element, columnIndex);
> }
>
> @Override
> public String getColumnText(Object element, int columnIndex) {
> if (columnIndex == 0) {
> if (element instanceof Scene) {
> Object o = map[0].get(element);
> return (o != null) ? o.toString() : "(null)";
> } else if (element instanceof Chapter) {
> Object o = map[1].get(element);
> return (o != null) ? o.toString() : "(null)";
> } else if (element instanceof Book) {
> Object o = map[2].get(element);
> return (o != null) ? o.toString() : "(null)";
> } else if (element instanceof World) {
> Object o = map[3].get(element);
> return (o != null) ? o.toString() : "(null)";
> }
> }
> return super.getColumnText(element, columnIndex);
> }
>
> };
>
> tViewer.setLabelProvider(omlp);
>
> IEMFListProperty projects =
> EMFProperties.list(Literals.WORLD__BOOK);
> tViewer.setInput(projects.observe(world));
> ===============================================
> ... and it WORKS!!
> I still need to understand things better, but I can proceed.
>
> Another thing I haven't found out how to do is:
>
> The root of my model is World.
>
> /**
> * @model
> */
> public interface World extends EObject {
> /**
> * @model
> */
> public String getAuthor();
>
> /**
> * @model opposite="world" containment="true"
> */
> public EList<Book> getBook();
>
> /**
> * @model containment="true"
> */
> public EList<Actor> getActor();
>
> /**
> * @model containment="true"
> */
> public EList<Location> getLocation();
>
> ...
>
> } // World
>
> So it is rather wrong to use:
> IEMFListProperty projects = EMFProperties.list(Literals.WORLD__BOOK);
> tViewer.setInput(projects.observe(world));
>
> ... but I didn't find what I should use instead!
> My ModelPackage doesn't seem to contain an EReference pointing to the
> Model Root.
>
> What should I use?
>
> TiA
> Mauro
>
>>
>> Tom
>>
>> Am 15.02.10 10:11, schrieb Mauro Condarelli:
>>> Mauro Condarelli wrote:
>>>> Hi,
>>>> I have a TreeView that is the main selection provider for one page:
>>>> ...
>>>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>>>> toolkit.paintBordersFor(tree);
>>>> tree.setHeaderVisible(true);
>>>> tree.setLinesVisible(true);
>>>> tViewer = new TreeViewer(tree);
>>>> page.getEditorSite().setSelectionProvider(tViewer);
>>>> ...
>>>> I have a context menu attached to the TreeView which has provisions to
>>>> add new nodes to the Model.
>>>> The context is dynamically created and, in the end fires the handler
>>>> of a Command. The handler for one particular addition (Add Scene) is
>>>> like this:
>>>>
>>>> public class AddScene extends AbstractHandler {
>>>> static final String ID = "it.condarelli.wbtest.commands.AddScene";
>>>>
>>>> @Override
>>>> public Object execute(ExecutionEvent event) throws
>>>> ExecutionException {
>>>> ISelection is = HandlerUtil.getCurrentSelection(event);
>>>> if (is instanceof IStructuredSelection) {
>>>> IStructuredSelection iss = (IStructuredSelection) is;
>>>> Object o = iss.getFirstElement();
>>>> if (o instanceof Chapter) {
>>>> Chapter _c = (Chapter) o;
>>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>>> _c.getScene().add(0, sc);
>>>> System.out.println("AddScene: added new Scene at start
>>>> of Chapter '" + _c.getTitle()+"'");
>>>> } else if (o instanceof Scene) {
>>>> Scene _s = (Scene) o;
>>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>>> Chapter _c = _s.getChapter();
>>>> int i = _c.getScene().indexOf(_s);
>>>> _c.getScene().add(i+1, sc);
>>>> System.out.println("AddScene: added new Scene in
>>>> Chapter '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
>>>> }
>>>>
>>>> } else
>>>> System.err.println("AddScene bad selection: " + is);
>>>> return null;
>>>> }
>>>>
>>>> }
>>>>
>>>> Up to here everything is Ok. There is a nice separation between the UI
>>>> and the Model, but now problems start:
>>>>
>>>> 1) the TreeView does not fully reflect the changes in the model; if I
>>>> add a Scene after another Scene (else if (o instanceof Scene) {...)
>>>> everything is ok, but if I add a Scene in an empty Chapter (if (o
>>>> instanceof Chapter) {...) the addition is *not* reflected by UI: I
>>>> need to reload the application (or otherwise reinitialize the
>>>> TreeViewer to see the newly created Scene.
>>>>
>>>> 2) I would like to automatically select the new Scene, but I simply do
>>>> not know how to do that at this point in the code.
>>>>
>>>> I am aware of several documents explaining how to synchronize <ui with
>>>> Model (e.g.:
>>>> http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
>>>>
>>>> but they all seem to require knowledge of the visual component
>>>> (tViewer, in this case).
>>>>
>>>> I can think of several ways to let the Handler to get hold of tViewer,
>>>> but I strngly suspect there should be a better way than to pollute the
>>>> whole code with cross-knowledge between Model and UI.
>>>>
>>>> Ideally I would like to be able to extract information about the
>>>> Widget (tViewer) from the Selection I get from the Selection Service,
>>>> but I didn't find a way to do that.
>>>>
>>>> Can someone point me in the right direction, please?
>>>>
>>>> Thanks in Advance
>>>> Mauro
>>> Ok,
>>> Answering to myself again ;)
>>> For the record:
>>> I solved the above problem by adding this to the AddScene Handler:
>>>
>>> ISelectionProvider isp = HandlerUtil
>>> .getActiveEditor(event)
>>> .getSite()
>>> .getSelectionProvider();
>>> if (isp instanceof Viewer) {
>>> Viewer tv = (Viewer) isp;
>>> tv.refresh();
>>> }
>>> ISelection sel = new StructuredSelection(sc);
>>> isp.setSelection(sel);
>>> ============================================================ =====
>>> Now I have a similar problem involving EMF Databinding.
>>> This is reason for crossposting.
>>>
>>> My TreeViewer displays some data from the Model.
>>> I have some master/detail pages that modify the model, possibly
>>> including the data displayed in the master TreeViewer.
>>> When this happens the TreeViewer is not automatically refreshed and I
>>> couldn't guess how to do it manually.
>>>
>>> TreeVieweris built like this:
>>>
>>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>>> toolkit.paintBordersFor(tree);
>>> tree.setHeaderVisible(true);
>>> tree.setLinesVisible(true);
>>> tViewer = new TreeViewer(tree);
>>> bind();
>>>
>>> The binding is:
>>>
>>> protected void bindText(DataBindingContext dbc, Text t, EObject o,
>>> EStructuralFeature sf) {
>>> final IWidgetValueProperty wvp =
>>> WidgetProperties.text(SWT.Modify);
>>> IObservableValue uiObs = wvp.observeDelayed(400, t);
>>> IEMFValueProperty evp = EMFProperties.value(sf);
>>> IObservableValue mObs = evp.observe(o);
>>> dbc.bindValue(uiObs, mObs, null, null);
>>> }
>>>
>>> protected void bind() {
>>> DataBindingContext dbc = new DataBindingContext();
>>>
>>> bindText(dbc, textAuthor, world, Literals.WORLD__AUTHOR);
>>> bindText(dbc, textName, world, Literals.WORLD__TITLE);
>>> bindText(dbc, textDesc, world, Literals.WORLD__DESC);
>>>
>>> IObservableFactory iof = new WorldObservableFactory();
>>> TreeStructureAdvisor tsa = new WorldTreeStructureAdvisor();
>>> ObservableListTreeContentProvider cp = new
>>> ObservableListTreeContentProvider(iof, tsa);
>>> tViewer.setContentProvider(cp);
>>>
>>> WorldLabelProvider wlp = new WorldLabelProvider();
>>> tViewer.setLabelProvider(wlp);
>>>
>>> IEMFListProperty projects =
>>> EMFProperties.list(ModelPackage.Literals.WORLD__BOOK);
>>> tViewer.setInput(projects.observe(world));
>>> }
>>>
>>> This works, but tViewer is not updated when the Model changes.
>>>
>>> I tried adding:
>>>
>>> IObservableList w = projects.observe(world);
>>> w.addChangeListener(new IChangeListener() {
>>> @Override
>>> public void handleChange(ChangeEvent event) {
>>> tViewer.refresh();
>>> }
>>> });
>>>
>>> But it is never called.
>>> I can send any information needed. I just refrained from adding to an
>>> already quite long post. Just ask.
>>> What should I do?
>>>
>>> TiA
>>> Mauro
>>
Re: model/TreeView synchronization problem. [message #514512 is a reply to message #514506] Mon, 15 February 2010 16:14 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Tom Schindl wrote:
> Hi,
>
> I'm not sure I follow this. Do you talk about observing the
> Resource#getContent()? There's currently no properties support for this
> and you need to use EMFObservables#observeResource().
>
> There's a bug (and a 90% ready implementation) already to provide this
> through the Properties-API but I can't remember the bug id.

Thanks a lot for the ultra-fast answer!

Yes. I want to observe Resource.getContent().

I will search for the bug and, in the meantime, I will try to understand
how to use EMFObservables#observeResource().

Many Thanks again
Mauro

>
>
> Tom
>
> Am 15.02.10 16:58, schrieb Mauro Condarelli:
>> Tom Schindl wrote:
>>> You need an ObservableMapLabelProvider (provided by JFace-Databinding) -
>>> or a more special one like is show in my posts about EMF-Databinding.
>>>
>>> A ColumnLabelProvider is in
>>> http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/
>>>
>>> and a CellLabelProvider in
>>> http://tomsondev.bestsolution.at/2009/06/08/galileo-emf-data binding-%e2%80%93-part-3/
>>>
>>>
>>> All the code is in EMF-CVS so you can check it out copy it to your
>>> project and your are done.
>>>
>> Thanks a lot Tom.
>> I already saw Your tutorial, but (shame on me) I was not able to follow
>> exactly that part. I will try again.
>>
>> In the meantime I modified my bindings as follows:
>>
>> ===============================================
>> IObservableSet set = cp.getKnownElements();
>> final IObservableMap[] map = new IObservableMap[4];
>> map[0] =
>> EMFProperties.value(Literals.SCENE__TITLE).observeDetail(set );
>> map[1] =
>> EMFProperties.value(Literals.CHAPTER__TITLE).observeDetail(s et);
>> map[2] =
>> EMFProperties.value(Literals.BOOK__TITLE).observeDetail(set) ;
>> map[3] =
>> EMFProperties.value(Literals.WORLD__TITLE).observeDetail(set );
>> ObservableMapLabelProvider omlp = new
>> ObservableMapLabelProvider(map) {
>> @Override
>> public Image getColumnImage(Object element, int columnIndex) {
>> // TODO Auto-generated method stub
>> return super.getColumnImage(element, columnIndex);
>> }
>>
>> @Override
>> public String getColumnText(Object element, int columnIndex) {
>> if (columnIndex == 0) {
>> if (element instanceof Scene) {
>> Object o = map[0].get(element);
>> return (o != null) ? o.toString() : "(null)";
>> } else if (element instanceof Chapter) {
>> Object o = map[1].get(element);
>> return (o != null) ? o.toString() : "(null)";
>> } else if (element instanceof Book) {
>> Object o = map[2].get(element);
>> return (o != null) ? o.toString() : "(null)";
>> } else if (element instanceof World) {
>> Object o = map[3].get(element);
>> return (o != null) ? o.toString() : "(null)";
>> }
>> }
>> return super.getColumnText(element, columnIndex);
>> }
>>
>> };
>>
>> tViewer.setLabelProvider(omlp);
>>
>> IEMFListProperty projects =
>> EMFProperties.list(Literals.WORLD__BOOK);
>> tViewer.setInput(projects.observe(world));
>> ===============================================
>> ... and it WORKS!!
>> I still need to understand things better, but I can proceed.
>>
>> Another thing I haven't found out how to do is:
>>
>> The root of my model is World.
>>
>> /**
>> * @model
>> */
>> public interface World extends EObject {
>> /**
>> * @model
>> */
>> public String getAuthor();
>>
>> /**
>> * @model opposite="world" containment="true"
>> */
>> public EList<Book> getBook();
>>
>> /**
>> * @model containment="true"
>> */
>> public EList<Actor> getActor();
>>
>> /**
>> * @model containment="true"
>> */
>> public EList<Location> getLocation();
>>
>> ...
>>
>> } // World
>>
>> So it is rather wrong to use:
>> IEMFListProperty projects = EMFProperties.list(Literals.WORLD__BOOK);
>> tViewer.setInput(projects.observe(world));
>>
>> ... but I didn't find what I should use instead!
>> My ModelPackage doesn't seem to contain an EReference pointing to the
>> Model Root.
>>
>> What should I use?
>>
>> TiA
>> Mauro
>>
>>> Tom
>>>
>>> Am 15.02.10 10:11, schrieb Mauro Condarelli:
>>>> Mauro Condarelli wrote:
>>>>> Hi,
>>>>> I have a TreeView that is the main selection provider for one page:
>>>>> ...
>>>>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>>>>> toolkit.paintBordersFor(tree);
>>>>> tree.setHeaderVisible(true);
>>>>> tree.setLinesVisible(true);
>>>>> tViewer = new TreeViewer(tree);
>>>>> page.getEditorSite().setSelectionProvider(tViewer);
>>>>> ...
>>>>> I have a context menu attached to the TreeView which has provisions to
>>>>> add new nodes to the Model.
>>>>> The context is dynamically created and, in the end fires the handler
>>>>> of a Command. The handler for one particular addition (Add Scene) is
>>>>> like this:
>>>>>
>>>>> public class AddScene extends AbstractHandler {
>>>>> static final String ID = "it.condarelli.wbtest.commands.AddScene";
>>>>>
>>>>> @Override
>>>>> public Object execute(ExecutionEvent event) throws
>>>>> ExecutionException {
>>>>> ISelection is = HandlerUtil.getCurrentSelection(event);
>>>>> if (is instanceof IStructuredSelection) {
>>>>> IStructuredSelection iss = (IStructuredSelection) is;
>>>>> Object o = iss.getFirstElement();
>>>>> if (o instanceof Chapter) {
>>>>> Chapter _c = (Chapter) o;
>>>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>>>> _c.getScene().add(0, sc);
>>>>> System.out.println("AddScene: added new Scene at start
>>>>> of Chapter '" + _c.getTitle()+"'");
>>>>> } else if (o instanceof Scene) {
>>>>> Scene _s = (Scene) o;
>>>>> Scene sc = ModelFactory.eINSTANCE.createScene();
>>>>> Chapter _c = _s.getChapter();
>>>>> int i = _c.getScene().indexOf(_s);
>>>>> _c.getScene().add(i+1, sc);
>>>>> System.out.println("AddScene: added new Scene in
>>>>> Chapter '" + _c.getTitle()+"' after Scene '"+_s.getTitle()+"'" );
>>>>> }
>>>>>
>>>>> } else
>>>>> System.err.println("AddScene bad selection: " + is);
>>>>> return null;
>>>>> }
>>>>>
>>>>> }
>>>>>
>>>>> Up to here everything is Ok. There is a nice separation between the UI
>>>>> and the Model, but now problems start:
>>>>>
>>>>> 1) the TreeView does not fully reflect the changes in the model; if I
>>>>> add a Scene after another Scene (else if (o instanceof Scene) {...)
>>>>> everything is ok, but if I add a Scene in an empty Chapter (if (o
>>>>> instanceof Chapter) {...) the addition is *not* reflected by UI: I
>>>>> need to reload the application (or otherwise reinitialize the
>>>>> TreeViewer to see the newly created Scene.
>>>>>
>>>>> 2) I would like to automatically select the new Scene, but I simply do
>>>>> not know how to do that at this point in the code.
>>>>>
>>>>> I am aware of several documents explaining how to synchronize <ui with
>>>>> Model (e.g.:
>>>>> http://www.eclipse.org/articles/Article-TreeViewer/TreeViewe rArticle.htm),
>>>>>
>>>>> but they all seem to require knowledge of the visual component
>>>>> (tViewer, in this case).
>>>>>
>>>>> I can think of several ways to let the Handler to get hold of tViewer,
>>>>> but I strngly suspect there should be a better way than to pollute the
>>>>> whole code with cross-knowledge between Model and UI.
>>>>>
>>>>> Ideally I would like to be able to extract information about the
>>>>> Widget (tViewer) from the Selection I get from the Selection Service,
>>>>> but I didn't find a way to do that.
>>>>>
>>>>> Can someone point me in the right direction, please?
>>>>>
>>>>> Thanks in Advance
>>>>> Mauro
>>>> Ok,
>>>> Answering to myself again ;)
>>>> For the record:
>>>> I solved the above problem by adding this to the AddScene Handler:
>>>>
>>>> ISelectionProvider isp = HandlerUtil
>>>> .getActiveEditor(event)
>>>> .getSite()
>>>> .getSelectionProvider();
>>>> if (isp instanceof Viewer) {
>>>> Viewer tv = (Viewer) isp;
>>>> tv.refresh();
>>>> }
>>>> ISelection sel = new StructuredSelection(sc);
>>>> isp.setSelection(sel);
>>>> ============================================================ =====
>>>> Now I have a similar problem involving EMF Databinding.
>>>> This is reason for crossposting.
>>>>
>>>> My TreeViewer displays some data from the Model.
>>>> I have some master/detail pages that modify the model, possibly
>>>> including the data displayed in the master TreeViewer.
>>>> When this happens the TreeViewer is not automatically refreshed and I
>>>> couldn't guess how to do it manually.
>>>>
>>>> TreeVieweris built like this:
>>>>
>>>> tree = toolkit.createTree(composite_2, SWT.BORDER);
>>>> toolkit.paintBordersFor(tree);
>>>> tree.setHeaderVisible(true);
>>>> tree.setLinesVisible(true);
>>>> tViewer = new TreeViewer(tree);
>>>> bind();
>>>>
>>>> The binding is:
>>>>
>>>> protected void bindText(DataBindingContext dbc, Text t, EObject o,
>>>> EStructuralFeature sf) {
>>>> final IWidgetValueProperty wvp =
>>>> WidgetProperties.text(SWT.Modify);
>>>> IObservableValue uiObs = wvp.observeDelayed(400, t);
>>>> IEMFValueProperty evp = EMFProperties.value(sf);
>>>> IObservableValue mObs = evp.observe(o);
>>>> dbc.bindValue(uiObs, mObs, null, null);
>>>> }
>>>>
>>>> protected void bind() {
>>>> DataBindingContext dbc = new DataBindingContext();
>>>>
>>>> bindText(dbc, textAuthor, world, Literals.WORLD__AUTHOR);
>>>> bindText(dbc, textName, world, Literals.WORLD__TITLE);
>>>> bindText(dbc, textDesc, world, Literals.WORLD__DESC);
>>>>
>>>> IObservableFactory iof = new WorldObservableFactory();
>>>> TreeStructureAdvisor tsa = new WorldTreeStructureAdvisor();
>>>> ObservableListTreeContentProvider cp = new
>>>> ObservableListTreeContentProvider(iof, tsa);
>>>> tViewer.setContentProvider(cp);
>>>>
>>>> WorldLabelProvider wlp = new WorldLabelProvider();
>>>> tViewer.setLabelProvider(wlp);
>>>>
>>>> IEMFListProperty projects =
>>>> EMFProperties.list(ModelPackage.Literals.WORLD__BOOK);
>>>> tViewer.setInput(projects.observe(world));
>>>> }
>>>>
>>>> This works, but tViewer is not updated when the Model changes.
>>>>
>>>> I tried adding:
>>>>
>>>> IObservableList w = projects.observe(world);
>>>> w.addChangeListener(new IChangeListener() {
>>>> @Override
>>>> public void handleChange(ChangeEvent event) {
>>>> tViewer.refresh();
>>>> }
>>>> });
>>>>
>>>> But it is never called.
>>>> I can send any information needed. I just refrained from adding to an
>>>> already quite long post. Just ask.
>>>> What should I do?
>>>>
>>>> TiA
>>>> Mauro
>
Re: model/TreeView synchronization problem. [message #514563 is a reply to message #514512] Mon, 15 February 2010 19:11 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Mauro Condarelli wrote:
> Tom Schindl wrote:
>> Hi,
>>
>> I'm not sure I follow this. Do you talk about observing the
>> Resource#getContent()? There's currently no properties support for this
>> and you need to use EMFObservables#observeResource().
>>
>> There's a bug (and a 90% ready implementation) already to provide this
>> through the Properties-API but I can't remember the bug id.
>
> Thanks a lot for the ultra-fast answer!
>
> Yes. I want to observe Resource.getContent().
>
> I will search for the bug and, in the meantime, I will try to understand
> how to use EMFObservables#observeResource().
>
> Many Thanks again
> Mauro

Sorry to pester You again.

I tried the following code:

Resource r = model.getResource();
// EList<EObject> eol = r.getContents();
IObservableList iol = EMFObservables.observeResourceContents(r);
tViewer.setInput(iol);

.... and it really displays the root of my tree.

Unfortunately trying to open it to display nodes it bombs with:

java.lang.ClassCastException: java.lang.String cannot be cast to
java.util.List
at
org.eclipse.emf.databinding.internal.EMFListProperty.doGetLi st(EMFListProperty.java:65)
at
org.eclipse.core.databinding.property.list.SimpleListPropert y.getList(SimpleListProperty.java:63)
at
org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.getList(SimplePropertyObservableList.ja va:122)
at
org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.doGetSize(SimplePropertyObservableList. java:126)

So I must be doing som Real Bad Things :((

I have not (yet) been able to find a suitable example on the Internet,
so here I am :)

Thanks in Advance
Mauro
Re: model/TreeView synchronization problem. [message #514568 is a reply to message #514563] Mon, 15 February 2010 19:15 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Hi,

Can you show us your ObservableFactory, I guess this where your problem
is orginating from.

Tom

Am 15.02.10 20:11, schrieb Mauro Condarelli:
> Mauro Condarelli wrote:
>> Tom Schindl wrote:
>>> Hi,
>>>
>>> I'm not sure I follow this. Do you talk about observing the
>>> Resource#getContent()? There's currently no properties support for this
>>> and you need to use EMFObservables#observeResource().
>>>
>>> There's a bug (and a 90% ready implementation) already to provide this
>>> through the Properties-API but I can't remember the bug id.
>>
>> Thanks a lot for the ultra-fast answer!
>>
>> Yes. I want to observe Resource.getContent().
>>
>> I will search for the bug and, in the meantime, I will try to
>> understand how to use EMFObservables#observeResource().
>>
>> Many Thanks again
>> Mauro
>
> Sorry to pester You again.
>
> I tried the following code:
>
> Resource r = model.getResource();
> // EList<EObject> eol = r.getContents();
> IObservableList iol = EMFObservables.observeResourceContents(r);
> tViewer.setInput(iol);
>
> ... and it really displays the root of my tree.
>
> Unfortunately trying to open it to display nodes it bombs with:
>
> java.lang.ClassCastException: java.lang.String cannot be cast to
> java.util.List
> at
> org.eclipse.emf.databinding.internal.EMFListProperty.doGetLi st(EMFListProperty.java:65)
>
> at
> org.eclipse.core.databinding.property.list.SimpleListPropert y.getList(SimpleListProperty.java:63)
>
> at
> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.getList(SimplePropertyObservableList.ja va:122)
>
> at
> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.doGetSize(SimplePropertyObservableList. java:126)
>
>
> So I must be doing som Real Bad Things :((
>
> I have not (yet) been able to find a suitable example on the Internet,
> so here I am :)
>
> Thanks in Advance
> Mauro
Re: model/TreeView synchronization problem. [message #514570 is a reply to message #514568] Mon, 15 February 2010 19:18 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Tom Schindl wrote:
> Hi,
>
> Can you show us your ObservableFactory, I guess this where your problem
> is orginating from.
Pronto!

package it.condarelli.wbtest.editors;

import it.condarelli.wbtest.model.Book;
import it.condarelli.wbtest.model.Chapter;
import it.condarelli.wbtest.model.ModelPackage;
import it.condarelli.wbtest.model.World;

import org.eclipse.core.databinding.observable.IObservable;
import org.eclipse.core.databinding.observable.list.IObservableList ;
import
org.eclipse.core.databinding.observable.masterdetail.IObserv ableFactory;
import org.eclipse.emf.databinding.EMFProperties;
import org.eclipse.emf.databinding.IEMFListProperty;

public class WorldObservableFactory implements IObservableFactory {
private IEMFListProperty wMulti =
EMFProperties.multiList(ModelPackage.Literals.WORLD__ACTOR,
ModelPackage.Literals.BOOK__LOCATION, ModelPackage.Literals.WORLD__BOOK);
private IEMFListProperty bMulti =
EMFProperties.multiList(ModelPackage.Literals.BOOK__ACTOR,
ModelPackage.Literals.BOOK__LOCATION,
ModelPackage.Literals.BOOK__CHAPTER, ModelPackage.Literals.BOOK__ITEM);
private IEMFListProperty cMulti =
EMFProperties.multiList(ModelPackage.Literals.CHAPTER__ACTOR ,
ModelPackage.Literals.CHAPTER__SCENE);

public WorldObservableFactory() {
// TODO Auto-generated constructor stub
}

@Override
public IObservable createObservable(Object target) {
if (target instanceof IObservableList) {
return (IObservable) target;
} else if (target instanceof World) {
return wMulti.observe(target);
} else if (target instanceof Book) {
return bMulti.observe(target);
} else if (target instanceof Chapter) {
return cMulti.observe(target);
}
return null;
}

}

TiA
Mauro

>
> Tom
>
> Am 15.02.10 20:11, schrieb Mauro Condarelli:
>> Mauro Condarelli wrote:
>>> Tom Schindl wrote:
>>>> Hi,
>>>>
>>>> I'm not sure I follow this. Do you talk about observing the
>>>> Resource#getContent()? There's currently no properties support for this
>>>> and you need to use EMFObservables#observeResource().
>>>>
>>>> There's a bug (and a 90% ready implementation) already to provide this
>>>> through the Properties-API but I can't remember the bug id.
>>> Thanks a lot for the ultra-fast answer!
>>>
>>> Yes. I want to observe Resource.getContent().
>>>
>>> I will search for the bug and, in the meantime, I will try to
>>> understand how to use EMFObservables#observeResource().
>>>
>>> Many Thanks again
>>> Mauro
>> Sorry to pester You again.
>>
>> I tried the following code:
>>
>> Resource r = model.getResource();
>> // EList<EObject> eol = r.getContents();
>> IObservableList iol = EMFObservables.observeResourceContents(r);
>> tViewer.setInput(iol);
>>
>> ... and it really displays the root of my tree.
>>
>> Unfortunately trying to open it to display nodes it bombs with:
>>
>> java.lang.ClassCastException: java.lang.String cannot be cast to
>> java.util.List
>> at
>> org.eclipse.emf.databinding.internal.EMFListProperty.doGetLi st(EMFListProperty.java:65)
>>
>> at
>> org.eclipse.core.databinding.property.list.SimpleListPropert y.getList(SimpleListProperty.java:63)
>>
>> at
>> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.getList(SimplePropertyObservableList.ja va:122)
>>
>> at
>> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.doGetSize(SimplePropertyObservableList. java:126)
>>
>>
>> So I must be doing som Real Bad Things :((
>>
>> I have not (yet) been able to find a suitable example on the Internet,
>> so here I am :)
>>
>> Thanks in Advance
>> Mauro
>
Re: model/TreeView synchronization problem. [message #514577 is a reply to message #514570] Mon, 15 February 2010 19:41 Go to previous message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 428
Registered: September 2009
Senior Member
Mauro Condarelli wrote:
> Tom Schindl wrote:
>> Hi,
>>
>> Can you show us your ObservableFactory, I guess this where your problem
>> is orginating from.
> Pronto!
>
> package it.condarelli.wbtest.editors;
>
> import it.condarelli.wbtest.model.Book;
> import it.condarelli.wbtest.model.Chapter;
> import it.condarelli.wbtest.model.ModelPackage;
> import it.condarelli.wbtest.model.World;
>
> import org.eclipse.core.databinding.observable.IObservable;
> import org.eclipse.core.databinding.observable.list.IObservableList ;
> import
> org.eclipse.core.databinding.observable.masterdetail.IObserv ableFactory;
> import org.eclipse.emf.databinding.EMFProperties;
> import org.eclipse.emf.databinding.IEMFListProperty;
>
> public class WorldObservableFactory implements IObservableFactory {
> private IEMFListProperty wMulti =
> EMFProperties.multiList(ModelPackage.Literals.WORLD__ACTOR,
> ModelPackage.Literals.BOOK__LOCATION, ModelPackage.Literals.WORLD__BOOK);

HERE IS THE BUG!! it should be:
ModelPackage.Literals.WORLD__LOCATION, ModelPackage.Literals.WORLD__BOOK);

Many thanks for pointing me in the right direction I never would have
guessed!

T H A N K S!!

Regards
Mauro

> private IEMFListProperty bMulti =
> EMFProperties.multiList(ModelPackage.Literals.BOOK__ACTOR,
> ModelPackage.Literals.BOOK__LOCATION,
> ModelPackage.Literals.BOOK__CHAPTER, ModelPackage.Literals.BOOK__ITEM);
> private IEMFListProperty cMulti =
> EMFProperties.multiList(ModelPackage.Literals.CHAPTER__ACTOR ,
> ModelPackage.Literals.CHAPTER__SCENE);
>
> public WorldObservableFactory() {
> // TODO Auto-generated constructor stub
> }
>
> @Override
> public IObservable createObservable(Object target) {
> if (target instanceof IObservableList) {
> return (IObservable) target;
> } else if (target instanceof World) {
> return wMulti.observe(target);
> } else if (target instanceof Book) {
> return bMulti.observe(target);
> } else if (target instanceof Chapter) {
> return cMulti.observe(target);
> }
> return null;
> }
>
> }
>
> TiA
> Mauro
>
>>
>> Tom
>>
>> Am 15.02.10 20:11, schrieb Mauro Condarelli:
>>> Mauro Condarelli wrote:
>>>> Tom Schindl wrote:
>>>>> Hi,
>>>>>
>>>>> I'm not sure I follow this. Do you talk about observing the
>>>>> Resource#getContent()? There's currently no properties support for
>>>>> this
>>>>> and you need to use EMFObservables#observeResource().
>>>>>
>>>>> There's a bug (and a 90% ready implementation) already to provide this
>>>>> through the Properties-API but I can't remember the bug id.
>>>> Thanks a lot for the ultra-fast answer!
>>>>
>>>> Yes. I want to observe Resource.getContent().
>>>>
>>>> I will search for the bug and, in the meantime, I will try to
>>>> understand how to use EMFObservables#observeResource().
>>>>
>>>> Many Thanks again
>>>> Mauro
>>> Sorry to pester You again.
>>>
>>> I tried the following code:
>>>
>>> Resource r = model.getResource();
>>> // EList<EObject> eol = r.getContents();
>>> IObservableList iol = EMFObservables.observeResourceContents(r);
>>> tViewer.setInput(iol);
>>>
>>> ... and it really displays the root of my tree.
>>>
>>> Unfortunately trying to open it to display nodes it bombs with:
>>>
>>> java.lang.ClassCastException: java.lang.String cannot be cast to
>>> java.util.List
>>> at
>>> org.eclipse.emf.databinding.internal.EMFListProperty.doGetLi st(EMFListProperty.java:65)
>>>
>>>
>>> at
>>> org.eclipse.core.databinding.property.list.SimpleListPropert y.getList(SimpleListProperty.java:63)
>>>
>>>
>>> at
>>> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.getList(SimplePropertyObservableList.ja va:122)
>>>
>>>
>>> at
>>> org.eclipse.core.internal.databinding.property.list.SimplePr opertyObservableList.doGetSize(SimplePropertyObservableList. java:126)
>>>
>>>
>>>
>>> So I must be doing som Real Bad Things :((
>>>
>>> I have not (yet) been able to find a suitable example on the Internet,
>>> so here I am :)
>>>
>>> Thanks in Advance
>>> Mauro
>>
Previous Topic:No checkbox for all nodes in a CheckboxTreeViewer ?
Next Topic:[Databinding] TreeViewer with items that contain lists (that should appear as subtrees)
Goto Forum:
  


Current Time: Tue Apr 16 22:57:58 GMT 2024

Powered by FUDForum. Page generated in 4.28116 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top