SWTTable中的多重编辑支持

时间:2017-09-19 14:22:38

标签: java eclipse-plugin swt eclipse-rcp tableviewer

我有一个SWT表,它包含2列

  1. 姓名

  2. 我想在值列上有多个单元格编辑器,我得到多个编辑器但是当我更改单元格中的某个值并想要再次更改它时,单元格编辑器不再出现。我的代码

     valueColumn.setEditingSupport(new EditingSupport(viewer) {         
            @Override
            protected CellEditor getCellEditor(Object element) {
                String type = (Parameter) element.getValue();
                if (type.equals("file")) {
                    return new FileEditingSupport(viewer).getCellEditor(element);
                } else if(type.equals("dir")) {
                    return new DirectoryEditingSupport(viewer).getCellEditor(element);
                } else if(type.equals("boolean")){
                    return new ComboBoxEditingSupport(viewer).getCellEditor(element);
                }
                return null;
            }
    
            @Override
            protected boolean canEdit(Object element) {
                return true;
            }
            @Override
            protected void setValue(Object element, Object value) {
                if (element != null && value != null) {
                    Parameter entry = (Parameter)element;
                    entry.setValue(value.toString());
                    viewer.refresh();
                }
            }           
            @Override
            protected Object getValue(Object element) {
                return ((Parameter)element).getValue();
            }   
        });
    

    FileEditingSupport类

    public class FileEditingSupport extends EditingSupport {
    
    private final TableViewer viewer;
    
    public FileEditingSupport(TableViewer viewer) {
        super(viewer);
        this.viewer = viewer;
    }
    
    @Override
    public CellEditor getCellEditor(Object element) {
        return new FileBrowseCellEditor(this.viewer, (Parameter) element);
    }
    
    @Override
    protected boolean canEdit(Object element) {
        return true;
    }
    
    @Override
    protected Object getValue(Object element) {
        return null;
    }
    
    @Override
    protected void setValue(Object element, Object value) {
    }
    
    }
    

    我可以选择一次文件,但是当我选择一个文件并希望更改它时,我没有得到文件选择器单元格编辑器

0 个答案:

没有答案