Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » EMF+Databinding+Master/DetailsForms=LOST
EMF+Databinding+Master/DetailsForms=LOST [message #513995] Thu, 11 February 2010 23:33 Go to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
Sorry to disturb again and doubly sorry because I'm cross-posting, but
I'm not sure what's the right place for this.

I'm trying to build a custom editor for my model written using EMF.
I am using forms to be consistent with normal eclipse behavior.
After some experimentation I managed to have a structure I like and it
is somewhat working.
I have a multi-page editor, but that is unimportant because my problems
are on the first "overview" page.
This is a simple (?) Master/Details page holding a TreeViewer on the
master block and a few DetailsPage's

Problem is in the DetailsPage's.

I have the following:

public class ChapterDetailsPage implements IDetailsPage {
private Chapter chapter; //<< this is the EMF Interface to display
....
public void createContents(Composite parent) {
//testComposite = new testComposite(parent, SWT.NONE);
//parent.setLayout(new FillLayout());
FormToolkit toolkit = managedForm.getToolkit();
parent.setLayout(new FillLayout());
//
Section sctnBook = toolkit.createSection(parent,
ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
sctnBook.setText("Chapter");

.... create the detail form this seems ok ...

if (chapter != null) // never entered: at creation time chapter
== null
m_bindingContext = initDataBindings();
}

public void selectionChanged(IFormPart part, ISelection selection) {
IStructuredSelection structuredSelection =
(IStructuredSelection) selection;
if (structuredSelection.size()==1) {
Chapter c = (Chapter)structuredSelection.getFirstElement();
if (!c.equals(chapter)) {
chapter = c;
if (m_bindingContext == null) << HERE IS PROBLEM (see
below)
m_bindingContext = initDataBindings();
update();
}
}
}

// here I do my Databindings; are they OK?
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue txtTitleObserveTextObserveWidget =
SWTObservables.observeText(txtTitle, SWT.Modify);
IObservableValue bookTitleObserveValue =
EMFObservables.observeValue(chapter, Literals.CHAPTER__TITLE);
bindingContext.bindValue(txtTitleObserveTextObserveWidget,
bookTitleObserveValue, null, null);
//
IObservableValue txtDescObserveTextObserveWidget =
SWTObservables.observeText(txtDesc, SWT.Modify);
IObservableValue bookDescObserveValue =
EMFObservables.observeValue(chapter, Literals.CHAPTER__DESC);
bindingContext.bindValue(txtDescObserveTextObserveWidget,
bookDescObserveValue, null, null);
//
ObservableListContentProvider listContentProvider = new
ObservableListContentProvider();
tViewer.setContentProvider(listContentProvider);
//
IObservableMap[] observeMaps =
EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
EStructuralFeature[]{Literals.SCENE__TITLE, Literals.CHAPTER__DESC});
tViewer.setLabelProvider(new
ObservableMapLabelProvider(observeMaps));
//
IObservableList bookChapterObserveList =
EMFObservables.observeList(Realm.getDefault(), chapter,
Literals.CHAPTER__SCENE);
tViewer.setInput(bookChapterObserveList);
//
return bindingContext;
}
}

Problem is this way I do not track the changes when chapter changes.
This is because the bindings are done only once and thus the form always
displays the same content.

The obvious workaround: reinitialize the bindings each time chapter is
updated (remove the problematic "if (m_bindingContext == null)" doesn't
work either because I get exceptions:

org.eclipse.core.runtime.AssertionFailedException: assertion failed:
Getter called on disposed observable
org.eclipse.emf.databinding.EObjectObservableMap@1655fb9

org.eclipse.core.runtime.AssertionFailedException: assertion failed:
Getter called on disposed observable
org.eclipse.emf.databinding.EObjectObservableMap@1655fb9

So I suspect I have done something seriously wrong with databinding.
Unfortunately I was not able to find a suitable example code.

I have found Master/Details and I have found EMF separately.
I did not find Master/Details and found EMF together.

Any suggestion?
Thanks a lot

Mauro
Re: EMF+Databinding+Master/DetailsForms=LOST [message #514026 is a reply to message #513995] Fri, 12 February 2010 08:50 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5331
Registered: July 2009
Senior Member
Hi,

My tutorial [1] on EMF-Databinding shows Master-Detail in action.

Am I correct in assuming that the field chapter is changing all the time?

I don't see you createing a detail-observables but only standard
observables.

If I get your code right.

Then you need change:

a) Instance field to:
WritableList chapter = new WritableList();

b) Create your bindings:
EMFObservables.observeDetail(chapter,....)

Please also note that you are using the old EMFObservables-Factory
whereas the newer EMFProperties should be preferred.

Tom

[1] http://tomsondev.bestsolution.at/2009/06/06/galileo-improved -emf-databinding-support/


Am 12.02.10 00:33, schrieb Mauro Condarelli:
> Sorry to disturb again and doubly sorry because I'm cross-posting, but
> I'm not sure what's the right place for this.
>
> I'm trying to build a custom editor for my model written using EMF.
> I am using forms to be consistent with normal eclipse behavior.
> After some experimentation I managed to have a structure I like and it
> is somewhat working.
> I have a multi-page editor, but that is unimportant because my problems
> are on the first "overview" page.
> This is a simple (?) Master/Details page holding a TreeViewer on the
> master block and a few DetailsPage's
>
> Problem is in the DetailsPage's.
>
> I have the following:
>
> public class ChapterDetailsPage implements IDetailsPage {
> private Chapter chapter; //<< this is the EMF Interface to display
> ...
> public void createContents(Composite parent) {
> //testComposite = new testComposite(parent, SWT.NONE);
> //parent.setLayout(new FillLayout());
> FormToolkit toolkit = managedForm.getToolkit();
> parent.setLayout(new FillLayout());
> //
> Section sctnBook = toolkit.createSection(parent,
> ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
> sctnBook.setText("Chapter");
>
> ... create the detail form this seems ok ...
>
> if (chapter != null) // never entered: at creation time chapter
> == null
> m_bindingContext = initDataBindings();
> }
>
> public void selectionChanged(IFormPart part, ISelection selection) {
> IStructuredSelection structuredSelection =
> (IStructuredSelection) selection;
> if (structuredSelection.size()==1) {
> Chapter c = (Chapter)structuredSelection.getFirstElement();
> if (!c.equals(chapter)) {
> chapter = c;
> if (m_bindingContext == null) << HERE IS PROBLEM (see
> below)
> m_bindingContext = initDataBindings();
> update();
> }
> }
> }
>
> // here I do my Databindings; are they OK?
> protected DataBindingContext initDataBindings() {
> DataBindingContext bindingContext = new DataBindingContext();
> //
> IObservableValue txtTitleObserveTextObserveWidget =
> SWTObservables.observeText(txtTitle, SWT.Modify);
> IObservableValue bookTitleObserveValue =
> EMFObservables.observeValue(chapter, Literals.CHAPTER__TITLE);
> bindingContext.bindValue(txtTitleObserveTextObserveWidget,
> bookTitleObserveValue, null, null);
> //
> IObservableValue txtDescObserveTextObserveWidget =
> SWTObservables.observeText(txtDesc, SWT.Modify);
> IObservableValue bookDescObserveValue =
> EMFObservables.observeValue(chapter, Literals.CHAPTER__DESC);
> bindingContext.bindValue(txtDescObserveTextObserveWidget,
> bookDescObserveValue, null, null);
> //
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
> tViewer.setContentProvider(listContentProvider);
> //
> IObservableMap[] observeMaps =
> EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
> EStructuralFeature[]{Literals.SCENE__TITLE, Literals.CHAPTER__DESC});
> tViewer.setLabelProvider(new
> ObservableMapLabelProvider(observeMaps));
> //
> IObservableList bookChapterObserveList =
> EMFObservables.observeList(Realm.getDefault(), chapter,
> Literals.CHAPTER__SCENE);
> tViewer.setInput(bookChapterObserveList);
> //
> return bindingContext;
> }
> }
>
> Problem is this way I do not track the changes when chapter changes.
> This is because the bindings are done only once and thus the form always
> displays the same content.
>
> The obvious workaround: reinitialize the bindings each time chapter is
> updated (remove the problematic "if (m_bindingContext == null)" doesn't
> work either because I get exceptions:
>
> org.eclipse.core.runtime.AssertionFailedException: assertion failed:
> Getter called on disposed observable
> org.eclipse.emf.databinding.EObjectObservableMap@1655fb9
>
> org.eclipse.core.runtime.AssertionFailedException: assertion failed:
> Getter called on disposed observable
> org.eclipse.emf.databinding.EObjectObservableMap@1655fb9
>
> So I suspect I have done something seriously wrong with databinding.
> Unfortunately I was not able to find a suitable example code.
>
> I have found Master/Details and I have found EMF separately.
> I did not find Master/Details and found EMF together.
>
> Any suggestion?
> Thanks a lot
>
> Mauro
Re: EMF+Databinding+Master/DetailsForms=LOST [message #514027 is a reply to message #513995] Fri, 12 February 2010 09:04 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro Condarelli
Messages: 417
Registered: September 2009
Senior Member
Answering to myself :)
I found the following is somewhat working.
see below.

Mauro Condarelli wrote:
> Sorry to disturb again and doubly sorry because I'm cross-posting, but
> I'm not sure what's the right place for this.
>
> I'm trying to build a custom editor for my model written using EMF.
> I am using forms to be consistent with normal eclipse behavior.
> After some experimentation I managed to have a structure I like and it
> is somewhat working.
> I have a multi-page editor, but that is unimportant because my problems
> are on the first "overview" page.
> This is a simple (?) Master/Details page holding a TreeViewer on the
> master block and a few DetailsPage's
>
> Problem is in the DetailsPage's.
>
> I have the following:
>
> public class ChapterDetailsPage implements IDetailsPage {
> private Chapter chapter; //<< this is the EMF Interface to display
private IObservableValue observableChapter = new
WritableValue(null, Chapter.class);

> ....
> public void createContents(Composite parent) {
> //testComposite = new testComposite(parent, SWT.NONE);
> //parent.setLayout(new FillLayout());
> FormToolkit toolkit = managedForm.getToolkit();
> parent.setLayout(new FillLayout());
> //
> Section sctnBook = toolkit.createSection(parent,
> ExpandableComposite.EXPANDED | ExpandableComposite.TITLE_BAR);
> sctnBook.setText("Chapter");
>
> .... create the detail form this seems ok ...
>
//delete > if (chapter != null) // never entered: at creation
time chapter
> == null
> m_bindingContext = initDataBindings();
> }
>
> public void selectionChanged(IFormPart part, ISelection selection) {
> IStructuredSelection structuredSelection =
> (IStructuredSelection) selection;
> if (structuredSelection.size()==1) {
> Chapter c = (Chapter)structuredSelection.getFirstElement();
> if (!c.equals(chapter)) {
> chapter = c;
//delete > if (m_bindingContext == null) << HERE IS
PROBLEM (see
//delete > below)
//delete > m_bindingContext = initDataBindings();
observableChapter.setValue(c);

> update();
> }
> }
> }
>
> // here I do my Databindings; are they OK?
> protected DataBindingContext initDataBindings() {
> DataBindingContext bindingContext = new DataBindingContext();
> //
> IObservableValue txtTitleObserveTextObserveWidget =
> SWTObservables.observeText(txtTitle, SWT.Modify);
//change > IObservableValue bookTitleObserveValue =
//change > EMFObservables.observeValue(chapter, Literals.CHAPTER__TITLE);
> bindingContext.bindValue(txtTitleObserveTextObserveWidget,
> bookTitleObserveValue, null, null);
IObservableValue bookTitleObserveValue =
EMFObservables.observeDetailValue(Realm.getDefault(), observableChapter,
Literals.CHAPTER__TITLE);

> //
> IObservableValue txtDescObserveTextObserveWidget =
> SWTObservables.observeText(txtDesc, SWT.Modify);
//change > IObservableValue bookDescObserveValue =
//change > EMFObservables.observeValue(chapter, Literals.CHAPTER__DESC);
IObservableValue bookDescObserveValue =
EMFObservables.observeDetailValue(Realm.getDefault(), observableChapter,
Literals.CHAPTER__DESC);

> bindingContext.bindValue(txtDescObserveTextObserveWidget,
> bookDescObserveValue, null, null);
> //
> ObservableListContentProvider listContentProvider = new
> ObservableListContentProvider();
> tViewer.setContentProvider(listContentProvider);
> //
> IObservableMap[] observeMaps =
//change >
EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
//change > EStructuralFeature[]{Literals.SCENE__TITLE,
Literals.CHAPTER__DESC});
IObservableMap[] observeMaps =
EMFObservables.observeMaps(listContentProvider.getKnownEleme nts(), new
EStructuralFeature[]{Literals.SCENE__TITLE, Literals.SCENE__DESC});

> tViewer.setLabelProvider(new
> ObservableMapLabelProvider(observeMaps));
> //
> IObservableList bookChapterObserveList =
//change > EMFObservables.observeList(Realm.getDefault(), chapter,
//change > Literals.CHAPTER__SCENE);
IObservableList bookChapterObserveList =
EMFObservables.observeDetailList(Realm.getDefault(), observableChapter,
Literals.CHAPTER__SCENE);

> tViewer.setInput(bookChapterObserveList);
> //
> return bindingContext;
> }
> }
>
> Problem is this way I do not track the changes when chapter changes.
> This is because the bindings are done only once and thus the form always
> displays the same content.
>
> The obvious workaround: reinitialize the bindings each time chapter is
> updated (remove the problematic "if (m_bindingContext == null)" doesn't
> work either because I get exceptions:
>
> org.eclipse.core.runtime.AssertionFailedException: assertion failed:
> Getter called on disposed observable
> org.eclipse.emf.databinding.EObjectObservableMap@1655fb9
>
> org.eclipse.core.runtime.AssertionFailedException: assertion failed:
> Getter called on disposed observable
> org.eclipse.emf.databinding.EObjectObservableMap@1655fb9
>
> So I suspect I have done something seriously wrong with databinding.
> Unfortunately I was not able to find a suitable example code.
>
> I have found Master/Details and I have found EMF separately.
> I did not find Master/Details and found EMF together.
>
> Any suggestion?
> Thanks a lot
>
> Mauro


With this update (somewhat working) code I have two major problems:
1) The TableViewer (tViewer) always displays just one column: the first
one defined in observeMaps. The others are silently ignored. I'm missing
something, but I can't divine what.
2) I don't really know what I'm doing. I'm blindly coping pieces of code
found googling around, but I miss a somewhat general picture. All usage
of EMFObservables is rather obscure to me.

Can someone shed light around, pretty please?

Thanks in Advance
Mauro
Re: EMF+Databinding+Master/DetailsForms=LOST [message #514031 is a reply to message #514027] Fri, 12 February 2010 09:20 Go to previous message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5331
Registered: July 2009
Senior Member
[...]

>
> With this update (somewhat working) code I have two major problems:
> 1) The TableViewer (tViewer) always displays just one column: the first
> one defined in observeMaps. The others are silently ignored. I'm missing
> something, but I can't divine what.

You are not showing us how you create the table viewer:
a) You need to create your Table/TableViewer-Columns
b) You need to set a LabelProvider to each of them

See my tutorial code in CVS.

> 2) I don't really know what I'm doing. I'm blindly coping pieces of code
> found googling around, but I miss a somewhat general picture. All usage
> of EMFObservables is rather obscure to me.

What you are doing is correct Master-Detail binding. Did you go through
my EMF-Databinding Tutorial and the source code it is coming with?

Tom
Previous Topic:[Databinding] what TreeView support is ao display my vailable from EMF?
Next Topic:No checkbox for all nodes in a CheckboxTreeViewer ?
Goto Forum:
  


Current Time: Tue Sep 23 02:29:09 GMT 2014

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

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