Pregunta

Estoy intentando actualizar un Modelo para GEF y mostrar los cambios en la vista que he creado. Actualmente, ningún cambio que realizo se refleja en la vista, estoy usando el siguiente enfoque para actualizar el modelo y me pregunto si es el enfoque correcto:

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();
            }
        }
    });
¿Fue útil?

Solución

¿Su EditPart está escuchando cambios en el modelo?

1 - Debe registrarse como oyente para su modelo. Utilizamos el mecanismo de notificación de EMF.

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 - Necesitas actuar cuando algo cambia.

public void notifyChanged(Notification notification) {
...
} 
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top