KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > search > AbstractSearchResultPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 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 package org.eclipse.pde.internal.ui.search;
12
13 import org.eclipse.jface.viewers.ILabelProvider;
14 import org.eclipse.jface.viewers.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.TableViewer;
16 import org.eclipse.jface.viewers.TreeViewer;
17 import org.eclipse.jface.viewers.Viewer;
18 import org.eclipse.jface.viewers.ViewerComparator;
19 import org.eclipse.search.ui.text.AbstractTextSearchResult;
20 import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
21
22 public abstract class AbstractSearchResultPage extends AbstractTextSearchViewPage {
23     
24     class ContentProvider implements IStructuredContentProvider {
25
26         private TableViewer fTableViewer;
27         private AbstractTextSearchResult fSearchResult;
28
29         /* (non-Javadoc)
30          * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
31          */

32         public Object JavaDoc[] getElements(Object JavaDoc inputElement) {
33             if (inputElement instanceof AbstractTextSearchResult)
34                 return ((AbstractTextSearchResult) inputElement).getElements();
35             return new Object JavaDoc[0];
36         }
37
38         /* (non-Javadoc)
39          * @see org.eclipse.jface.viewers.IContentProvider#dispose()
40          */

41         public void dispose() {
42         }
43
44         /* (non-Javadoc)
45          * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
46          */

47         public void inputChanged(Viewer viewer, Object JavaDoc oldInput, Object JavaDoc newInput) {
48             fTableViewer = (TableViewer)viewer;
49             fSearchResult = (AbstractTextSearchResult)newInput;
50         }
51         
52         public void clear() {
53             fTableViewer.refresh();
54         }
55         
56         public void elementsChanged(Object JavaDoc[] updatedElements) {
57             for (int i= 0; i < updatedElements.length; i++) {
58                 if (fSearchResult.getMatchCount(updatedElements[i]) > 0) {
59                     if (fTableViewer.testFindItem(updatedElements[i]) != null)
60                         fTableViewer.refresh(updatedElements[i]);
61                     else
62                         fTableViewer.add(updatedElements[i]);
63                 } else {
64                     fTableViewer.remove(updatedElements[i]);
65                 }
66             }
67         }
68     }
69
70     private ContentProvider fContentProvider;
71
72     public AbstractSearchResultPage() {
73         super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
74     }
75     
76     
77     /* (non-Javadoc)
78      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[])
79      */

80     protected void elementsChanged(Object JavaDoc[] objects) {
81         if (fContentProvider != null && fContentProvider.fSearchResult != null)
82             fContentProvider.elementsChanged(objects);
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#clear()
87      */

88     protected void clear() {
89         if (fContentProvider != null)
90             fContentProvider.clear();
91     }
92     
93     /* (non-Javadoc)
94      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTreeViewer(org.eclipse.jface.viewers.TreeViewer)
95      */

96     protected void configureTreeViewer(TreeViewer viewer) {
97         throw new IllegalStateException JavaDoc("Doesn't support tree mode."); //$NON-NLS-1$
98
}
99
100     /* (non-Javadoc)
101      * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer)
102      */

103     protected void configureTableViewer(TableViewer viewer) {
104         viewer.setComparator(createViewerComparator());
105         viewer.setLabelProvider(createLabelProvider());
106         fContentProvider= new ContentProvider();
107         viewer.setContentProvider(fContentProvider);
108     }
109     
110     protected abstract ILabelProvider createLabelProvider();
111     
112     protected abstract ViewerComparator createViewerComparator();
113     
114
115 }
116
Popular Tags