Master/details+databinding+EMF problem

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

Master/details+databinding+EMF problem

Postby Mauro » Thu Feb 11, 2010 4:57 pm

Hi,
I have a master/details page.
I managed to make it work as I need.

Current problem is with Databinding.
I have my model in EMF.
I do provide and update the current reference from the Master Selection to the Details SelectionChanged.

Problem is the Bindings page generates only things like EMFObservables.observeValue() that are suitable for static references, while the master/detail dynamic nature would need something like EMFObservables.observeDetailValue() working not on plain references, but on IObservable instances.

I have a working application obtained by hand-modification of the code. Unfortunately the hand-modified code does not parse anymore.
I have not found the right incantation to have SWT Designer produce the right code.
Can You confirm Bindings do not work in this scenario?
Otherwise can You describe how to convince the Binding generator to behave? :)
Should I send a dump of the parsing errors?

This is the code generated:
Code: Select all
    private Chapter chapter; // this is an EMF-managed Interface

    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;
                update();
            }
        }
    }


    protected DataBindingContext initBindings() {
        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.getKnownElements(), 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;
    }

And this is what I really need (working code):
Code: Select all
    private IObservableValue chapter;

    /**
     * Create the details page.
     */
    public ChapterDetailsPage() {
        // Create the details page
        chapter = new WritableValue(null, Chapter.class);
    }


    public void selectionChanged(IFormPart part, ISelection selection) {
        IStructuredSelection structuredSelection = (IStructuredSelection) selection;
        if (structuredSelection.size()==1) {
            Chapter c = (Chapter)structuredSelection.getFirstElement();
            if (!c.equals(chapter.getValue())) {
                chapter.setValue(c);
                update();
            }
        }
    }

    protected DataBindingContext initDataBindings() {
        DataBindingContext bindingContext = new DataBindingContext();
        //
        IObservableValue txtTitleObserveTextObserveWidget = SWTObservables.observeText(txtTitle, SWT.Modify);
        IObservableValue bookTitleObserveValue = EMFObservables.observeDetailValue(Realm.getDefault(), chapter, Literals.CHAPTER__TITLE);
        bindingContext.bindValue(txtTitleObserveTextObserveWidget, bookTitleObserveValue, null, null);
        //
        IObservableValue txtDescObserveTextObserveWidget = SWTObservables.observeText(txtDesc, SWT.Modify);
        IObservableValue bookDescObserveValue = EMFObservables.observeDetailValue(Realm.getDefault(), chapter, Literals.CHAPTER__DESC);
        bindingContext.bindValue(txtDescObserveTextObserveWidget, bookDescObserveValue, null, null);
        //
        ObservableListContentProvider listContentProvider = new ObservableListContentProvider();
        tViewer.setContentProvider(listContentProvider);
        //
        IObservableMap[] observeMaps = EMFObservables.observeMaps(listContentProvider.getKnownElements(), new EStructuralFeature[]{Literals.SCENE__TITLE, Literals.CHAPTER__DESC});
        tViewer.setLabelProvider(new ObservableMapLabelProvider(observeMaps));
        //
        IObservableList bookChapterObserveList = EMFObservables.observeDetailList(Realm.getDefault(), chapter, Literals.CHAPTER__SCENE);
        tViewer.setInput(bookChapterObserveList);
        //
        return bindingContext;
    }

Best Regards
Mauro
Mauro
 
Posts: 7
Joined: Mon Feb 08, 2010 5:39 pm

Re: Master/details+databinding+EMF problem

Postby Eric Clayberg » Thu Feb 18, 2010 9:13 am

See the attached project and the screen shot below.

If a field is an observable object, we now add it to the EMF objects page.

WBComposite.png
WBComposite.png (169.07 KiB) Viewed 290 times
Attachments
WBtest.zip
(141.07 KiB) Downloaded 53 times
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to SWT Designer

Who is online

Users browsing this forum: Google [Bot] and 2 guests