开发者

Eclipse Modeling Framework: Linking an alternative view to the model

I have an ECore model I exploit to automatically generate the model source and JFace edit package. I am trying to develop an alternative view for contents of that model, basically a graph view based on JFreeChart. I have managed to create a JFreeChart based view plugin. Now I need to link the view with the model. How can I do that? I would like to edit the model with the TreeBased editor and see the effects of such editing in the graph view. Is that possi开发者_C百科ble?

thank you


If you open your Graphbased-View ask for the IFile of the current opened editor. After you got the file, you can load the model (see the generated Editor how to load the Model from the underlying resource) attach a IResourceChangeListener to get a notification, if the underlying IFile of your EMF Model changed. After a notification you can reload the model from your file and show the model in your view.

In addition you have to register a PartListener to get a notification if the user brings another emf-editor to top or he closes the editor (you also have to unload (on close) or refresh (another editor with your emf-model was brought to top).


Yes, it is, as the generated EMF code provides a notification layer: use EObject.eAdapters to add a new adapter, that is notified if the model is changed.

    object.eAdapters().add(new Adapter() {

        public void setTarget(Notifier newTarget) {
            // TODO Auto-generated method stub

        }

        public void notifyChanged(Notification notification) {
            // TODO Auto-generated method stub

        }

        public boolean isAdapterForType(Object type) {
            // TODO Auto-generated method stub
            return false;
        }

        public Notifier getTarget() {
            // TODO Auto-generated method stub
            return null;
        }
    });


Ok I have managed to do that following the Zoltán suggestions. Anyway I admit I would have preferred a more structured answer, and that is why I am answering my own question with a brief summary of the solution.

basically the idea is that a view plugin implements the ViewPart interface. Because of this it can actually invoke the following methods

getSite().getWorkbenchWindow().getSelectionService()

in order to get the workbench selection service. You can therefore invoke the SelectionService method

addSelectionListener(ISelectionListener listener)

passing as parameter your own ISelectionListener which can be the same ViewPart you are implementing. You just have to implement the ISelectionListener interface and thus provide an implementation of the selectionChanged method

public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜