]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2010 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 | ||
18 | import org.eclipse.search.ui.text.AbstractTextSearchResult; | |
19 | ||
20 | /** | |
21 | * TODO: this class should replace JavaSearchTableContentProvider | |
22 | * (must generalize type of fResult to AbstractTextSearchResult in JavaSearchContentProvider) | |
23 | */ | |
24 | public class TextSearchTableContentProvider implements IStructuredContentProvider { | |
25 | protected final Object[] EMPTY_ARRAY= new Object[0]; | |
26 | private AbstractTextSearchResult fSearchResult; | |
27 | private TableViewer fTableViewer; | |
28 | ||
29 | /* | |
30 | * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) | |
31 | */ | |
32 | public Object[] getElements(Object inputElement) { | |
33 | if (inputElement instanceof AbstractTextSearchResult) | |
34 | return ((AbstractTextSearchResult) inputElement).getElements(); | |
35 | return EMPTY_ARRAY; | |
36 | } | |
37 | ||
38 | /* | |
39 | * @see org.eclipse.jface.viewers.IContentProvider#dispose() | |
40 | */ | |
41 | public void dispose() { | |
42 | //nothing | |
43 | } | |
44 | ||
45 | /* | |
46 | * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object) | |
47 | */ | |
48 | public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { | |
49 | fTableViewer= (TableViewer) viewer; | |
50 | fSearchResult= (AbstractTextSearchResult) newInput; | |
51 | } | |
52 | ||
53 | public void elementsChanged(Object[] updatedElements) { | |
54 | //TODO: copied from JavaSearchTableContentProvider | |
55 | for (int i= 0; i < updatedElements.length; i++) { | |
56 | if (fSearchResult.getMatchCount(updatedElements[i]) > 0) { | |
57 | if (fTableViewer.testFindItem(updatedElements[i]) != null) | |
58 | fTableViewer.refresh(updatedElements[i]); | |
59 | else | |
60 | fTableViewer.add(updatedElements[i]); | |
61 | } else { | |
62 | fTableViewer.remove(updatedElements[i]); | |
63 | } | |
64 | } | |
65 | } | |
66 | ||
67 | public void clear() { | |
68 | //TODO: copied from JavaSearchTableContentProvider | |
69 | fTableViewer.refresh(); | |
70 | } | |
71 | } |