KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > search2 > internal > ui > basic > views > TableViewerNavigator


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Michael Fraenkel (fraenkel@us.ibm.com) - contributed a fix for:
11  * o Go to next match on last match does nothing
12  * (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=58311)
13  *******************************************************************************/

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