KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > search > OccurrencesSearchResultPage


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  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.search;
13
14 import org.eclipse.jface.viewers.TableViewer;
15 import org.eclipse.jface.viewers.TreeViewer;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.jface.viewers.ViewerComparator;
18
19 import org.eclipse.ui.IEditorPart;
20 import org.eclipse.ui.PartInitException;
21 import org.eclipse.ui.texteditor.ITextEditor;
22
23 import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
24 import org.eclipse.search.ui.text.Match;
25
26 import org.eclipse.jdt.core.IJavaElement;
27 import org.eclipse.jdt.core.JavaModelException;
28
29 import org.eclipse.jdt.ui.JavaUI;
30
31
32 public class OccurrencesSearchResultPage extends AbstractTextSearchViewPage {
33
34     private TextSearchTableContentProvider fContentProvider;
35
36     public OccurrencesSearchResultPage() {
37         super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
38     }
39
40     /*
41      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int)
42      */

43     protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
44         JavaElementLine element= (JavaElementLine) match.getElement();
45         IJavaElement javaElement= element.getJavaElement();
46         try {
47             IEditorPart editor= JavaUI.openInEditor(javaElement, activate, false);
48             if (editor instanceof ITextEditor) {
49                 ITextEditor textEditor= (ITextEditor) editor;
50                 textEditor.selectAndReveal(currentOffset, currentLength);
51             }
52         } catch (PartInitException e1) {
53             return;
54         } catch (JavaModelException e1) {
55             return;
56         }
57
58     }
59
60     /*
61      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[])
62      */

63     protected void elementsChanged(Object JavaDoc[] objects) {
64         if (fContentProvider != null)
65             fContentProvider.elementsChanged(objects);
66     }
67
68     /*
69      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#clear()
70      */

71     protected void clear() {
72         if (fContentProvider != null)
73             fContentProvider.clear();
74     }
75
76     /*
77      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTreeViewer(org.eclipse.jface.viewers.TreeViewer)
78      */

79     protected void configureTreeViewer(TreeViewer viewer) {
80         throw new IllegalStateException JavaDoc("Doesn't support tree mode."); //$NON-NLS-1$
81
}
82
83     /*
84      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer)
85      */

86     protected void configureTableViewer(TableViewer viewer) {
87         viewer.setComparator(new ViewerComparator() {
88             public int compare(Viewer v, Object JavaDoc e1, Object JavaDoc e2) {
89                 JavaElementLine jel1= (JavaElementLine) e1;
90                 JavaElementLine jel2= (JavaElementLine) e2;
91                 return jel1.getLine() - jel2.getLine();
92             }
93         });
94         viewer.setLabelProvider(new OccurrencesSearchLabelProvider(this));
95         fContentProvider= new TextSearchTableContentProvider();
96         viewer.setContentProvider(fContentProvider);
97     }
98     
99 }
100
Popular Tags