I am still struggling with EMF Bindings.
I have a model I want to edit using Forms.
Up to now I have found no way to have SWT Designer generate the things as I need them.
It may well be I haven't found the right incantation.
This is an example of what I need:
- Code: Select all
public class SceneEditPage extends FormPage implements ISelectionListener {
private Scene scene = null;
private IObservableValue observableScene = null;
...
@Override
protected void createFormContent(IManagedForm managedForm) {
//ensure we have the selected thing
observableScene = new WritableValue(scene, Scene.class);
getSite().getPage().addSelectionListener(this);
selectionChanged(getSite().getPage().getActiveEditor(), getSite().getPage().getSelection());
FormToolkit toolkit = managedForm.getToolkit();
...
comboViewer = new ComboViewer(composite, SWT.BORDER);
Combo combo = comboViewer.getCombo();
combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
managedForm.getToolkit().paintBordersFor(combo);
comboViewer.setContentProvider(new ArrayContentProvider()); <<<added manually
comboViewer.setLabelProvider(new LabelProvider()); <<<added manually
comboViewer.setInput(ScStatus.values()); <<<added manually
txtContent = managedForm.getToolkit().createText(managedForm.getForm().getBody(), "New Text", SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
txtContent.setText("Content");
txtContent.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
m_bindingContext = initDataBindings();
}
...
protected DataBindingContext initDataBindings() {
DataBindingContext bindingContext = new DataBindingContext();
//
IObservableValue txtContentObserveTextObserveWidget = SWTObservables.observeText(txtContent, SWT.Modify);
IObservableValue sceneContentObserveValue = EMFObservables.observeDetailValue(Realm.getDefault(), observableScene, Literals.SCENE__CONTENT); <<<changed manually
bindingContext.bindValue(txtContentObserveTextObserveWidget, sceneContentObserveValue, null, null);
//
IObservableValue comboViewerObserveSingleSelection = ViewersObservables.observeDelayedValue(1000, ViewersObservables.observeSingleSelection(comboViewer));
IObservableValue sceneStatusObserveValue = EMFObservables.observeDetailValue(Realm.getDefault(), observableScene, Literals.SCENE__STATUS); <<<changed manually
bindingContext.bindValue(comboViewerObserveSingleSelection, sceneStatusObserveValue, null, null);
//
return bindingContext;
}
...
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
if (structuredSelection.size()==1) {
Scene s = (Scene)structuredSelection.getFirstElement();
if (!s.equals(scene)) {
scene = s;
if (observableScene != null)
observableScene.setValue(s);
//update();
}
}
}
The lines marked <<<added/changed manually are the ones I couldn't guess how to generate from SWT Designer.
SWT Designer, OTOH, seems perfectly able to parse the modified code, so I guess there should be some way to have it generated, isn't it so?
If useful I can send the complete project.
Regards
Mauro