gpt4 book ai didi

java - Eclipse PDE - 如何在标准属性 View 中对属性进行排序

转载 作者:搜寻专家 更新时间:2023-11-01 03:07:14 26 4
gpt4 key购买 nike



我正在开发一个 Eclipse 3.6 插件,并且有一个包含 TreeViewer 的 View 。选择此 TreeViewer 中的项目时,其属性会出现在标准属性 View 中。默认情况下,属性当前按字母顺序排列。
我想以不同方式订购这些属性。

好像其他人也遇到过这个问题:
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.

建议的解决方案是:

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.

所以我需要继承PropertySheetPage , 覆盖 setSorter 方法,一切都应该没问题。

出现两个问题:

  1. 为什么它在文档中写道:

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

  2. 我在哪里建立标准属性 View 和 PropertySheetPage 的子类之间的链接?
    在我的例子中,我没有使用编辑器,只是有一个 TreeViewer,当一个项目被选中时它会提供属性。

    感谢任何支持!

最佳答案

我遇到了同样的事情并找到了解决方案。

我所做的是为我贡献的属性页的 ID 添加一个排序序列前缀(基本上是一个 3 位数)并创建一个 ContributionComparator获取 ID 的前 3 位数字并进行基本排序。

代码看起来像这样:

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

然后,在我的WorkbenchAdvisor , 我覆盖了 getComparitorFor如果 contributionType 是属性,则实例化我创建的 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;
}

现在属性页按照我希望的顺序显示。

关于java - Eclipse PDE - 如何在标准属性 View 中对属性进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18128176/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com