KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > refactoring > nls > search > NLSSearchResultPage


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.refactoring.nls.search;
13
14 import org.eclipse.core.runtime.IAdaptable;
15 import org.eclipse.jdt.core.JavaModelException;
16 import org.eclipse.jdt.internal.ui.search.JavaSearchResultPage;
17 import org.eclipse.jdt.internal.ui.search.TextSearchTableContentProvider;
18 import org.eclipse.jface.viewers.TableViewer;
19 import org.eclipse.jface.viewers.TreeViewer;
20 import org.eclipse.jface.viewers.ViewerComparator;
21
22 import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
23 import org.eclipse.search.ui.text.Match;
24 import org.eclipse.ui.IEditorPart;
25 import org.eclipse.ui.PartInitException;
26 import org.eclipse.ui.part.IShowInTargetList;
27 import org.eclipse.ui.texteditor.ITextEditor;
28
29
30 public class NLSSearchResultPage extends AbstractTextSearchViewPage implements IAdaptable {
31
32     private TextSearchTableContentProvider fContentProvider;
33     private NLSSearchEditorOpener fEditorOpener= new NLSSearchEditorOpener();
34
35     public NLSSearchResultPage() {
36         super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
37     }
38     
39     /*
40      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match,
41      * int, int)
42      */

43     protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException {
44         try {
45             IEditorPart editor= fEditorOpener.openMatch(match);
46             if (editor != null && activate)
47                 editor.getEditorSite().getPage().activate(editor);
48             if (editor instanceof ITextEditor) {
49                 ITextEditor textEditor= (ITextEditor) editor;
50                 textEditor.selectAndReveal(currentOffset, currentLength);
51             }
52         } catch (JavaModelException e1) {
53             throw new PartInitException(e1.getStatus());
54         }
55     }
56     
57     /*
58      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[])
59      */

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

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

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

83     protected void configureTableViewer(TableViewer viewer) {
84         viewer.setComparator(new ViewerComparator() {
85             public int category(Object JavaDoc element) {
86                 if (element instanceof FileEntry) {
87                     return 0;
88                 } else {
89                     return 1;
90                 }
91             }
92         });
93         viewer.setLabelProvider(new NLSSearchResultLabelProvider2(this));
94         fContentProvider= new TextSearchTableContentProvider();
95         viewer.setContentProvider(fContentProvider);
96     }
97     
98     /* (non-Javadoc)
99      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
100      */

101     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
102         if (IShowInTargetList.class.equals(adapter)) {
103             return JavaSearchResultPage.SHOW_IN_TARGET_LIST;
104         }
105         return null;
106     }
107
108     
109 }
110
Popular Tags