EMF Bindings (again)

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

EMF Bindings (again)

Postby Mauro » Tue Feb 16, 2010 5:25 am

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;


    protected void createFormContent(IManagedForm managedForm) {
        //ensure we have the selected thing
        observableScene = new WritableValue(scene, Scene.class);
        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));
        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.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;


    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)

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.

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

Re: EMF Bindings (again)

Postby Eric Clayberg » Thu Feb 18, 2010 9:15 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.


Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
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