java对properties文件内容排序,java – Eclipse PDE – 如何在Standard Propeties视图中对Properties进行排序...

我正在开发一个Eclipse 3.6插件,并且有一个包含TreeViewer的视图.

选择此TreeViewer中的项目后,其属性将显示在标准“属性”视图中.默认情况下,属性按字母顺序排序.

我想以不同的方式订购这些房产.

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方法,一切都应该没问题.

出现两个问题:

>为什么在文档中写道:

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

>我在哪里建立标准属性视图和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方法,以实例化我创建的ContributionComparator,如果contributionType是属性:

@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,eclipse-plugin,eclipse-rcp

来源: https://codeday.me/bug/20190629/1325948.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值