[心缘地方]同学录
首页 | 功能说明 | 站长通知 | 最近更新 | 编码查看转换 | 代码下载 | 常见问题及讨论 | 《深入解析ASP核心技术》 | 王小鸭自动发工资条VBA版
登录系统:用户名: 密码: 如果要讨论问题,请先注册。

[整理]RCP插件开发,Propertes 视图中的属性项目的顺序问题

上一篇:[整理]RCP插件开发,如何使用properties视图,[另一篇]
下一篇:[整理]Eclipse RCP 开发,Actions与Commands的区别

添加日期:2011/3/31 17:36:59 快速返回   返回列表 阅读4786次

参考了这里:http://lggege.javaeye.com/blog/246950

Properties视图的属性项目,默认是以字母顺序排序的,而且不能直接定义排序。

(1)需要自己做一个PropertySheetPage的子类,重新定义排序方法。


import org.eclipse.ui.views.properties.IPropertySheetEntry;
import org.eclipse.ui.views.properties.PropertySheetPage;
import org.eclipse.ui.views.properties.PropertySheetSorter;

public class XXXPropertySheetPage extends PropertySheetPage {

    public XXXPropertySheetPage() {
        
        //重新定义排序,直接返回0,即相等,则属性项目会按添加顺序显示。
        this.setSorter(new PropertySheetSorter() {
            public int compare(IPropertySheetEntry entryA,
                    IPropertySheetEntry entryB) {
                return 0;
            }
            
            public int compareCategories(String categoryA, String categoryB) {
                  return 0;
            }
        });
    }
}



上例直接返回0了,这样就按添加的顺序显示了。可以根据需要修改排序方法。

(2)在Editor的getAdatper方法,返回该子类。如果你不是在做Editor,那俺不晓得喽。


public Object getAdapter(Class type) {
    
    //如果是Property视图
    if (type == IPropertySheetPage.class){
        
        //每个打开的编辑器窗口,只会访问这里一次,所以直接new一个返回就行。
        return new DataRowPropertySheetPage();
    }

    //其他的,让super去找吧
    return super.getAdapter(type);
}


原来getAdapter方法就是返回各种自定义视图对象的呀。

(3)搞定了。
 

评论 COMMENTS
没有评论 No Comments.

添加评论 Add new comment.
昵称 Name:
评论内容 Comment:
验证码(不区分大小写)
Validation Code:
(not case sensitive)
看不清?点这里换一张!(Change it here!)
 
评论由管理员查看后才能显示。the comment will be showed after it is checked by admin.
CopyRight © 心缘地方 2005-2999. All Rights Reserved