Question

i'm trying to update a Model for GEF and have the changes shown in the view i've created. Currently no change I make is being reflected in the view, i'm using the following approach to update the model and am wondering if its the right approach to take:

Display.getDefault().asyncExec(new Runnable() {
   public void run() {
            String viewId = "beat.views.BeatView";

            IWorkbench workbench = PlatformUI.getWorkbench();

            IWorkbenchWindow mainWindow = workbench
                    .getActiveWorkbenchWindow();

            try {

                BeatView view = (BeatView) mainWindow.getActivePage()
                        .showView(viewId);

                BeatEditPart beatEditPart = (BeatEditPart)view.getGraphicalViewer().getContents();

                BeatModel beatModel = (BeatModel)beatEditPart.getModel();
                beatModel.setObjects(model);
            } catch (PartInitException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
Was it helpful?

Solution

Is your EditPart listening to model changes?

1 - You need to register as a listener to your model. We use EMF's notify mechanism.

public void activate() {
    if (!isActive())
        ((EObject) getModel()).eAdapters().add(this);
    super.activate();
}

public void deactivate() {
    if (isActive())
        ((EObject) getModel()).eAdapters().remove(this);
    super.deactivate();
}

2 - You need to act when something changes.

public void notifyChanged(Notification notification) {
...
} 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top