Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » How to set a preference page at first place ?
icon5.gif  How to set a preference page at first place ? [message #506898] Mon, 11 January 2010 05:00 Go to next message
Eclipse UserFriend
Hi,

I added preference pages in a Eclipse RCP application using org.eclipse.ui.preferencePages extension point. These pages are sorted on alphabet order. But I want a specific page to be at the first place, the way it is done for example for General preference page in Eclipse ? How could I do that ?

Thanks in advance,

Olivier
Re: How to set a preference page at first place ? [message #507095 is a reply to message #506898] Tue, 12 January 2010 02:26 Go to previous messageGo to next message
Eclipse UserFriend
On 11/01/10 3:30 PM, olivier.thierry@gmail.com wrote:
> Hi,
>
> I added preference pages in a Eclipse RCP application using
> org.eclipse.ui.preferencePages extension point. These pages are sorted
> on alphabet order. But I want a specific page to be at the first place,
> the way it is done for example for General preference page in Eclipse ?
> How could I do that ?
>
> Thanks in advance,
>
> Olivier


In your WorkbenchAdvisor, override the getComparatorFor() method.


- Prakash
Platform UI Team, IBM

Blog <http://blog.eclipse-tips.com>
Twitter <http://www.twitter.com/Eclipse_Tips>
Re: How to set a preference page at first place ? [message #507659 is a reply to message #506898] Thu, 14 January 2010 04:51 Go to previous messageGo to next message
Eclipse UserFriend
Only for one page to be the first one -> override in your WorkbenchAdvisor the getMainPreferencePageId() method.

But for more control of the order of the pages overriding the getComparatorFor() method suggested above is recommended.
Re: How to set a preference page at first place ? [message #508581 is a reply to message #506898] Tue, 19 January 2010 09:24 Go to previous messageGo to next message
Eclipse UserFriend
The getMainPreferencePageId() method is exactly what I needed. Thanks a lot for your help !
Re: How to set a preference page at first place ? [message #519961 is a reply to message #506898] Wed, 10 March 2010 11:20 Go to previous messageGo to next message
Eclipse UserFriend
Finally I had more complex sorts to do so I needed to override getComparatorFor method in WorkbenchAdvisor. I desperately tried to find an example on the web, with no success. So here is a small and easy example.

I overrode the getComparatorFor method in my workbench advisor class. I needed to sort preference pages so I use a specific comparator only for "preferences" contribution types.

public ContributionComparator getComparatorFor(String contributionType) {
	if (contributionType.equals(IContributionService.TYPE_PREFERENCE)) {
		return new PreferencesComparator();
	}
	else {
		return super.getComparatorFor(contributionType);
	}
}


Then I wrote the following PreferencesComparator class. It overrides the category method to set the right value for some preference pages to display in the right order :the preference nodes with the lowest category are displayed first.

public class PreferencesComparator extends ContributionComparator {

	public int category(IComparableContribution c) {
		if (c instanceof WorkbenchPreferenceNode) {
			String id = ((WorkbenchPreferenceNode) c).getId();
			if (PlanTransportTourPreferencePage.ID.equals(id)) {
				return 1;
			}
			else if (PlanTransportSequencePreferencePage.ID.equals(id)) {
				return 2;
			}
			else if (PlanTransportPositionPreferencePage.ID.equals(id)) {
				return 3;
			}
			else {
				return super.category(c);
			}
		}
		else {
			return super.category(c);
		}
	}
}


Not sure it is a state of the art example, but I hope it will help.

Regards,

Olivier
Re: How to set a preference page at first place ? [message #523728 is a reply to message #519961] Mon, 29 March 2010 00:00 Go to previous messageGo to next message
Eclipse UserFriend
Olivier,
Thanks for taking the time to post your solution. I was trying to do a similar thing and your example was the perfect answer

Re: How to set a preference page at first place ? [message #689731 is a reply to message #506898] Tue, 28 June 2011 04:58 Go to previous message
Eclipse UserFriend
Thanks too, very useful !

eoriou

EDIT : But the access to the WorkbenchPreferenceNode class is apparently discouraged...

[Updated on: Tue, 28 June 2011 05:25] by Moderator

Previous Topic:accurate .project file reference on linked resources
Next Topic:[Common navigator] - Weird warning/error messages on startup
Goto Forum:
  


Current Time: Mon Jul 21 10:31:24 EDT 2025

Powered by FUDForum. Page generated in 0.04711 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top