属性视图小结

1.如果要实现在属性视图中编辑被选择的对象,则至少必须满足以下两个条件:

  • 被选择的对象必须实现或者能够适配成IPropertySource接口对象。
  • 被选择的对象必须能够被实现了ISelectionProvider接口的选择提供者提供属性视图

2.Eclipse中内置了一些实现了IPropertyDescriptor接口的类

  • PropertyDescriptor 可以实现不可编辑的属性

  • ColorPropertyDescriptor会弹出颜色选择对话框

  • ComboBoxPropertyDescriptor 可以通过下拉框选择需要的属性

  • TextPropertyDescriptor 实现可编辑的属性

  • StandardComboBoxPropertyDescriptor

3.实现属性栏打开自定义的对话框

  • 可以参考在属性页中打开对话框 ,写得已经很详细了。

4.实现属性的显示顺序

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

4.1 在Editor中加入如下代码:

	...................
		if (type.equals(IPropertySheetPage.class)) {
			return new PropertySheetPage() {
				public void createControl(Composite parent) {
					// super.createControl(parent);
					PropertySheetSorter sorter = new PropertySheetSorter() {
						public int compare(IPropertySheetEntry entryA,
								IPropertySheetEntry entryB) {
							return getCollator().compare(
									entryA.getDescription(),
									entryB.getDescription());
						}
					};
					this.setSorter(sorter);
					super.createControl(parent);
				}
			};
		}
		return super.getAdapter(type);
	}

4.2 在处理属性视图的类中加入以下代码

public IPropertyDescriptor[] getPropertyDescriptors() {
		ArrayList<IPropertyDescriptor> properties = new ArrayList<IPropertyDescriptor>();
		TextPropertyDescriptor name=new TextPropertyDescriptor(Node.PROPERTY_RENAME, "Name");
		name.setDescription("01");//设置这个是为了排序
		properties.add(name);//增加任务名
		if (node instanceof TaskModel) {			
			TextPropertyDescriptor des=new TextPropertyDescriptor(TaskModel.PROPERTY_DESCRIPTION,
			"Description");
			des.setDescription("02");
			properties.add(des);//增加任务描述
...........................

其实就是通过entryA.getDescription()来作为排序依据.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值