【问题标题】:I need to execute some code only for RCP not For RAP how can i do that我只需要为 RCP 而不是 RAP 执行一些代码我该怎么做
【发布时间】:2015-03-23 23:33:27
【问题描述】:

我正在研究 Eclipse RCP/RAP 单一来源。 我需要在ApplicationWorkbenchAdvisor 类的resotreState()saveState() 方法中执行一些代码,这些代码仅适用于RCP,但不适用于RAP。实现这一点的最佳方法是什么?

【问题讨论】:

    标签: eclipse-rcp eclipse-rap


    【解决方案1】:

    如果只应在 RCP 中执行的代码在两个平台上都编译,那么您可以像这样查询SWT#getPlatform()

    if( !SWT.getPlatform().startsWith( "rap" ) ) {
      // execute RCP code
    }
    

    如果 RCP 代码使用的 API 在两个平台上都不可用,那么我建议将代码提取到一个片段中,并且只将该片段与 RCP 应用程序一起部署。搜索“说唱单一来源”以了解更多信息。

    【讨论】:

    • 请看下面的代码:@Overridepublic IStatus saveState(IMemento memento) {TerminalCompatibility.saveState(memento);ServerStorageController.getInstance().saveState(memento);return super.saveState(memento);} ——这个代码依赖于IMemento。是否有可能我可以将此代码移动到 RCP 特定片段。我不想写空的兼容性类。
    • IMemento 在两个平台上都可用,因此您可以使用第一种方法并使用 if 条件保护保存状态的代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    • 2020-05-24
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多