当我们双击 Checkbox TreeView 选中的项目时,如何获得键盘光标焦点来编辑标签文本

How to get the Keyboard curser focus to edit the label text, when we double click on CheckboxTreeViewer selected item

public class MyLabelProvider extends LabelProvider {

    @Override
    public Image getImage(Object element) {
        return createImage(imagePath);
    }

    @Override
    public String getText(Object element) {
        return MessageFormat.format((String)element); // CheckBOxTreeViewer, AA, BBB //and etc.
    }

    @Override
    public void dispose() {

    }

}


public class MyContentProvider implements ITreeContentProvider, IViewerListener {

    private CheckboxTreeViewer viewer;
  @Override
    public void inputChanged(Viewer viewer, Object oldInput, Object NewInput) {

    }

    @Override
    public Object[] getElements(Object inputElement) {
    }

    @Override
    public Object[] getChildren(Object parentElement) {
    }
    @Override
    public Object getParent(Object element) {
    }
    @Override
    public boolean hasChildren(Object element) {
    }
    @Override
    public void refreshOnlyContent(Object element) {
    }
    @Override
    public void refreshOnlyLabels() {
    }
    @Override
    public void refreshEverything(Object element) {
    }

    @Override
    public void dispose() {
    }
}


public class MyClass {

@PostConstruct
    public void postConstruct(Composite composite) {

CheckboxTreeViewer   treeViewer = new CheckboxTreeViewer(Composite);

MyContentProvider contentProvider = new MyContentProvider ();

treeViewer.setContentProvider(contentProvider);

IViewerListener  viewerListener = contentProvider;

treeViewer.setLabelProvider(new MyLabelProvider ());

treeViewer.addDoubleClickListener(new IDoubleClickListener() {

 @Override
public void doubleClick(DoubleClickEvent event) {

      //editor cursor focus code
  }
});

}
}

如何编辑 CheckboxTreeViewer 标签文本。

在此项目中,示例标签文本为 CheckBOxTreeViewer、AA、BBB 等

当我们双击 CheckboxTreeViewer 项目时,如何获得键盘光标焦点以便编辑标签文本。 CheckboxTreeViewer Image

版本与 AWT/Swing 不同。

您需要在 treeViewer 上使用:

  • setColumnProperties() 为版本命名列。默认情况下,树只有一列,因此您可以使用只有一个元素的数组)
  • setCellEditors() 指示您如何编辑值(文本, 组合,...)
  • setCellModifier() 这使得行对象之间的连接, 和编辑器(转换值,指示值是否为 可编辑,...)

如果您想要双击版本:

TreeViewerEditor.create(treeViewer, new ColumnViewerEditorActivationStrategy(treeViewer){
    protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {  
        return event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION;
    }

您也可以查看这篇非常有趣的文章:http://ramkulkarni.com/blog/in-place-editing-in-eclipse-treeviewer/