开发者

Where in an Eclipse plugin to I place an algorithm that utilises several views

I've got an Eclipse plugin that contains 4 views. A piece of programming functionality must sit 'above' these views, tying them together. I'll call it the 'master'

Can anybody advise on the best location for this functionality? Really, I want the 'master' to start once the application is open and the views have been initialised.

In my generated RCP application plugin I have an Activitor, a Client, a Perspective, an ApplicationActionBarAdvisor, and ApplicationWorkbenchAdvisor, and an ApplicationWorkbenchWindowAdvisor. None of these seem suitable for hosting the 'master'.

Edit: after a little further investigation I suspect the ApplicationWindowAdvisor holds my answer. It has a number of methods that may be overridden to jump into application lifecycle stages. The ones that appear to relate to this problem appear to be: postStartup, postWindowOpen, postWindowCreate

I'd appreciate any pointers on which method is called after all the views have been created/initialised.

Edit 2: more googling has exposed use of the org.eclipse.ui.startup extension point, as IStartup.earlyStartup()开发者_如何学C is also run after the Workbench was completely started.

cheers, Ian


Maybe you could define an OSGi service (see the tutorial by Lars Vogel for detailed howto: http://www.vogella.de/articles/OSGi/article.html).

This service could be initialized either declaratively, or by using your plug-in activator; then each view could connect to this service.

On the other hand, if you want to communicate between the views, you could simple use the workbench selection service - in this case, all views are operating somewhat independent of each other, without central control.

Edit Responding to the changes in the question: neither proposed methods have anything to do with the opening (or closing) of the views. The postStartup is executed after the application starts; postWindowOpen is executed after the window is opened; while postWindowCreate is opened after the window is created, but before its opened.

The earlyStartup() makes it possible to execute after the workbench was started, but it still does not makes sure whether the corresponding views are opened - views have a different life-cycle then windows.

Globally, you have to provide some common service that can be used by each of the views; this can registered at most points of the application lifecycle - you should choose the one that fits your need best.


I think you're mixing concepts. Algorithms don't work on views but on the models which the views show.

A view is nothing but a window which transforms bits in memory to something a user can find useful.

So what you really want is to separate the models in your views from the views themselves. That will also make testing much more simple. Have them publish events when they are change.

Your algorithm should subscribe to the events of all four models and do its work, putting the result in another model where the same or other views can pick it up.

In the views, also subscribe to the appropriate events which your models emit and update them accordingly.

This way, you can separate the model from the views. You won't get into trouble when the user rearranges views or closes them.


I think the best you can do is setup a Perspective with those views and lock them, so the user may not close them.

I do not remember exactly how you can do this, but I think setting the perspective as 'fixed' on the extension point declaration might do the trick.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜