Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is this code needed for a TreeViewer from Eclipsepedia?

I found these JFaceSnippets from eclipsepedia. I am particularly interested in the TreeViewer but I can not understand the code 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);  

Why is this specific code snippet needed? If I run the example with this code commented out, there does not seem to be a difference.
So why is this code used and what does it offer in the TreeViewer?

like image 483
Cratylus Avatar asked Jul 05 '26 00:07

Cratylus


1 Answers

This part of the code allows in-place editing of the tree cells, so you can double-click on a node and edit its contents.

This line allows Trees to have "Cells" that can be used for editing.

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

This line determines when the cell editor will be activated for inplace editing (Double-click, 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;  
  }  
};  

This line creates the actual editor that will be used to edit the tree cells

TreeViewerEditor.create(v, focusCellManager, actSupport, ColumnViewerEditor.TABBING_HORIZONTAL| ColumnViewerEditor.TABBING_MOVE_TO_ROW_NEIGHBOR   | ColumnViewerEditor.TABBING_VERTICAL | ColumnViewerEditor.KEYBOARD_ACTIVATION); 
like image 85
mhussein Avatar answered Jul 06 '26 15:07

mhussein



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!