3

我从 eclipsepedia 中找到了这些JFaceSnippets。我对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);  

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

4

2 回答 2

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); 
于 2012-09-24T11:41:55.467 回答
0

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

于 2012-09-23T10:39:28.957 回答