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

标签 java eclipse eclipse-plugin eclipse-rcp



我正在开发一个 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/

相关文章:

java - 为什么打印 [[Ljava.lang.Object;@12f29d9, [Ljava.lang.Object;@1648f32]

java - 在 MapFragment 中显示当前位置

android - 无法在Android模拟器中模拟位置数据

java - 如何在Eclipse中使用javabean?

java - 将应用程序与 VC++ 应用程序集成

java - 如何在 org.apache.directory.ldap.client.api.LdapConnection 中添加带反斜杠的用户名?

java - 如何以 sbt 汇编后可访问的方式打开我的资源目录中的文件?

java - 将spring项目导入到另一个spring项目中

java - 如何使用 eclipse 插件将控制台输出重定向到 GUI 控制台 View ?

java - 全新的 Eclipse 插件项目充满了错误