001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.search;
011:
012: import org.eclipse.jface.viewers.ILabelProvider;
013: import org.eclipse.jface.viewers.IStructuredContentProvider;
014: import org.eclipse.jface.viewers.TableViewer;
015: import org.eclipse.jface.viewers.TreeViewer;
016: import org.eclipse.jface.viewers.Viewer;
017: import org.eclipse.jface.viewers.ViewerComparator;
018: import org.eclipse.search.ui.text.AbstractTextSearchResult;
019: import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
020:
021: public abstract class AbstractSearchResultPage extends
022: AbstractTextSearchViewPage {
023:
024: class ContentProvider implements IStructuredContentProvider {
025:
026: private TableViewer fTableViewer;
027: private AbstractTextSearchResult fSearchResult;
028:
029: /* (non-Javadoc)
030: * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
031: */
032: public Object[] getElements(Object inputElement) {
033: if (inputElement instanceof AbstractTextSearchResult)
034: return ((AbstractTextSearchResult) inputElement)
035: .getElements();
036: return new Object[0];
037: }
038:
039: /* (non-Javadoc)
040: * @see org.eclipse.jface.viewers.IContentProvider#dispose()
041: */
042: public void dispose() {
043: }
044:
045: /* (non-Javadoc)
046: * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
047: */
048: public void inputChanged(Viewer viewer, Object oldInput,
049: Object newInput) {
050: fTableViewer = (TableViewer) viewer;
051: fSearchResult = (AbstractTextSearchResult) newInput;
052: }
053:
054: public void clear() {
055: fTableViewer.refresh();
056: }
057:
058: public void elementsChanged(Object[] updatedElements) {
059: for (int i = 0; i < updatedElements.length; i++) {
060: if (fSearchResult.getMatchCount(updatedElements[i]) > 0) {
061: if (fTableViewer.testFindItem(updatedElements[i]) != null)
062: fTableViewer.refresh(updatedElements[i]);
063: else
064: fTableViewer.add(updatedElements[i]);
065: } else {
066: fTableViewer.remove(updatedElements[i]);
067: }
068: }
069: }
070: }
071:
072: private ContentProvider fContentProvider;
073:
074: public AbstractSearchResultPage() {
075: super (AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT);
076: }
077:
078: /* (non-Javadoc)
079: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[])
080: */
081: protected void elementsChanged(Object[] objects) {
082: if (fContentProvider != null
083: && fContentProvider.fSearchResult != null)
084: fContentProvider.elementsChanged(objects);
085: }
086:
087: /* (non-Javadoc)
088: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#clear()
089: */
090: protected void clear() {
091: if (fContentProvider != null)
092: fContentProvider.clear();
093: }
094:
095: /* (non-Javadoc)
096: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTreeViewer(org.eclipse.jface.viewers.TreeViewer)
097: */
098: protected void configureTreeViewer(TreeViewer viewer) {
099: throw new IllegalStateException("Doesn't support tree mode."); //$NON-NLS-1$
100: }
101:
102: /* (non-Javadoc)
103: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer)
104: */
105: protected void configureTableViewer(TableViewer viewer) {
106: viewer.setComparator(createViewerComparator());
107: viewer.setLabelProvider(createLabelProvider());
108: fContentProvider = new ContentProvider();
109: viewer.setContentProvider(fContentProvider);
110: }
111:
112: protected abstract ILabelProvider createLabelProvider();
113:
114: protected abstract ViewerComparator createViewerComparator();
115:
116: }
|