1 14 package org.eclipse.search2.internal.ui.basic.views; 15 import org.eclipse.jface.viewers.TableViewer; 16 17 public class TableViewerNavigator implements INavigate { 18 private TableViewer fViewer; 19 public TableViewerNavigator(TableViewer viewer) { 20 fViewer = viewer; 21 } 22 public void navigateNext(boolean forward) { 23 int itemCount = fViewer.getTable().getItemCount(); 24 if (itemCount == 0) 25 return; 26 int[] selection = fViewer.getTable().getSelectionIndices(); 27 int nextIndex = 0; 28 if (selection.length > 0) { 29 if (forward) { 30 nextIndex = selection[selection.length - 1] + 1; 31 if (nextIndex >= itemCount) 32 nextIndex = 0; 33 } else { 34 nextIndex = selection[0] - 1; 35 if (nextIndex < 0) 36 nextIndex = itemCount - 1; 37 } 38 } 39 fViewer.getTable().setSelection(nextIndex); 40 fViewer.getTable().showSelection(); 41 } 42 } 43 | Popular Tags |