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