KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.IStructuredContentProvider;
15 import org.eclipse.jface.viewers.TableViewer;
16 import org.eclipse.jface.viewers.Viewer;
17 import org.eclipse.search.ui.text.AbstractTextSearchResult;
18
19 /**
20  * TODO: this class should replace JavaSearchTableContentProvider
21  * (must generalize type of fResult to AbstractTextSearchResult in JavaSearchContentProvider)
22  */

23 public class TextSearchTableContentProvider implements IStructuredContentProvider {
24     protected final Object JavaDoc[] EMPTY_ARRAY= new Object JavaDoc[0];
25     private AbstractTextSearchResult fSearchResult;
26     private TableViewer fTableViewer;
27
28     /*
29      * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
30      */

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

40     public void dispose() {
41         //nothing
42
}
43
44     /*
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 elementsChanged(Object JavaDoc[] updatedElements) {
53         //TODO: copied from JavaSearchTableContentProvider
54
int addCount= 0;
55         int removeCount= 0;
56         for (int i= 0; i < updatedElements.length; i++) {
57             if (fSearchResult.getMatchCount(updatedElements[i]) > 0) {
58                 if (fTableViewer.testFindItem(updatedElements[i]) != null)
59                     fTableViewer.refresh(updatedElements[i]);
60                 else
61                     fTableViewer.add(updatedElements[i]);
62                 addCount++;
63             } else {
64                 fTableViewer.remove(updatedElements[i]);
65                 removeCount++;
66             }
67         }
68     }
69     
70     public void clear() {
71         //TODO: copied from JavaSearchTableContentProvider
72
fTableViewer.refresh();
73     }
74 }
75
Popular Tags