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.inifile.(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
IWorkbenchPreferenceConstantsmentions:Maybe a line in the
plugin_customization.inifile: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:
is not in the right order when the
plugin_customization.inidoes 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:
Liverpool 5 – 0 Aston Villa then add:
.
.
.
.
Note: another possibility is to Replace the Perspective-Switcher in RCP apps
You can more easily define the order in a menu or in buttons there.
Extreme solution: re-implement a perspective switcher.