views:

2317

answers:

2

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?

+2  A: 
VonC
Brilliant, the line in ini file does the trick. But, I have a default view in which I am displaying links to perspectives. I want these links to be in the same order as well.(I am iterating thr' perspective registry here so its not in desired order). (cont)...
Chandan .
Also that perspective switcher doesn't display perspectives in order. Is there a way to access the the variable defined in ini file? Using that variable I can at least fix ordering in the view if not pers. switcher. Or better...is there a way to control/alter entry into pers. registry? Many Thanks.
Chandan .
I confirm that, when I iterate though perspective registry(as you have shown), perspectives are not in the same order as given in ini file. But, ini file entry does make perspective appear in order on UI.Is there a way to read this ini file entry in my program? Much thanks.
Chandan .
"Is there a way to read this ini file entry in my program?": not that I know of. I will search some more.
VonC
Hi VonC, I just figured out that we can retreive the ini file value with another tweak using API "PlatformUI.getPreferenceStore().setDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS)". Afterall, ini entry goes into pref. store :-). Thanks for all your help. I can up you only once :-(
Chandan .
Thank you for this feedback. I have included your comment in my answer
VonC
Oh Sorry....my bad. I meant to write .getDefault() ended up writing setDefault(). Could you please edit ou answer accordingly so that it doesn't mislead others?(I can't edit your answer - no rights yet) Sorry for the trouble.
Chandan .
I meant, The ini file entry that we add, internally gets recorded into preference store. Therefore, we can retreive it using - PlatformUI.getPreferenceStore().getDefault(IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS);
Chandan .
Done (fix the comment in my answer). But I suppose that does not solve the "perspective order" problem...
VonC
No, perspective registry remains unaltered. But, what we achieve here is "readily access to ordered list of perspectives". 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.
Chandan .
Excellent. I have added that bit of knowledge into the answer.
VonC
To clarify more, By iterating through the above said variable(which is a comma separated list of pers.ids) we can fetch the perspectives using PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(pid[i]); where pid[i] is ith comma separated pers.id. Now answer is more complete.
Chandan .
+2  A: 

To sum up all the observations and findings,

1) It is not possible to alter entries in the perspective registry. It is read-only.

2) To make perspective appear in the order that we want on perspective bar, we can achieve it by adding an entry in plugin_customization.ini (or preferences.ini) as shown below.

org.eclipse.ui/PERSPECTIVE_BAR_EXTRAS=perspectiveId1,perspectiveId2,perspectiveId3

3) If we want to fetch this ordered list, we can't fetch it directly. But as this ini file entry internally gets recorded in PreferenceStore we can fetch the same value from PreferenceStore using the following API as shown below.

PlatformUI.getPreferenceStore().getDefault( 
    IWorkbenchPreferenceConstants.PERSPECTIVE_BAR_EXTRAS);

Why would someone need to access the entry defined in ini file at all?

Well, in my case I had a view in which i had to display links to every perspective. As my perspective bar was sorted in desired order, I also wanted to maintain the same order in my view while displaying links to perspectives.

4) There is no known way to inflict the same sort order in the display of default perspective switcher. While a new custom perspective switcher can be written to achieve the desired effect.

Chandan .
Excellent summary! +1.
VonC