为什么Eclipsepedia的TreeViewer需要这些代码?

时间:2012-09-23 10:00:09

标签: java eclipse swt eclipse-rcp jface

我从eclipsepedia找到了这些JFaceSnippets。我对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中提供了什么?

2 个答案:

答案 0 :(得分:3)

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

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

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); 

答案 1 :(得分:0)

当我阅读代码时,它指定了交互设置,例如,您可以通过双击并使用回车键等来激活单元格。其中一些设置可能与默认设置保持一致。