java - 为什么 Eclipsepedia 的 TreeViewer 需要这段代码?

标签 java eclipse swt eclipse-rcp jface

我找到了这些 JFaceSnippets来自eclipsepedia。我对 TreeViewer 特别感兴趣但我无法理解代码 here :

TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));  
ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {  
   protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {  
    return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL  
    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED &&
             event.keyCode == SWT.CR)
    || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;  
  }  
};  
TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR  
 | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION);  

为什么需要这个特定的代码片段?如果我在注释掉这段代码的情况下运行示例,似乎没有什么不同。
那么为什么要使用这段代码,它在 TreeViewer 中提供了什么?

最佳答案

这部分代码允许就地编辑树单元格,因此您可以双击节点并编辑其内容。

此行允许树具有可用于编辑的“单元格”。

TreeViewerFocusCellManager focusCellManager = new TreeViewerFocusCellManager(v,new FocusCellOwnerDrawHighlighter(v));

这一行决定何时激活单元格编辑器进行就地编辑(双击,回车)

ColumnViewerEditorActivationStrategy actSupport = new ColumnViewerEditorActivationStrategy(v) {  
   protected boolean isEditorActivationEvent(ColumnViewerEditorActivationEvent event) {  
    return event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL  
    || event.eventType == ColumnViewerEditorActivationEvent.MOUSE_DOUBLE_CLICK_SELECTION
    || (event.eventType == ColumnViewerEditorActivationEvent.KEY_PRESSED &&
             event.keyCode == SWT.CR)
    || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC;  
  }  
};  

此行创建将用于编辑树单元格的实际编辑器

TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR   | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); 

关于java - 为什么 Eclipsepedia 的 TreeViewer 需要这段代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12551353/

相关文章:

java - 如何选择表中最后插入的行?

java - xmx 和 MaxRAM JVM 参数有什么区别?

Eclipse PDE - 标记注释类型 - 背景颜色未更新

java - 添加大量内容时 ScrolledComposite 渲染不正确

java - 引号内定义的字符数组?

java - 在Java中,为什么char ch与String命令不一致?

java - 谷歌眼镜中的 Hello World

安卓+ eclipse : Can't push files to SD Card

java - 基于选择的 Eclipse RCP 处理程序启用

java - 更改 SWT TreeItem 父级