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

我从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中提供了什么?

解决方法:

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

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

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

此行确定何时激活单元格编辑器以进行就地编辑(双击,Enter)

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); 
上一篇:Snackbar使用详解及其相关框架TSnackbar


下一篇:Android笔记——输入框(EditText)