简体   繁体   中英

Eclipse PDE - How to sort the Properties in the Standard Propeties view



I'm developing an Eclipse 3.6 plugin, and have a view that contains a TreeViewer . When an item from this TreeViewer is selected, its properties appear in the standard Properties View. The Properties currently are ordered alphabetically by default.
I would like to order these properties differently .

It seems like someone else has had this problem too:
http://www.eclipse.org/forums/index.php/m/393029/

The properties in the Properties view of the default generated editor is sorted by alphabetical order. I would like to ask how to modify and arrange them in different orders.

The suggested solution is:

Your editor needs to provide the PropertySheetPage from the getAdapter(Class) method. If it doesn't provide one the property sheet will use the default PropertySheetPage, which uses the standard collator to produce the sort order. Your getAdapter() method needs to provide a specialized subclass of PropertySheetPage that sets you sorter instead.

So I need to subclass PropertySheetPage , override the setSorter method and everything should be fine.

Two questions arise:

  1. Why does it write in the documentation that:

    This class may be instantiated; it is not intended to be subclassed.

  2. Where do I make the link between the Standard Properties View and the subclass of the PropertySheetPage ?
    I am not using an editor in my case, but just have a TreeViewer that when an item is selected it provides the properties.

    Any support is appreciated!

I ran into the same thing and found a solution.

What I did is add a sort sequence prefix to the id of the property pages I was contributing (basically a 3 digit number) and create a ContributionComparator that took the first 3 digits of the id and do a basic sort.

The code looks something like this:

@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;
}

Then, in my WorkbenchAdvisor , I overrode the getComparitorFor method to instantiate ContributionComparator I created if the contributionType was a property:

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

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

    return cc;
}

Now the property pages show up in the order I want them to.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM