1 11 12 package org.eclipse.jface.viewers; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.widgets.Event; 16 import org.eclipse.swt.widgets.Item; 17 import org.eclipse.swt.widgets.Tree; 18 import org.eclipse.swt.widgets.TreeItem; 19 20 28 public class TreeViewerFocusCellManager extends SWTFocusCellManager { 29 private static final CellNavigationStrategy TREE_NAVIGATE = new CellNavigationStrategy() { 30 public void collapse(ColumnViewer viewer, ViewerCell cellToCollapse, 31 Event event) { 32 if (cellToCollapse != null) { 33 ((TreeItem) cellToCollapse.getItem()).setExpanded(false); 34 } 35 } 36 37 public void expand(ColumnViewer viewer, ViewerCell cellToExpand, 38 Event event) { 39 if (cellToExpand != null) { 40 TreeViewer v = (TreeViewer) viewer; 41 v.setExpandedState(v 42 .getTreePathFromItem((Item)cellToExpand.getItem()), true); 43 } 44 } 45 46 public boolean isCollapseEvent(ColumnViewer viewer, 47 ViewerCell cellToCollapse, Event event) { 48 return cellToCollapse != null 49 && ((TreeItem) cellToCollapse.getItem()).getExpanded() 50 && cellToCollapse.getColumnIndex() == 0 51 && event.keyCode == SWT.ARROW_LEFT; 52 } 53 54 public boolean isExpandEvent(ColumnViewer viewer, 55 ViewerCell cellToExpand, Event event) { 56 return cellToExpand != null 57 && ((TreeItem) cellToExpand.getItem()).getItemCount() > 0 58 && !((TreeItem) cellToExpand.getItem()).getExpanded() 59 && cellToExpand.getColumnIndex() == 0 60 && event.keyCode == SWT.ARROW_RIGHT; 61 } 62 }; 63 64 72 public TreeViewerFocusCellManager(TreeViewer viewer, 73 FocusCellHighlighter focusDrawingDelegate) { 74 super(viewer, focusDrawingDelegate,TREE_NAVIGATE); 75 } 76 77 ViewerCell getInitialFocusCell() { 78 Tree tree = (Tree) getViewer().getControl(); 79 80 if( tree.getItemCount() > 0 ) { 81 return getViewer().getViewerRowFromItem(tree.getItem(0)).getCell(0); 82 } 83 84 return null; 85 } 86 } 87 | Popular Tags |