| /******************************************************************************* |
| * Copyright (c) 2000, 2005 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| |
| package org.eclipse.jdt.internal.ui.search; |
| |
| import org.eclipse.jdt.core.IJavaElement; |
| import org.eclipse.jdt.core.JavaModelException; |
| import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; |
| import org.eclipse.jface.viewers.TableViewer; |
| import org.eclipse.jface.viewers.TreeViewer; |
| import org.eclipse.search.ui.text.AbstractTextSearchViewPage; |
| import org.eclipse.search.ui.text.Match; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.PartInitException; |
| import org.eclipse.ui.texteditor.ITextEditor; |
| |
| |
| public class OccurrencesSearchResultPage extends AbstractTextSearchViewPage { |
| |
| private TextSearchTableContentProvider fContentProvider; |
| |
| public OccurrencesSearchResultPage() { |
| super(AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT); |
| } |
| |
| /* |
| * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int) |
| */ |
| protected void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException { |
| IEditorPart editor= null; |
| JavaElementLine element= (JavaElementLine) match.getElement(); |
| IJavaElement javaElement= element.getJavaElement(); |
| try { |
| editor= EditorUtility.openInEditor(javaElement, false); |
| } catch (PartInitException e1) { |
| return; |
| } catch (JavaModelException e1) { |
| return; |
| } |
| |
| if (editor != null && activate) |
| editor.getEditorSite().getPage().activate(editor); |
| if (editor instanceof ITextEditor) { |
| ITextEditor textEditor= (ITextEditor) editor; |
| textEditor.selectAndReveal(currentOffset, currentLength); |
| } |
| } |
| |
| /* |
| * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#elementsChanged(java.lang.Object[]) |
| */ |
| protected void elementsChanged(Object[] objects) { |
| if (fContentProvider != null) |
| fContentProvider.elementsChanged(objects); |
| } |
| |
| /* |
| * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#clear() |
| */ |
| protected void clear() { |
| if (fContentProvider != null) |
| fContentProvider.clear(); |
| } |
| |
| /* |
| * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTreeViewer(org.eclipse.jface.viewers.TreeViewer) |
| */ |
| protected void configureTreeViewer(TreeViewer viewer) { |
| throw new IllegalStateException("Doesn't support tree mode."); //$NON-NLS-1$ |
| } |
| |
| /* |
| * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#configureTableViewer(org.eclipse.jface.viewers.TableViewer) |
| */ |
| protected void configureTableViewer(TableViewer viewer) { |
| viewer.setSorter(new JavaElementLineSorter()); |
| viewer.setLabelProvider(new OccurrencesSearchLabelProvider(this)); |
| fContentProvider= new TextSearchTableContentProvider(); |
| viewer.setContentProvider(fContentProvider); |
| } |
| |
| } |