简体   繁体   English

Eclipse PDE - 如何在Standard Propeties视图中对Properties进行排序

[英]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 . 我正在开发一个Eclipse 3.6插件,并且有一个包含TreeViewer When an item from this TreeViewer is selected, its properties appear in the standard Properties View. 选择此TreeViewer的项目后,其属性将显示在标准“属性”视图中。 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/ 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. 您的编辑器需要从getAdapter(Class)方法提供PropertySheetPage。 If it doesn't provide one the property sheet will use the default PropertySheetPage, which uses the standard collator to produce the sort order. 如果它没有提供,则属性表将使用默认的PropertySheetPage,它使用标准collat​​or生成排序顺序。 Your getAdapter() method needs to provide a specialized subclass of PropertySheetPage that sets you sorter instead. 您的getAdapter()方法需要提供PropertySheetPage的专用子类,以便为您设置排序器。

So I need to subclass PropertySheetPage , override the setSorter method and everything should be fine. 所以我需要setSorter PropertySheetPage ,覆盖setSorter方法,一切都应该没问题。

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 ? 在哪里可以在标准属性视图和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. 我不是在我的情况下使用编辑器,但只是有一个TreeViewer ,当选择一个项目时它提供属性。

    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. 我所做的是在我所贡献的属性页面的id中添加一个排序序列前缀(基本上是一个3位数字),并创建一个ContributionComparator ,它获取id的前3位数并进行基本排序。

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: 然后,在我的WorkbenchAdvisor中 ,我重写了getComparitorFor方法,以实例化我在contribType是属性时创建的ContributionComparator:

@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. 现在,属性页按我希望的顺序显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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