Controlling Property Page Sort Order

Normally, when you view the property pages on Eclipse items, the pages show up in alphabetical order.

Sometimes this isn’t what you want.  While I was working on my RCP project I found the property pages usually didn’t show up in a pleasing order, so had to figure out a way to control the sort order.

The first thing I did was add a 3 digit sort sequence to the front of the id of every property page I registered… something like this:

   <extension
         point="org.eclipse.ui.propertyPages">
      <page
            id="001com.example.property.information"
            name="Information">

Then I created a ContributionComparator object that extracted the first 3 characters of the property page id and used it to do a simple comparison.

[java]
@Override
public int compare(IComparableContribution c1, IComparableContribution c2) {
int result = super.compare(c1, c2);

IPluginContribution pc1 = (IPluginContribution)c1;
IPluginContribution pc2 = (IPluginContribution)c2;

String id1 = pc1.getLocalId().substring(0,3);
String id2 = pc2.getLocalId().substring(0,3);

result = id1.compareTo(id2);

return result;
}
[/java]

Then, in my WorkbenchAdvisor class,  I overrode the getComparitorFor method to instantiate my ContributionComparitor if the contributionType is a property page.

[java]
@Override
public ContributionComparator getComparatorFor(String contributionType) {
ContributionComparator cc;

if (contributionType.equals(IContributionService.TYPE_PROPERTY)) {
cc = new PatchInstallerContributionComparator();
} else {
cc = super.getComparatorFor(contributionType);
}

return cc;
}
[/java]
Now the property pages show up in the order I want them to.

Leave a Reply

Your email address will not be published. Required fields are marked *