Home » Modeling » EMF » EMF + DataBinding + Master/Detail problem
EMF + DataBinding + Master/Detail problem [message #530607] |
Fri, 30 April 2010 10:04 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
Hi,
I must be doing something *very* wrong, but I cannot understand what.
Please point me in the right direction.
-- I have a Master page:
public class WorldMasterBlock extends MasterDetailsBlock {
...
private IObservableValue treeObs = null;
...
@Override
protected void createMasterPart(final IManagedForm managedForm,
Composite parent) {
...
tree = toolkit.createTree(composite_2, SWT.BORDER);
tViewer = new TreeViewer(tree);
...
treeObs = ViewerProperties.singleSelection().observe(tViewer);
...
}
@Override
protected void registerPages(DetailsPart part) {
...
part.registerPage(SceneImpl.class, new SceneDetailsPage2(treeObs));
...
}
-- and a Details page:
public class SceneDetailsPage2 implements IDetailsPage {
private IObservableValue observableScene = null;
...
public SceneDetailsPage2(IObservableValue observableScene) {
this.observableScene = observableScene;
}
...
public void createContents(Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
...
EMFDataBindingContext ctx = new EMFDataBindingContext();
IWidgetValueProperty text = WidgetProperties.text(SWT.Modify);
IWidgetListProperty list = WidgetProperties.items();
IWidgetValueProperty sel = WidgetProperties.selection();
ctx.bindValue(text.observeDelayed(500, txtTitle),
EMFProperties.value(WorldPackage.Literals.IBASE__TITLE).obse rveDetail(observableScene));
ctx.bindValue(text.observeDelayed(500, txtDesc),
EMFProperties.value(WorldPackage.Literals.IBASE__DESC).obser veDetail(observableScene));
ctx.bindValue(text.observeDelayed(500, txtContent),
EMFProperties.value(WorldPackage.Literals.IBASE__CONTENT).ob serveDetail(observableScene));
ctx.bindValue(text.observeDelayed(500, txtWords),
EMFProperties.value(WorldPackage.Literals.SCENE__WORD_COUNT) .observeDetail(observableScene));
ctx.bindList(list.observe(lstActors),
EMFProperties.list(FeaturePath.fromList(WorldPackage.Literal s.SCENE__ACTOR,
WorldPackage.Literals.ACTOR__NAME)).observeDetail(observable Scene));
ctx.bindValue(new
DateAndTimeObservableValue(sel.observeDelayed(500, dtDate),
sel.observeDelayed(500, dtTime)),
EMFProperties.value(FeaturePath.fromList(WorldPackage.Litera ls.IBASE__TIME,
WorldPackage.Literals.TIME_EVENT__DATE)).observeDetail(obser vableScene));
ctx.bindValue(sel.observeDelayed(500, spnDays),
EMFProperties.value(FeaturePath.fromList(WorldPackage.Litera ls.IBASE__TIME,
WorldPackage.Literals.TIME_EVENT__SPANS_DAYS)).observeDetail (observableScene));
ctx.bindValue(sel.observeDelayed(500,
spnHours),EMFProperties.value(FeaturePath.fromList(WorldPack age.Literals.IBASE__TIME,
WorldPackage.Literals.TIME_EVENT__SPANS_HOURS)).observeDetai l(observableScene));
ctx.bindValue(sel.observeDelayed(500, spnMinutes),
EMFProperties.value(FeaturePath.fromList(WorldPackage.Litera ls.IBASE__TIME,
WorldPackage.Literals.TIME_EVENT__SPANS_MINUTES)).observeDet ail(observableScene));
}
...
public void selectionChanged(IFormPart part, ISelection selection) {
IStructuredSelection structuredSelection =
(IStructuredSelection) selection;
if (structuredSelection.size() == 1) {
Scene s = (Scene) structuredSelection.getFirstElement();
try {
Object o = observableScene.getValue(); //<-- this is
SceneDetailsPage2.java:359
if (o instanceof Scene) {
Scene z = (Scene) o;
System.out.println("structuredSelection(" +
s.getTitle() + "); observebleScene(" + z.getTitle() + ")");
} else {
System.out.println("structuredSelection(" +
s.getTitle() + "); observebleScene(" + o.getClass() + ")");
}
} catch (Exception e) {
System.out.println("structuredSelection(" +
s.getTitle() + "); exception(" + e.getMessage() + ")");
}
...
}
}
I am using selectionChanged() because I need to setup a few sliders I
didn't figure to how to bind to values. Otherwise it shouldn't be
necessary because observableScene should already track the selection in
Master.
All this works Ok on the *first* selection.
When I switch to another instance of Scene (in Master) it doesn't work
anymore.
A few (??) trials show that, after the first time any access to
observableScene value (observableScene.getValue() or
observableScene.setValue()) bombs with the following error.
What am I doing so wrong?
Note that not using the external treeObs and setting manually
obsevableScene in selectionChanged fails in a similar way from the first
iteration!
Resource file:/C:/Tmp/La-Missione.world is clean
structuredSelection(Prologo); observebleScene(Prologo)
structuredSelection(il Matrimonio);
exception(org.eclipse.emf.ecore.util.EObjectResolvingEList cannot be
cast to org.eclipse.emf.ecore.EObject)
java.lang.ClassCastException:
org.eclipse.emf.ecore.util.EObjectResolvingEList cannot be cast to
org.eclipse.emf.ecore.EObject
at
org.eclipse.emf.databinding.internal.EMFListProperty.doGetLi st(EMFListProperty.java:64)
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.toArray(SimplePropertyObservableList.ja va:161)
at java.util.ArrayList.<init>(Unknown Source)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$3.run(DetailObservableList.java:99)
at
org.eclipse.core.databinding.observable.ObservableTracker.ru nAndIgnore(ObservableTracker.java:169)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$2.handleValueChange(DetailObservableL ist.java:97)
at
org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.fireValueChange(DecoratingObservableValue.java:5 5)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.handleValueChange(DecoratingObservableValue.java :93)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue$1.handleValueChange(DecoratingObservableValue.ja va:67)
at
org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at
org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.fireValueChange(AbstractObservableValue.java:71)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableValue.access$1(DetailObservableValue.java: 1)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableValue$3.run(DetailObservableValue.java:92)
at
org.eclipse.core.databinding.observable.ObservableTracker.ru nAndIgnore(ObservableTracker.java:169)
at
org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableValue$2.handleValueChange(DetailObservable Value.java:88)
at
org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.fireValueChange(DecoratingObservableValue.java:5 5)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.handleValueChange(DecoratingObservableValue.java :93)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue$1.handleValueChange(DecoratingObservableValue.ja va:67)
at
org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at
org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at
org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.fireValueChange(AbstractObservableValue.java:71)
at
org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.notifyIfChanged(SimplePropertyObserva bleValue.java:120)
at
org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.doGetValue(SimplePropertyObservableVa lue.java:97)
at
org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.getValue(AbstractObservableValue.java:76)
at
org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.getValue(DecoratingObservableValue.java:98)
at
it.condarelli.writer.editors.SceneDetailsPage2.selectionChan ged(SceneDetailsPage2.java:359)
at org.eclipse.ui.forms.DetailsPart$1.run(DetailsPart.java:274)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.ui.forms.DetailsPart.showPage(DetailsPart.java:2 61)
at org.eclipse.ui.forms.DetailsPart.update(DetailsPart.java:234 )
at org.eclipse.ui.forms.DetailsPart.selectionChanged(DetailsPar t.java:219)
at
org.eclipse.ui.forms.ManagedForm.fireSelectionChanged(Manage dForm.java:148)
at
it.condarelli.writer.editors.WorldMasterBlock$2.selectionCha nged(WorldMasterBlock.java:240)
at org.eclipse.jface.viewers.Viewer$2.run(Viewer.java:162)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.runtime.Platform.run(Platform.java:888)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:48)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:17 5)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer .java:160)
at
org.eclipse.jface.viewers.StructuredViewer.updateSelection(S tructuredViewer.java:2132)
at
org.eclipse.jface.viewers.StructuredViewer.handleSelect(Stru cturedViewer.java:1160)
at
org.eclipse.jface.viewers.StructuredViewer$4.widgetSelected( StructuredViewer.java:1190)
at
org.eclipse.jface.util.OpenStrategy.fireSelectionEvent(OpenS trategy.java:228)
at org.eclipse.jface.util.OpenStrategy.access$4(OpenStrategy.ja va:222)
at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrate gy.java:389)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3910)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3503)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2405)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 21)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:332)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:493)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at it.condarelli.writer.Writer.start(Writer.java:20)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:194)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:110)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:79)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:368)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:179)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 559)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
at org.eclipse.equinox.launcher.Main.run(Main.java:1311)
at org.eclipse.equinox.launcher.Main.main(Main.java:1287)
Many thanks in advance
Mauro
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530703 is a reply to message #530607] |
Fri, 30 April 2010 14:52 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
On 30/04/2010 12.04, Mauro Condarelli wrote:
> Hi,
> I must be doing something *very* wrong, but I cannot understand what.
> Please point me in the right direction.
> ...
I'm answering to myself... up to a point.
I managed to pinpoint the error to this binding:
ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
List lstActors = listViewer.getList();
ctx.bindList(
list.observe(lstActors),
EMFProperties.list(
FeaturePath.fromList(
WorldPackage.Literals.SCENE__ACTOR,
WorldPackage.Literals.ACTOR__NAME
)
).observeDetail(observableScene)
);
where, in the model I have:
public interface Scene extends IBase {
...
/**
* @model lower="1" many="true"
*/
EList<Actor> getActor();
...
}
Actors are contained elsewhere; here is just a list of references.
public interface Actor extends EObject {
/**
* @model default="Nemo" required="true"
*/
String getName();
...
}
I suspect I don't really understand the semantics of
EMFProperties.list() and, possibly, of FeaturePath.fromList()
I need to construct a list of Actors and fill the ListView with their Names.
Thanks in Advance
Mauro
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530711 is a reply to message #530703] |
Fri, 30 April 2010 15:14 |
Eclipse User |
|
|
|
Originally posted by: Thomas.Kowatsch.ruag.com
Hi Mauro.
Best thing you have a look at Tom Schindel's EMF Databinding Blog.
http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
He is also discussing how to setup master detail bindings.
HTH
--Thomas
Mauro Condarelli schrieb:
> On 30/04/2010 12.04, Mauro Condarelli wrote:
>> Hi,
>> I must be doing something *very* wrong, but I cannot understand what.
>> Please point me in the right direction.
>> ...
> I'm answering to myself... up to a point.
>
> I managed to pinpoint the error to this binding:
>
> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> List lstActors = listViewer.getList();
> ctx.bindList(
> list.observe(lstActors),
> EMFProperties.list(
> FeaturePath.fromList(
> WorldPackage.Literals.SCENE__ACTOR,
> WorldPackage.Literals.ACTOR__NAME
> )
> ).observeDetail(observableScene)
> );
>
> where, in the model I have:
>
> public interface Scene extends IBase {
> ...
> /**
> * @model lower="1" many="true"
> */
> EList<Actor> getActor();
> ...
> }
> Actors are contained elsewhere; here is just a list of references.
>
> public interface Actor extends EObject {
>
> /**
> * @model default="Nemo" required="true"
> */
> String getName();
> ...
> }
>
> I suspect I don't really understand the semantics of
> EMFProperties.list() and, possibly, of FeaturePath.fromList()
>
> I need to construct a list of Actors and fill the ListView with their
> Names.
>
> Thanks in Advance
> Mauro
|
|
| | |
Re: EMF + DataBinding + Master/Detail problem [message #530811 is a reply to message #530805] |
Sat, 01 May 2010 09:08 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
On 01/05/2010 9.36, Tom Schindl wrote:
> Am 30.04.10 18:17, schrieb Mauro Condarelli:
>> On 30/04/2010 17.14, Thomas Kowatsch wrote:
>>> Hi Mauro.
>>> Best thing you have a look at Tom Schindel's EMF Databinding Blog.
>>> http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
>>>
>>> He is also discussing how to setup master detail bindings.
>>> HTH
>>> --Thomas
>>
>> Thanks for the hint, Thomas.
>>
>> I am aware of that.
>> Actually it is my main source of information.
>>
>
> Right but I also think that in case of Databinding and the description
> of the usecases it's probably impossible to get this into Javadoc,
> that's why I wrote the Databinding Blog Series (BTW every part of it has
> been already 4.000 hits == 20.000 hits in total :-).
>
> Probably time to write a book about Eclipse-Databinding :-)
If You do in a reasonable timeframe (before I discover the last secret
of Databinding) You have already sold at least my copy ;)
.... but I don't really understand: You can write whatever You want in
Javadoc, including, but not limited to: "The Lord of the Rings" :p (see:
http://java.sun.com/j2se/javadoc/writingdoccomments/ "Writing
Programming Guide Documentation"). I use extensively this feature at
work to document libraries I write (I actually use Doxygen because I
program mainly in C/C++). Hint. Hint. :) ;) :)
>
>> The Javadoc pages are somewhat terse.
>>
>> I think I managed to understand what's wrong, but I have no idea about
>> hos to make it right.
>>
>> In Tom's Example he has:
>>
>> // 2. Use case - observe the nested list
>> // The list of all subprojects of the projects parent
>> public IObservableList uc2(Project p) {
>> IEMFListProperty prop = EMFProperties.list(
>> FeaturePath.formList(
>> ProjectPackage.Literals.PROJECT__PROJECT,
>> ProjectPackage.Literals.PROJECT__SUBPROJECTS
>> )
>> );
>> return prop.observe(p);
>> }
>>
>> where ProjectPackage.Literals.PROJECT__PROJECT is a single value, while
>> ProjectPackage.Literals.PROJECT__SUBPROJECTS represents a list. i.e.: he
>> is dereferencing a project and using that to find a list of subprojects.
>>
>> I have the reverse: I have a list of Actors and for *each* of those I
>> need to retrieve a single attribute (the Name).
>>
>
> This is not supported if I get your request right. I'm not sure what
> you'd expect to use the actors name for. Can you show us the code you
> are using? If you want to observe the all actors names what you are
> searching for is an IObservableMap.
Here it comes!
Problematic binding is:
ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
List lstActors = listViewer.getList();
ctx.bindList(
list.observe(lstActors),
EMFProperties.list(
FeaturePath.fromList(
WorldPackage.Literals.SCENE__ACTOR,
WorldPackage.Literals.ACTOR__NAME
)
).observeDetail(observableScene)
);
where, in the model I have:
public interface Scene extends IBase {
...
/**
* @model lower="1" many="true"
*/
EList<Actor> getActor();
...
}
Actors are contained elsewhere; here is just a list of references.
public interface Actor extends EObject {
/**
* @model default="Nemo" required="true"
*/
String getName();
...
}
What I need is to:
- display in the ListViewer the names of the Actors in the Scene EList.
- be able to get a pointer to the Actor when I select it's Name (to edit
it).
- remove or add to the EList via drag&drop from the full list of Actors.
Right now I would be happy to achieve point 1. :(
>
>> I'm even unsure if that can be done (with Databinding, I mean) and I'm
>> completely in the fog about *how* to do it.
>>
>> Any comment?
>>
>> Side issue: I understand there should be a new edition of the book "EMF:
>> Eclipse Modeling Framework".
>> Two questions there:
>> 1) when will it be available?
>
> It's already available since about a year.
I oops. I thought there would be a "third Edition" soon.
Does it describe a reasonably current state of EMF?
>
>> 2) will it cover the above issues?
>>
>
> No.
:((((((((((
I think some specific would be *very* useful!
>
> Tom
Mauro
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530817 is a reply to message #530811] |
Sat, 01 May 2010 10:19 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Am 01.05.10 11:08, schrieb Mauro Condarelli:
> On 01/05/2010 9.36, Tom Schindl wrote:
>> Am 30.04.10 18:17, schrieb Mauro Condarelli:
>>> On 30/04/2010 17.14, Thomas Kowatsch wrote:
>>>> Hi Mauro.
>>>> Best thing you have a look at Tom Schindel's EMF Databinding Blog.
>>>> http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
>>>>
>>>>
>>>> He is also discussing how to setup master detail bindings.
>>>> HTH
>>>> --Thomas
>>>
>>> Thanks for the hint, Thomas.
>>>
>>> I am aware of that.
>>> Actually it is my main source of information.
>>>
>>
>> Right but I also think that in case of Databinding and the description
>> of the usecases it's probably impossible to get this into Javadoc,
>> that's why I wrote the Databinding Blog Series (BTW every part of it has
>> been already 4.000 hits == 20.000 hits in total :-).
>>
>> Probably time to write a book about Eclipse-Databinding :-)
>
> If You do in a reasonable timeframe (before I discover the last secret
> of Databinding) You have already sold at least my copy ;)
>
> ... but I don't really understand: You can write whatever You want in
> Javadoc, including, but not limited to: "The Lord of the Rings" :p (see:
> http://java.sun.com/j2se/javadoc/writingdoccomments/ "Writing
> Programming Guide Documentation"). I use extensively this feature at
> work to document libraries I write (I actually use Doxygen because I
> program mainly in C/C++). Hint. Hint. :) ;) :)
Yes but what you really need is example code to understand how all this
things work together.
>
>>
>>> The Javadoc pages are somewhat terse.
>>>
>>> I think I managed to understand what's wrong, but I have no idea about
>>> hos to make it right.
>>>
>>> In Tom's Example he has:
>>>
>>> // 2. Use case - observe the nested list
>>> // The list of all subprojects of the projects parent
>>> public IObservableList uc2(Project p) {
>>> IEMFListProperty prop = EMFProperties.list(
>>> FeaturePath.formList(
>>> ProjectPackage.Literals.PROJECT__PROJECT,
>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS
>>> )
>>> );
>>> return prop.observe(p);
>>> }
>>>
>>> where ProjectPackage.Literals.PROJECT__PROJECT is a single value, while
>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS represents a list. i.e.: he
>>> is dereferencing a project and using that to find a list of subprojects.
>>>
>>> I have the reverse: I have a list of Actors and for *each* of those I
>>> need to retrieve a single attribute (the Name).
>>>
>>
>> This is not supported if I get your request right. I'm not sure what
>> you'd expect to use the actors name for. Can you show us the code you
>> are using? If you want to observe the all actors names what you are
>> searching for is an IObservableMap.
>
> Here it comes!
> Problematic binding is:
>
> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> List lstActors = listViewer.getList();
> ctx.bindList(
> list.observe(lstActors),
> EMFProperties.list(
> FeaturePath.fromList(
> WorldPackage.Literals.SCENE__ACTOR,
> WorldPackage.Literals.ACTOR__NAME
> )
> ).observeDetail(observableScene)
> );
>
IListProperty lp =
EMFProperties.value(WorldPackage.Literals.SCENE__ACTOR);
IValueProperty p =
EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
ObservableListContentProvider cp = new ObservableListContentProvider();
TableViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
listViewer.setContentProvider(cp);
listViewer.setLabelProvider(new
ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts()))
);
listViewer.setInput(lp.observeDetail(observableScene));
If you want a better LabelProvider I'd suggest you take a look at the
class is wrote for my blog example named GenericMapCellLabelProvider.
> where, in the model I have:
>
> public interface Scene extends IBase {
> ...
> /**
> * @model lower="1" many="true"
> */
> EList<Actor> getActor();
> ...
> }
> Actors are contained elsewhere; here is just a list of references.
>
> public interface Actor extends EObject {
>
> /**
> * @model default="Nemo" required="true"
> */
> String getName();
> ...
> }
>
> What I need is to:
> - display in the ListViewer the names of the Actors in the Scene EList.
See above how this should look like
> - be able to get a pointer to the Actor when I select it's Name (to edit
> it).
With a Table you can use EditingSupport
> - remove or add to the EList via drag&drop from the full list of Actors.
>
See above modifying the EList updates your viewers content.
Tom
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530818 is a reply to message #530817] |
Sat, 01 May 2010 10:23 |
Thomas Schindl Messages: 6651 Registered: July 2009 |
Senior Member |
|
|
Am 01.05.10 12:19, schrieb Tom Schindl:
> Am 01.05.10 11:08, schrieb Mauro Condarelli:
>> On 01/05/2010 9.36, Tom Schindl wrote:
>>> Am 30.04.10 18:17, schrieb Mauro Condarelli:
>>>> On 30/04/2010 17.14, Thomas Kowatsch wrote:
>>>>> Hi Mauro.
>>>>> Best thing you have a look at Tom Schindel's EMF Databinding Blog.
>>>>> http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
>>>>>
>>>>>
>>>>> He is also discussing how to setup master detail bindings.
>>>>> HTH
>>>>> --Thomas
>>>>
>>>> Thanks for the hint, Thomas.
>>>>
>>>> I am aware of that.
>>>> Actually it is my main source of information.
>>>>
>>>
>>> Right but I also think that in case of Databinding and the description
>>> of the usecases it's probably impossible to get this into Javadoc,
>>> that's why I wrote the Databinding Blog Series (BTW every part of it has
>>> been already 4.000 hits == 20.000 hits in total :-).
>>>
>>> Probably time to write a book about Eclipse-Databinding :-)
>>
>> If You do in a reasonable timeframe (before I discover the last secret
>> of Databinding) You have already sold at least my copy ;)
>>
>> ... but I don't really understand: You can write whatever You want in
>> Javadoc, including, but not limited to: "The Lord of the Rings" :p (see:
>> http://java.sun.com/j2se/javadoc/writingdoccomments/ "Writing
>> Programming Guide Documentation"). I use extensively this feature at
>> work to document libraries I write (I actually use Doxygen because I
>> program mainly in C/C++). Hint. Hint. :) ;) :)
>
> Yes but what you really need is example code to understand how all this
> things work together.
>
>>
>>>
>>>> The Javadoc pages are somewhat terse.
>>>>
>>>> I think I managed to understand what's wrong, but I have no idea about
>>>> hos to make it right.
>>>>
>>>> In Tom's Example he has:
>>>>
>>>> // 2. Use case - observe the nested list
>>>> // The list of all subprojects of the projects parent
>>>> public IObservableList uc2(Project p) {
>>>> IEMFListProperty prop = EMFProperties.list(
>>>> FeaturePath.formList(
>>>> ProjectPackage.Literals.PROJECT__PROJECT,
>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS
>>>> )
>>>> );
>>>> return prop.observe(p);
>>>> }
>>>>
>>>> where ProjectPackage.Literals.PROJECT__PROJECT is a single value, while
>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS represents a list. i.e.: he
>>>> is dereferencing a project and using that to find a list of subprojects.
>>>>
>>>> I have the reverse: I have a list of Actors and for *each* of those I
>>>> need to retrieve a single attribute (the Name).
>>>>
>>>
>>> This is not supported if I get your request right. I'm not sure what
>>> you'd expect to use the actors name for. Can you show us the code you
>>> are using? If you want to observe the all actors names what you are
>>> searching for is an IObservableMap.
>>
>> Here it comes!
>> Problematic binding is:
>>
>> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
>> List lstActors = listViewer.getList();
>> ctx.bindList(
>> list.observe(lstActors),
>> EMFProperties.list(
>> FeaturePath.fromList(
>> WorldPackage.Literals.SCENE__ACTOR,
>> WorldPackage.Literals.ACTOR__NAME
>> )
>> ).observeDetail(observableScene)
>> );
>>
>
>
> IListProperty lp =
> EMFProperties.value(WorldPackage.Literals.SCENE__ACTOR);
>
> IValueProperty p =
> EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
>
> ObservableListContentProvider cp = new ObservableListContentProvider();
>
> TableViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> listViewer.setContentProvider(cp);
> listViewer.setLabelProvider(new
> ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts()))
> );
> listViewer.setInput(lp.observeDetail(observableScene));
>
>
In the end it is the stuff described in
http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/
when I talk about binding a TableViewer.
Tom
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530853 is a reply to message #530817] |
Sat, 01 May 2010 21:18 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
On 01/05/2010 12.19, Tom Schindl wrote:
> Am 01.05.10 11:08, schrieb Mauro Condarelli:
>> On 01/05/2010 9.36, Tom Schindl wrote:
>>> Am 30.04.10 18:17, schrieb Mauro Condarelli:
>>>> On 30/04/2010 17.14, Thomas Kowatsch wrote:
>>>>> Hi Mauro.
>>>>> Best thing you have a look at Tom Schindel's EMF Databinding Blog.
>>>>> http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
>>>>>
>>>>>
>>>>> He is also discussing how to setup master detail bindings.
>>>>> HTH
>>>>> --Thomas
>>>>
>>>> Thanks for the hint, Thomas.
>>>>
>>>> I am aware of that.
>>>> Actually it is my main source of information.
>>>>
>>>
>>> Right but I also think that in case of Databinding and the description
>>> of the usecases it's probably impossible to get this into Javadoc,
>>> that's why I wrote the Databinding Blog Series (BTW every part of it has
>>> been already 4.000 hits == 20.000 hits in total :-).
>>>
>>> Probably time to write a book about Eclipse-Databinding :-)
>>
>> If You do in a reasonable timeframe (before I discover the last secret
>> of Databinding) You have already sold at least my copy ;)
>>
>> ... but I don't really understand: You can write whatever You want in
>> Javadoc, including, but not limited to: "The Lord of the Rings" :p (see:
>> http://java.sun.com/j2se/javadoc/writingdoccomments/ "Writing
>> Programming Guide Documentation"). I use extensively this feature at
>> work to document libraries I write (I actually use Doxygen because I
>> program mainly in C/C++). Hint. Hint. :) ;) :)
>
> Yes but what you really need is example code to understand how all this
> things work together.
Agreed.
What I sourly miss is a cookbook-style book on RCP development.
There are a lot of ways to do similar things and I'm lost.
I hope to come to a grip sooner or later.
>
>>
>>>
>>>> The Javadoc pages are somewhat terse.
>>>>
>>>> I think I managed to understand what's wrong, but I have no idea about
>>>> hos to make it right.
>>>>
>>>> In Tom's Example he has:
>>>>
>>>> // 2. Use case - observe the nested list
>>>> // The list of all subprojects of the projects parent
>>>> public IObservableList uc2(Project p) {
>>>> IEMFListProperty prop = EMFProperties.list(
>>>> FeaturePath.formList(
>>>> ProjectPackage.Literals.PROJECT__PROJECT,
>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS
>>>> )
>>>> );
>>>> return prop.observe(p);
>>>> }
>>>>
>>>> where ProjectPackage.Literals.PROJECT__PROJECT is a single value, while
>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS represents a list. i.e.: he
>>>> is dereferencing a project and using that to find a list of subprojects.
>>>>
>>>> I have the reverse: I have a list of Actors and for *each* of those I
>>>> need to retrieve a single attribute (the Name).
>>>>
>>>
>>> This is not supported if I get your request right. I'm not sure what
>>> you'd expect to use the actors name for. Can you show us the code you
>>> are using? If you want to observe the all actors names what you are
>>> searching for is an IObservableMap.
>>
>> Here it comes!
>> Problematic binding is:
>>
>> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
>> List lstActors = listViewer.getList();
>> ctx.bindList(
>> list.observe(lstActors),
>> EMFProperties.list(
>> FeaturePath.fromList(
>> WorldPackage.Literals.SCENE__ACTOR,
>> WorldPackage.Literals.ACTOR__NAME
>> )
>> ).observeDetail(observableScene)
>> );
>>
>
>
> IListProperty lp =
> EMFProperties.value(WorldPackage.Literals.SCENE__ACTOR);
>
> IValueProperty p =
> EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
>
> ObservableListContentProvider cp = new ObservableListContentProvider();
>
> TableViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> listViewer.setContentProvider(cp);
> listViewer.setLabelProvider(new
> ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts()))
> );
> listViewer.setInput(lp.observeDetail(observableScene));
>
I modified Your code as follows (for obvious errors):
ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
...
IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
IValueProperty p = EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
ObservableListContentProvider cp = new ObservableListContentProvider();
listViewer.setContentProvider(cp);
listViewer.setLabelProvider(new ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts())));
listViewer.setInput(lp.observeDetail(observableScene));
this somewhat works, but doesn't always update well when I change the selection in my Master.
My Master/Detail is as follows:
-- I have a Master page:
public class WorldMasterBlock extends MasterDetailsBlock {
...
private IObservableValue treeObs = null;
...
@Override
protected void createMasterPart(final IManagedForm managedForm,
Composite parent) {
...
tree = toolkit.createTree(composite_2, SWT.BORDER);
tViewer = new TreeViewer(tree);
...
treeObs = ViewerProperties.singleSelection().observe(tViewer);
...
}
@Override
protected void registerPages(DetailsPart part) {
...
part.registerPage(SceneImpl.class, new SceneDetailsPage2(treeObs));
...
}
-- and a Details page:
public class SceneDetailsPage2 implements IDetailsPage {
private IObservableValue observableScene = null;
...
public SceneDetailsPage2(IObservableValue observableScene) {
this.observableScene = observableScene;
}
...
public void createContents(Composite parent) {
FormToolkit toolkit = managedForm.getToolkit();
...
ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
List lstActors = listViewer.getList();
lstActors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
...
EMFDataBindingContext ctx = new EMFDataBindingContext();
...
IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
IValueProperty p = EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
ObservableListContentProvider cp = new ObservableListContentProvider();
listViewer.setContentProvider(cp);
listViewer.setLabelProvider(new ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts())));
listViewer.setInput(lp.observeDetail(observableScene));
}
...
public void selectionChanged(IFormPart part, ISelection selection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.size() == 1) {
Scene s = (Scene) structuredSelection.getFirstElement();
try {
Object o = observableScene.getValue(); //<-- this is SceneDetailsPage2.java:405
if (o instanceof Scene) {
Scene z = (Scene) o;
System.out.println("structuredSelection(" + s.getTitle() + "); observebleScene(" + z.getTitle() + ")");
} else {
System.out.println("structuredSelection(" + s.getTitle() + "); observebleScene(" + o.getClass() + ")");
}
} catch (Exception e) {
System.out.println("structuredSelection(" + s.getTitle() + "); exception(" + e.getMessage() + ")");
}
...
}
}
I am using selectionChanged() because I need to setup a few sliders I didn't figure to how to bind to values. Otherwise it shouldn't be necessary because observableScene should already track the selection in Master.
when it starts misbehaving I consistently get the following error:
structuredSelection(Il Risveglio); exception(null)
java.lang.NullPointerException
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSettingDelegate (BasicEObjectImpl.java:1542)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1029)
at it.condarelli.writer.model.world.impl.IBaseImpl.eGet(IBaseIm pl.java:597)
at it.condarelli.writer.model.world.impl.ChapterImpl.eGet(Chapt erImpl.java:262)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1013)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1005)
at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1000)
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.toArray(SimplePropertyObservableList.ja va:161)
at java.util.ArrayList.<init>(Unknown Source)
at org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$3.run(DetailObservableList.java:99)
at org.eclipse.core.databinding.observable.ObservableTracker.ru nAndIgnore(ObservableTracker.java:169)
at org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$2.handleValueChange(DetailObservableL ist.java:97)
at org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.fireValueChange(DecoratingObservableValue.java:5 5)
at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.handleValueChange(DecoratingObservableValue.java :93)
at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue$1.handleValueChange(DecoratingObservableValue.ja va:67)
at org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
at org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
at org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.fireValueChange(AbstractObservableValue.java:71)
at org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.notifyIfChanged(SimplePropertyObserva bleValue.java:120)
at org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.doGetValue(SimplePropertyObservableVa lue.java:97)
at org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.getValue(AbstractObservableValue.java:76)
at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.getValue(DecoratingObservableValue.java:98)
at it.condarelli.writer.editors.SceneDetailsPage2.selectionChan ged(SceneDetailsPage2.java:405)
at org.eclipse.ui.forms.DetailsPart$1.run(DetailsPart.java:274)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
at org.eclipse.ui.forms.DetailsPart.showPage(DetailsPart.java:2 61)
at org.eclipse.ui.forms.DetailsPart.update(DetailsPart.java:234 )
at org.eclipse.ui.forms.DetailsPart.selectionChanged(DetailsPar t.java:219)
at org.eclipse.ui.forms.ManagedForm.fireSelectionChanged(Manage dForm.java:148)
at it.condarelli.writer.editors.WorldMasterBlock$2.selectionCha nged(WorldMasterBlock.java:240)
...
Can You divine what's going wrong?
>
> If you want a better LabelProvider I'd suggest you take a look at the
> class is wrote for my blog example named GenericMapCellLabelProvider.
I will, even if a plain list is ok.
>
>> where, in the model I have:
>>
>> public interface Scene extends IBase {
>> ...
>> /**
>> * @model lower="1" many="true"
>> */
>> EList<Actor> getActor();
>> ...
>> }
>> Actors are contained elsewhere; here is just a list of references.
>>
>> public interface Actor extends EObject {
>>
>> /**
>> * @model default="Nemo" required="true"
>> */
>> String getName();
>> ...
>> }
>>
>> What I need is to:
>> - display in the ListViewer the names of the Actors in the Scene EList.
>
> See above how this should look like
I'm still missing something :(
>
>> - be able to get a pointer to the Actor when I select it's Name (to edit
>> it).
>
> With a Table you can use EditingSupport
>
>> - remove or add to the EList via drag&drop from the full list of Actors.
>>
>
> See above modifying the EList updates your viewers content.
>
> Tom
Thanks
Mauro
|
|
|
Re: EMF + DataBinding + Master/Detail problem [message #530878 is a reply to message #530853] |
Sun, 02 May 2010 10:03 |
Mauro Condarelli Messages: 428 Registered: September 2009 |
Senior Member |
|
|
On 01/05/2010 23.18, Mauro Condarelli wrote:
> On 01/05/2010 12.19, Tom Schindl wrote:
>> Am 01.05.10 11:08, schrieb Mauro Condarelli:
>>> On 01/05/2010 9.36, Tom Schindl wrote:
>>>> Am 30.04.10 18:17, schrieb Mauro Condarelli:
>>>>> On 30/04/2010 17.14, Thomas Kowatsch wrote:
>>>>>> Hi Mauro.
>>>>>> Best thing you have a look at Tom Schindel's EMF Databinding Blog.
>>>>>> http://tomsondev.bestsolution.at/2009/06/15/galileo-emf-data binding-part-4
>>>>>>
>>>>>>
>>>>>> He is also discussing how to setup master detail bindings.
>>>>>> HTH
>>>>>> --Thomas
>>>>>
>>>>> Thanks for the hint, Thomas.
>>>>>
>>>>> I am aware of that.
>>>>> Actually it is my main source of information.
>>>>>
>>>>
>>>> Right but I also think that in case of Databinding and the description
>>>> of the usecases it's probably impossible to get this into Javadoc,
>>>> that's why I wrote the Databinding Blog Series (BTW every part of it has
>>>> been already 4.000 hits == 20.000 hits in total :-).
>>>>
>>>> Probably time to write a book about Eclipse-Databinding :-)
>>>
>>> If You do in a reasonable timeframe (before I discover the last secret
>>> of Databinding) You have already sold at least my copy ;)
>>>
>>> ... but I don't really understand: You can write whatever You want in
>>> Javadoc, including, but not limited to: "The Lord of the Rings" :p (see:
>>> http://java.sun.com/j2se/javadoc/writingdoccomments/ "Writing
>>> Programming Guide Documentation"). I use extensively this feature at
>>> work to document libraries I write (I actually use Doxygen because I
>>> program mainly in C/C++). Hint. Hint. :) ;) :)
>>
>> Yes but what you really need is example code to understand how all this
>> things work together.
> Agreed.
> What I sourly miss is a cookbook-style book on RCP development.
> There are a lot of ways to do similar things and I'm lost.
> I hope to come to a grip sooner or later.
>
>>
>>>
>>>>
>>>>> The Javadoc pages are somewhat terse.
>>>>>
>>>>> I think I managed to understand what's wrong, but I have no idea about
>>>>> hos to make it right.
>>>>>
>>>>> In Tom's Example he has:
>>>>>
>>>>> // 2. Use case - observe the nested list
>>>>> // The list of all subprojects of the projects parent
>>>>> public IObservableList uc2(Project p) {
>>>>> IEMFListProperty prop = EMFProperties.list(
>>>>> FeaturePath.formList(
>>>>> ProjectPackage.Literals.PROJECT__PROJECT,
>>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS
>>>>> )
>>>>> );
>>>>> return prop.observe(p);
>>>>> }
>>>>>
>>>>> where ProjectPackage.Literals.PROJECT__PROJECT is a single value, while
>>>>> ProjectPackage.Literals.PROJECT__SUBPROJECTS represents a list. i.e.: he
>>>>> is dereferencing a project and using that to find a list of subprojects.
>>>>>
>>>>> I have the reverse: I have a list of Actors and for *each* of those I
>>>>> need to retrieve a single attribute (the Name).
>>>>>
>>>>
>>>> This is not supported if I get your request right. I'm not sure what
>>>> you'd expect to use the actors name for. Can you show us the code you
>>>> are using? If you want to observe the all actors names what you are
>>>> searching for is an IObservableMap.
>>>
>>> Here it comes!
>>> Problematic binding is:
>>>
>>> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
>>> List lstActors = listViewer.getList();
>>> ctx.bindList(
>>> list.observe(lstActors),
>>> EMFProperties.list(
>>> FeaturePath.fromList(
>>> WorldPackage.Literals.SCENE__ACTOR,
>>> WorldPackage.Literals.ACTOR__NAME
>>> )
>>> ).observeDetail(observableScene)
>>> );
>>>
>>
>>
>> IListProperty lp =
>> EMFProperties.value(WorldPackage.Literals.SCENE__ACTOR);
>>
>> IValueProperty p =
>> EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
>>
>> ObservableListContentProvider cp = new ObservableListContentProvider();
>>
>> TableViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
>> listViewer.setContentProvider(cp);
>> listViewer.setLabelProvider(new
>> ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts()))
>> );
>> listViewer.setInput(lp.observeDetail(observableScene));
>>
> I modified Your code as follows (for obvious errors):
>
> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> ...
> IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
> IValueProperty p = EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
> ObservableListContentProvider cp = new ObservableListContentProvider();
> listViewer.setContentProvider(cp);
> listViewer.setLabelProvider(new ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts())));
> listViewer.setInput(lp.observeDetail(observableScene));
>
> this somewhat works, but doesn't always update well when I change the selection in my Master.
Answering to myself (again):
the following works
IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
IValueProperty p = EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
ObservableListContentProvider cp = new ObservableListContentProvider();
listViewer.setContentProvider(cp);
listViewer.setLabelProvider(new ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts())));
listViewer.setInput(lp.observeDetail(observableScene));
if and only if observableScene always contains a Scene.
This means I cannot directly observe the variable provided by the Master,
but I have to use a local one updated in selectionChanged().
My other bindings work regardless.
I tried to modify the above copying from http://tomsondev.bestsolution.at/2009/06/27/galileo-emf-data binding-part-5/,
but my code below doesn't work (no error, but no entries in the list):
ObservableListContentProvider cp = new ObservableListContentProvider();
IObservableMap am = EMFProperties.value(/*editingDomain,*/
FeaturePath.fromList(
WorldPackage.Literals.SCENE__ACTOR,
WorldPackage.Literals.ACTOR__NAME
)
).observeDetail(cp.getKnownElements());
listViewer.setLabelProvider(new ObservableMapLabelProvider(am));
IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
listViewer.setContentProvider(cp);
listViewer.setInput(lp.observeDetail(observableScene));
It is clear to me I really do not understand Databinding.
In an attempt to fill my knowledge gap I just bought "Eclipse Rich Client Platform: Designing, Coding,
and Packaging Java Applications, Second Edition" and I'm now studying it.
Can someone suggest other fonts of overall description?
TiA
Mauro
>
> My Master/Detail is as follows:
>
> -- I have a Master page:
>
> public class WorldMasterBlock extends MasterDetailsBlock {
> ...
> private IObservableValue treeObs = null;
> ...
> @Override
> protected void createMasterPart(final IManagedForm managedForm,
> Composite parent) {
> ...
> tree = toolkit.createTree(composite_2, SWT.BORDER);
> tViewer = new TreeViewer(tree);
> ...
> treeObs = ViewerProperties.singleSelection().observe(tViewer);
> ...
> }
> @Override
> protected void registerPages(DetailsPart part) {
> ...
> part.registerPage(SceneImpl.class, new SceneDetailsPage2(treeObs));
> ...
> }
>
> -- and a Details page:
>
> public class SceneDetailsPage2 implements IDetailsPage {
> private IObservableValue observableScene = null;
> ...
> public SceneDetailsPage2(IObservableValue observableScene) {
> this.observableScene = observableScene;
> }
> ...
> public void createContents(Composite parent) {
> FormToolkit toolkit = managedForm.getToolkit();
> ...
> ListViewer listViewer = new ListViewer(composite_1, SWT.BORDER);
> List lstActors = listViewer.getList();
> lstActors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 2, 1));
> ...
> EMFDataBindingContext ctx = new EMFDataBindingContext();
> ...
> IListProperty lp = EMFProperties.list(WorldPackage.Literals.SCENE__ACTOR);
> IValueProperty p = EMFProperties.value(WorldPackage.Literals.ACTOR__NAME);
> ObservableListContentProvider cp = new ObservableListContentProvider();
> listViewer.setContentProvider(cp);
> listViewer.setLabelProvider(new ObservableMapLabelProvider(p.observeDetail(cp.getKnownElemen ts())));
> listViewer.setInput(lp.observeDetail(observableScene));
> }
> ...
> public void selectionChanged(IFormPart part, ISelection selection) {
> IStructuredSelection structuredSelection = (IStructuredSelection) selection;
> if (structuredSelection.size() == 1) {
> Scene s = (Scene) structuredSelection.getFirstElement();
> try {
> Object o = observableScene.getValue(); //<-- this is SceneDetailsPage2.java:405
> if (o instanceof Scene) {
> Scene z = (Scene) o;
> System.out.println("structuredSelection(" + s.getTitle() + "); observebleScene(" + z.getTitle() + ")");
> } else {
> System.out.println("structuredSelection(" + s.getTitle() + "); observebleScene(" + o.getClass() + ")");
> }
> } catch (Exception e) {
> System.out.println("structuredSelection(" + s.getTitle() + "); exception(" + e.getMessage() + ")");
> }
> ...
> }
> }
>
>
> I am using selectionChanged() because I need to setup a few sliders I didn't figure to how to bind to values. Otherwise it shouldn't be necessary because observableScene should already track the selection in Master.
>
> when it starts misbehaving I consistently get the following error:
>
> structuredSelection(Il Risveglio); exception(null)
> java.lang.NullPointerException
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eSettingDelegate (BasicEObjectImpl.java:1542)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1029)
> at it.condarelli.writer.model.world.impl.IBaseImpl.eGet(IBaseIm pl.java:597)
> at it.condarelli.writer.model.world.impl.ChapterImpl.eGet(Chapt erImpl.java:262)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1013)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1005)
> at org.eclipse.emf.ecore.impl.BasicEObjectImpl.eGet(BasicEObjec tImpl.java:1000)
> 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.toArray(SimplePropertyObservableList.ja va:161)
> at java.util.ArrayList.<init>(Unknown Source)
> at org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$3.run(DetailObservableList.java:99)
> at org.eclipse.core.databinding.observable.ObservableTracker.ru nAndIgnore(ObservableTracker.java:169)
> at org.eclipse.core.internal.databinding.observable.masterdetai l.DetailObservableList$2.handleValueChange(DetailObservableL ist.java:97)
> at org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
> at org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
> at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.fireValueChange(DecoratingObservableValue.java:5 5)
> at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.handleValueChange(DecoratingObservableValue.java :93)
> at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue$1.handleValueChange(DecoratingObservableValue.ja va:67)
> at org.eclipse.core.databinding.observable.value.ValueChangeEve nt.dispatch(ValueChangeEvent.java:62)
> at org.eclipse.core.databinding.observable.ChangeManager.fireEv ent(ChangeManager.java:119)
> at org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.fireValueChange(AbstractObservableValue.java:71)
> at org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.notifyIfChanged(SimplePropertyObserva bleValue.java:120)
> at org.eclipse.core.internal.databinding.property.value.SimpleP ropertyObservableValue.doGetValue(SimplePropertyObservableVa lue.java:97)
> at org.eclipse.core.databinding.observable.value.AbstractObserv ableValue.getValue(AbstractObservableValue.java:76)
> at org.eclipse.core.databinding.observable.value.DecoratingObse rvableValue.getValue(DecoratingObservableValue.java:98)
> at it.condarelli.writer.editors.SceneDetailsPage2.selectionChan ged(SceneDetailsPage2.java:405)
> at org.eclipse.ui.forms.DetailsPart$1.run(DetailsPart.java:274)
> at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator .java:70)
> at org.eclipse.ui.forms.DetailsPart.showPage(DetailsPart.java:2 61)
> at org.eclipse.ui.forms.DetailsPart.update(DetailsPart.java:234 )
> at org.eclipse.ui.forms.DetailsPart.selectionChanged(DetailsPar t.java:219)
> at org.eclipse.ui.forms.ManagedForm.fireSelectionChanged(Manage dForm.java:148)
> at it.condarelli.writer.editors.WorldMasterBlock$2.selectionCha nged(WorldMasterBlock.java:240)
> ...
>
> Can You divine what's going wrong?
>
>>
>> If you want a better LabelProvider I'd suggest you take a look at the
>> class is wrote for my blog example named GenericMapCellLabelProvider.
> I will, even if a plain list is ok.
>
>>
>>> where, in the model I have:
>>>
>>> public interface Scene extends IBase {
>>> ...
>>> /**
>>> * @model lower="1" many="true"
>>> */
>>> EList<Actor> getActor();
>>> ...
>>> }
>>> Actors are contained elsewhere; here is just a list of references.
>>>
>>> public interface Actor extends EObject {
>>>
>>> /**
>>> * @model default="Nemo" required="true"
>>> */
>>> String getName();
>>> ...
>>> }
>>>
>>> What I need is to:
>>> - display in the ListViewer the names of the Actors in the Scene EList.
>>
>> See above how this should look like
>
> I'm still missing something :(
>
>>
>>> - be able to get a pointer to the Actor when I select it's Name (to edit
>>> it).
>>
>> With a Table you can use EditingSupport
>>
>>> - remove or add to the EList via drag&drop from the full list of Actors.
>>>
>>
>> See above modifying the EList updates your viewers content.
>>
>> Tom
>
> Thanks
> Mauro
|
|
|
Goto Forum:
Current Time: Fri Apr 19 07:55:07 GMT 2024
Powered by FUDForum. Page generated in 0.02936 seconds
|