1 13 14 package org.eclipse.jface.viewers; 15 16 import org.eclipse.swt.events.KeyEvent; 17 import org.eclipse.swt.events.KeyListener; 18 19 26 public class ColumnViewerEditorActivationStrategy { 27 private ColumnViewer viewer; 28 29 private KeyListener keyboardActivationListener; 30 31 35 public ColumnViewerEditorActivationStrategy(ColumnViewer viewer) { 36 this.viewer = viewer; 37 } 38 39 44 protected boolean isEditorActivationEvent( 45 ColumnViewerEditorActivationEvent event) { 46 boolean singleSelect = ((IStructuredSelection)viewer.getSelection()).size() == 1; 47 return singleSelect && (event.eventType == ColumnViewerEditorActivationEvent.MOUSE_CLICK_SELECTION 48 || event.eventType == ColumnViewerEditorActivationEvent.PROGRAMMATIC 49 || event.eventType == ColumnViewerEditorActivationEvent.TRAVERSAL); 50 } 51 52 55 private ViewerCell getFocusCell() { 56 return viewer.getColumnViewerEditor().getFocusCell(); 57 } 58 59 62 public ColumnViewer getViewer() { 63 return viewer; 64 } 65 66 72 public void setEnableEditorActivationWithKeyboard(boolean enable) { 73 if (enable) { 74 if (keyboardActivationListener == null) { 75 keyboardActivationListener = new KeyListener() { 76 77 public void keyPressed(KeyEvent e) { 78 ViewerCell cell = getFocusCell(); 79 80 if (cell != null) { 81 viewer 82 .triggerEditorActivationEvent(new ColumnViewerEditorActivationEvent( 83 cell, e)); 84 } 85 } 86 87 public void keyReleased(KeyEvent e) { 88 89 } 90 91 }; 92 viewer.getControl().addKeyListener(keyboardActivationListener); 93 } 94 } else { 95 if (keyboardActivationListener != null) { 96 viewer.getControl().removeKeyListener( 97 keyboardActivationListener); 98 keyboardActivationListener = null; 99 } 100 } 101 } 102 103 } 104 | Popular Tags |