eclipse-plugin - Eclipse RCP : How to order perspective buttons belonging to different plugins?

标签 eclipse-plugin eclipse-rcp

我的应用程序有 5 个插件。每个插件都有自己的透视图,因此每个透视图扩展定义都在各个插件的 plugin.xml 下。

现在,我想控制这些透视图在我的应用程序中出现的顺序。怎么做?

有一个包含“ApplicationWorkBenchAdvisor.java”的主要插件。这有 initialize() 方法,我在其中迭代透视注册表使用

PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();

然后以逗号分隔的方式将透视 id 附加到字符串变量(pbar),稍后将像这样使用。
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS, pbar);
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS, pbar);

当遍历透视注册表时,我可以比较透视 id 并按照我希望它出现的方式对其进行排序(当通过比较 id 添加到“pbar”时)但是,我不想在这里进行排序,因为它看起来像肮脏的方式。

有没有其他地方可以确定视角出现的顺序? (每个视角驻留在不同的插件中)。

添加

1)我们还可以控制透视切换器中的顺序吗?

2)有没有办法控制进入透视注册表以产生所需的顺序。如果不能,我们可以写回透视注册表吗?

最佳答案

如果您的应用程序被封装为 Eclipse 产品,您可以调整 plugin.properties/plugin_customization.ini 文件。
(由 product extension point 中的“preferenceCustomization”属性引用的文件。)
此文件是 java.io.Properties 格式文件。通常,此文件用于设置作为插件公共(public) API 的一部分发布的首选项的值。
(such a file for org.eclipse.platform 的示例)

因此,如果表示透视顺序的字符串可以作为属性引用,则可以在其中定义默认顺序。
由于 IWorkbenchPreferenceConstants 的源代码提到:

 /**
  * Lists the extra perspectives to show in the perspective bar.
  * The value is a comma-separated list of perspective ids.
  * The default is the empty string.
  *
  * @since 3.2
  */
 public static final String JavaDoc PERSPECTIVE_BAR_EXTRAS = "PERSPECTIVE_BAR_EXTRAS"; //$NON-NLS-1$

可能是 plugin_customization.ini 中的一行文件:
org.eclipse.ui/PERSPECTIVE_BAR_EXTRAS=perspectiveId1,perspectiveId2,perspectiveId3

将允许您指定该订单,而无需对其进行硬编码。

补充笔记:

IPerspectiveRegistry (或 PerspectiveRegistry )不会写任何东西(特别是对于在扩展中定义的透视图)

排序可以在工作台的状态中找到(存储在工作区中,然后再次启动时恢复,.metadata/.plugins/org.eclipse.ui.workbench/workbench.xml)

您是否确认:
IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
IPerspectiveDescriptor[] perspectives = registry.getPerspectives();
plugin_customization.ini 时的顺序不正确是否正确定义了该顺序?

Liverpool 5 - 0 Aston Villa确实确认(在评论中),但也表明 (有序)ini 文件条目在内部被记录到首选项存储中 ,这意味着可以通过 检索它们偏好存储 API :
PatformUI.getPreferenceStore().getDefault( 
    IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS)

利物浦 5 - 0 阿斯顿维拉然后补充:

perspective registry (the initial "PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();" bit) remains unaltered (and unordered).
But, you still can "readily access to ordered list of perspectives" through preference store.
So, for other tasks, instead of iterating though perspective registry (which is still unordered), we can use the ordered variable that stores list of ordered perpective ids.



.
.
.
.

注意:另一种可能性是 Replace the Perspective-Switcher in RCP apps

alt text => 至:alt text

您可以更轻松地在菜单或按钮中定义顺序。

极端解决方案:re-implement a perspective switcher .

http://www.richclient2.de/wp-content/uploads/2006/08/persp_header.png

关于eclipse-plugin - Eclipse RCP : How to order perspective buttons belonging to different plugins?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/708502/

相关文章:

java - PyDev for Eclipse - 解决 Python 依赖关系( Unresolved 导入)

java - 编辑器初始化失败站点在rcp eclipse中不正确

java - 新建Eclipse插件项目什么时候选择 "Generate an activator..."

java - 如何禁用 GUI 树查看器中展开箭头的悬停显示?我希望它们始终可见

java - 自定义小部件未显示在我的 Eclipse 4 应用程序中

java - RCP 导出向导删除不必要的项目

java - 在 Eclipse 插件中使用 Javassist

eclipse - 如何在 Eclipse 中禁用 AWS SAM 本地?

java - 如何将 Eclipse-RCP 应用程序限制为单个实例?

java - 如何从 Eclipse 的 Navigator View 中获取选定的项目?