GEF 给PropertySheetPage设置属性排序功能

在PropertySheetPage显示的属性中, 如果需要自定义属性显示的上下顺序, 就需要给PropertySheetPage添加一个PropertySheetSorter, 从而决定属性显示的上下顺序.

protected void setSorter(PropertySheetSorter sorter) {


但是, 这个方法是protected的, 所以, 只有在给Editor添加PropertySheetPage的时候, 需要使用比较脏的方法给PropertySheetPage 设置一个sorter了.


我的做法如下:
		propertySheetPage = new PropertySheetPage() {
/**
* @see org.eclipse.ui.views.properties.PropertySheetPage#createControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createControl(Composite parent) {
// 设置一个使用描述来排序的Sorter
PropertySheetSorter sorter = new PropertySheetSorter() {
public int compare(IPropertySheetEntry entryA, IPropertySheetEntry entryB) {
// 使用IPropertySheetEntry的description排序.
return getCollator().compare(entryA.getDescription(), entryB.getDescription());
}
};
this.setSorter(sorter);

super.createControl(parent);
}
};

注: 排序的规制是使用entryA.getDescription()来作为排序依据.

于是: Model中的代码如下:
	public IPropertyDescriptor[] getPropertyDescriptors() {

TextPropertyDescriptor locationXPD = new TextPropertyDescriptor(P_LOCATION_X, "X坐标");
locationXPD.setDescription("01");

TextPropertyDescriptor locationYPD = new TextPropertyDescriptor(P_LOCATION_Y, "Y坐标");
locationYPD.setDescription("02");

return new IPropertyDescriptor[] { locationXPD, locationYPD};
}


效果: 'X坐标' 排在了 'Y坐标' 的前面了.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值