Eclipse RCP:如何订购属于不同插件的透视按钮? [英] Eclipse RCP: How to order perspective buttons belonging to different plugins?
问题描述
现在,我想控制这些透视在我的应用程序中出现的顺序。如何做?
有一个主要的插件是ApplicationWorkBenchAdvisor.java。这里有一个initialize()方法,其中我通过透视注册表使用
PlatformUI.getWorkbench()。getPerspectiveRegistry()。 getPerspectives();
,然后将透明度标签以逗号分隔的方式附加到稍后使用的String变量(pbar)这样。
PlatformUI.getPreferenceStore()。setDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS,pbar);
PlatformUI.getPreferenceStore()。setValue(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS,pbar);
在透视注册表进行迭代时,我可以比较透视图ids并进行排序(添加到 '通过比较ids)我想要它出现的方式,但我不想这样做排序,因为它看起来像一个脏的方式。
有没有其他地方可以修改观点出现的顺序? (每个视角都位于不同的插件中)。
ADDED
1)我们还可以控制透视切换器?
2)有没有办法控制进入透视注册表以实现所需的顺序。如果我们不能写回透视注册表?
如果您的应用程序被封装为eclipse产品,您可以调整< a href =http://dev.eclipse.org/newslists/news.eclipse.platform/msg71104.html =nofollow noreferrer> plugin.properties/plugin_customization.ini
文件。
(您的。
My application has 5 plugins. Each plugin has a perspective of it's own and hence each perspective extension definition is under individual plugin's plugin.xml.
Now, I want to control the order in which these perspectives appear in my application. How to do it?
There is one main plugin that holds "ApplicationWorkBenchAdvisor.java". This has initialize() method in which I am iterating through the perspective registry using
PlatformUI.getWorkbench().getPerspectiveRegistry().getPerspectives();
and then appending perspective ids in a comma separated fashion to a String variable (pbar) which is used later like this.
PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS, pbar);
PlatformUI.getPreferenceStore().setValue(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS, pbar);
When iterating thourgh the perspective registry, I can compare perspective ids and sort it(when adding to 'pbar' by comparing ids) the way I want it to appear but, I don't want to do this ordering here as it appears like a dirty way.
Is there any other place where we can fix the order in which perspectives appear? (Each perspective resides in different plugin).
ADDED
1) Could we also control the ordering in the perspective switcher?
2) Is there a way to control entry into perspective registry to in inflict the desired order. If not could we write back into perspective registry?
If your application is encapsulated as an eclipse product, you may tweak the plugin.properties/plugin_customization.ini
file.
(file referenced by the 'preferenceCustomization
' property in your product extension point.)
This file is a java.io.Properties format file. Typically this file is used to set the values for preferences that are published as part of a plug-in's public API.
(Example of such a file for org.eclipse.platform
)
So if the string representing the order of perspective can be referenced as a property, you can define the default order in there.
Since the source code of IWorkbenchPreferenceConstants
mentions:
/**
* 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$
Maybe a line in the plugin_customization.ini
file:
org.eclipse.ui/PERSPECTIVE_BAR_EXTRAS=perspectiveId1,perspectiveId2,perspectiveId3
would allow you to specify that order without having to hard-code it.
Additional notes:
IPerspectiveRegistry (or PerspectiveRegistry) is not made to write anything (especially for perspective defined in an extension)
Ordering may be found in the state of the workbench (stored in the workspace and then restored when its launched again, .metadata/.plugins/org.eclipse.ui.workbench/workbench.xml
)
Do you confirm that:
IPerspectiveRegistry registry = PlatformUI.getWorkbench().getPerspectiveRegistry();
IPerspectiveDescriptor[] perspectives = registry.getPerspectives();
is not in the right order when the plugin_customization.ini
does define that order correctly ?
Liverpool 5 - 0 Aston Villa does confirm that (in the comments), but also indicates the (ordered) ini file entries internally get recorded into preference store, which means they can be retrieved through the preference store API:
PatformUI.getPreferenceStore().getDefault(
IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS)
Liverpool 5 - 0 Aston Villa then add:
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.
.
.
.
.
Note: another possibility is to Replace the Perspective-Switcher in RCP apps
=> to:
You can more easily define the order in a menu or in buttons there.
Extreme solution: re-implement a perspective switcher.
这篇关于Eclipse RCP:如何订购属于不同插件的透视按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!