Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 10:00 Go to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
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 07:26 Go to previous messageGo to next message
Prakash G.R. is currently offline Prakash G.R.Friend
Messages: 621
Registered: July 2009
Senior Member
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 09:51 Go to previous messageGo to next message
Catalin Gerea is currently offline Catalin GereaFriend
Messages: 89
Registered: July 2009
Location: Bucharest, Romania
Member

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 14:24 Go to previous messageGo to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
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 16:20 Go to previous messageGo to next message
Olivier Thierry is currently offline Olivier ThierryFriend
Messages: 11
Registered: January 2010
Location: Nantes, France
Junior Member
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 04:00 Go to previous messageGo to next message
Dale Swift is currently offline Dale SwiftFriend
Messages: 1
Registered: July 2009
Junior Member
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 08:58 Go to previous message
eoriou  is currently offline eoriou Friend
Messages: 1
Registered: June 2011
Junior Member
Thanks too, very useful !

eoriou

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

[Updated on: Tue, 28 June 2011 09:25]

Report message to a moderator

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


Current Time: Sun Sep 25 07:10:38 GMT 2016

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

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