简体   繁体   English

Eclipse e4:访问PostContextCreate中的属性

[英]Eclipse e4: Accessing properties in PostContextCreate

I am using the PostContextCreate part of the life cycle in an e4 RCP application to create the back-end "business logic" part of my application. 我在e4 RCP应用程序中使用生命周期的PostContextCreate部分来创建应用程序的后端“业务逻辑”部分。 I then inject it into the context using an IEclipseContext . 然后我使用IEclipseContext将它注入上下文。 I now have a requirement to persist some business logic configuration options between executions of my application. 我现在需要在应用程序的执行之间保留一些业务逻辑配置选项。 I have some questions: 我有一些疑问:

  1. It looks like properties (eg accessible from MContext ) would be really useful here, a straightforward Map<String,String> sounds ideal for my simple requirements, but how can I get them in PostContextCreate ? 看起来属性(例如可以从MContext访问)在这里真的很有用,一个简单的Map<String,String>听起来很适合我的简单要求,但是如何在PostContextCreate获取它们呢?
  2. Will my properties persist if my application is being run with clearPersistedState set to true ? 如果我的应用程序在clearPersistedState设置为true情况下运行,我的属性是否会持续存在? (I'm guessing not). (我猜不是)。
  3. If I turn clearPersistedState off then will it try and persist the other stuff that I injected into the context? 如果我关闭clearPersistedState ,那么它会尝试并保留我注入上下文的其他内容吗?

Or am I going about this all wrong? 或者我这样做是错的? Any suggestions would be welcome. 欢迎大家提出意见。 I may just give up and read/write my own properties file. 我可能只是放弃并读/写我自己的属性文件。

I think the Map returned by MApplicationElement.getPersistedState() is intended to be used for persistent data. 我认为MApplicationElement.getPersistedState()返回的Map旨在用于持久数据。 This will be cleared by -clearPersistedState. 这将由-clearPersistedState清除。

The PostContextCreate method of the life cycle is run quite early in the startup and not everything is available at this point. 生命周期的PostContextCreate方法在启动时很早就开始运行,此时并不是所有东西都可用。 So you might have to wait for the app startup complete event ( UIEvents.UILifeCycle.APP_STARTUP_COMPLETE ) before accessing the persisted state data. 因此,您可能必须等待应用程序启动完成事件( UIEvents.UILifeCycle.APP_STARTUP_COMPLETE )才能访问持久状态数据。

You can always use the traditional Platform.getStateLocation(bundle) to get a location in the workspace .metadata to store arbitrary data. 您始终可以使用传统的Platform.getStateLocation(bundle)来获取工作空间.metadata中的位置以存储任意数据。 This is not touched by clearPersistedState. clearPersistedState不会触及这一点。

Update: 更新:

To subscribe to the app startup complete: 要订阅应用启动完成:

@PostContextCreate
public void postContextCreate(IEventBroker eventBroker)
{
  eventBroker.subscribe(UIEvents.UILifeCycle.APP_STARTUP_COMPLETE, new AppStartupCompleteEventHandler());
}


private static final class AppStartupCompleteEventHandler implements EventHandler
{ 
  @Override
  public void handleEvent(final Event event)
  {
    ... your code here
  }
}

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

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