现在很少用Eclipse RCP框架开发软件了,对于属性视图默认的Descriptor并不能满足业务需求,于是做了三个轮子以备不时之需。
note: 获取地址参见文章结尾

可编辑下拉框

用法

//IPropertyDescriptord创建
EditableComboPropertyDescriptor test1 = new EditableComboPropertyDescriptor("可编辑下拉", "可编辑下拉",new String[]{"苟利国家生死以","岂因祸福避趋之","+ 1 s","+ 2 s","+ 3 s"});
#setPropertyValue
-case "可编辑下拉"
obj = (String)value;
#getPropertyValue
-case "可编辑下拉"
return obj

多选下拉框

用法

//创建时不传入下拉列表,在Descriptor类定义时进行填充,在#setPropertyValue时设置当前值
DropdownMultiListDescriptor     test2 = new DropdownMultiListDescriptor("多选下拉", "多选下拉");
#setPropertyValue
-case "可编辑下拉"
obj = (int[] arr)value;
#getPropertyValue
-case "可编辑下拉"
return obj//int[]

/////////////////////////////////////////
/**
 * 多选下拉
 * 每个属性视图单独实现
 * editor.setInput(new DropdownMultiListItem[]{ALT, CTRL,SHIFT,WIN}); 填充内容
 */
public class DropdownMultiListDescriptor extends PropertyDescriptor {
    String[] nodeList = null;

    public DropdownMultiListDescriptor(String id, String displayName) {
        super(id, displayName);
    }

    public CellEditor createPropertyEditor(Composite parent) {
        DropdownMultiTreeCellEditor editor = new DropdownMultiTreeCellEditor(parent, false);

        editor.setLabelProvider(new ILabelProvider() {
            public void removeListener(ILabelProviderListener listener) {
            }

            public boolean isLabelProperty(Object element, String property) {
                return false;
            }

            public void dispose() {
            }

            public void addListener(ILabelProviderListener listener) {
            }

            public String getText(Object element) {
                if(element instanceof DropdownMultiListItem) {
                    DropdownMultiListItem ti = (DropdownMultiListItem)element;
                    return ti.name;                    
                }else{
                    return "";
                }
            }

            public Image getImage(Object element) {
                return null;
            }
        });
        editor.setContentProvider(new ITreeContentProvider() {

            public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            }
            public void dispose() {

            }
            public Object[] getElements(Object inputElement) {
                return (Object[]) inputElement;
            }
            public boolean hasChildren(Object element) {
                return false;
            }
            public Object getParent(Object element) {
                return null;
            }
            public Object[] getChildren(Object parentElement) {
                return null;
            }
        });
        DropdownMultiListItem ALT = new DropdownMultiListItem("ALT",1);
        DropdownMultiListItem CTRL = new DropdownMultiListItem("CTRL",2);
        DropdownMultiListItem SHIFT = new DropdownMultiListItem("SHIFT",3);
        DropdownMultiListItem WIN = new DropdownMultiListItem("WIN",4);

        editor.setInput(new DropdownMultiListItem[]{ALT, CTRL,SHIFT,WIN});
        if (getValidator() != null) {
            editor.setValidator(getValidator());
        }
        return editor;
    }
}

可清除单元格

用法

//对于这种不在单元格上显示实际数据的情况,直接在updateContent上限制显示内容即可
//需自行根据特定需求使用ClearableDialogCellEditor创建PropertyDescriptor

下载地址:https://github.com/Laxse/RCP_Awesome_PropertyDescriptor


只要有树叶飞舞的地方,火就会燃烧。