简体   繁体   English

Eclipse e4 RCP 插件间访问服务

[英]Eclipse e4 RCP accessing services between plugins

I'm currently working on my first Eclipse e4 RCP app using Eclipse 4.2M6.我目前正在使用 Eclipse 4.2M6 开发我的第一个 Eclipse e4 RCP 应用程序。 I'm developing a main plugin which has the core code for my app and defines a number of services as extensions to allow other plugins/fragments to hook into the app to add new functionality.我正在开发一个主插件,它具有我的应用程序的核心代码,并将许多服务定义为扩展,以允许其他插件/片段挂接到应用程序以添加新功能。

My main service has methods which the other plugins should use to register new functionality, and to add programatically to the model of the main app.我的主要服务有其他插件应该使用的方法来注册新功能,并以编程方式添加到主应用程序的 model。 I'm however unsure how to get these plugins to lookup the service and register themselves when the plugin is started.但是,我不确定如何让这些插件在插件启动时查找服务并自行注册。

An example:一个例子:

My interface for my service in the main plugin:我在主插件中的服务界面:

public interface FeedManager {

    boolean registerFeed(Feed service);

    boolean unregisterFeed(Feed service);

    IObservableList getFeeds();
}

What I'm wanting in second plugin:我在第二个插件中想要什么:

public class TestFeed {

    ///this method could be in a constructor or @PostConstruct method instead
    @Inject
    public void init(FeedManager manager){    

        Feed feed = new Feed();
        feed.setName("Test feed");

        manager.registerFeed(feed);

    }

}

Eclipse E4 offers fragments and processors to support modularity. Eclipse E4 提供片段和处理器以支持模块化。

Lars Vogel provides an excellent tutorial for this: Lars Vogel 为此提供了一个很好的教程:

http://www.vogella.com/articles/Eclipse4Modularity/article.html http://www.vogella.com/articles/Eclipse4Modularity/article.html

+1 for @Frank for pointing the correct tutorial. +1 @Frank 指出正确的教程。 There, you need to create a processor in your second plugin.在那里,您需要在第二个插件中创建一个处理器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM