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.action.IMenuManager;
013: import org.eclipse.jface.action.Separator;
014: import org.eclipse.jface.viewers.ILabelProvider;
015: import org.eclipse.jface.viewers.IStructuredSelection;
016: import org.eclipse.jface.viewers.LabelProvider;
017: import org.eclipse.jface.viewers.ViewerComparator;
018: import org.eclipse.pde.core.plugin.IPluginBase;
019: import org.eclipse.pde.core.plugin.IPluginExtension;
020: import org.eclipse.pde.core.plugin.IPluginExtensionPoint;
021: import org.eclipse.pde.core.plugin.IPluginImport;
022: import org.eclipse.pde.internal.ui.PDEPlugin;
023: import org.eclipse.pde.internal.ui.views.plugins.ImportActionGroup;
024: import org.eclipse.pde.internal.ui.views.plugins.JavaSearchActionGroup;
025: import org.eclipse.search.ui.text.Match;
026: import org.eclipse.swt.graphics.Image;
027: import org.eclipse.ui.PartInitException;
028: import org.eclipse.ui.actions.ActionContext;
029:
030: public class PluginSearchResultPage extends AbstractSearchResultPage {
031:
032: class SearchLabelProvider extends LabelProvider {
033: /* (non-Javadoc)
034: * @see org.eclipse.jface.viewers.LabelProvider#getImage(java.lang.Object)
035: */
036: public Image getImage(Object element) {
037: return PDEPlugin.getDefault().getLabelProvider().getImage(
038: element);
039: }
040:
041: /* (non-Javadoc)
042: * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
043: */
044: public String getText(Object object) {
045: if (object instanceof IPluginBase)
046: return ((IPluginBase) object).getId();
047:
048: if (object instanceof IPluginImport) {
049: IPluginImport dep = (IPluginImport) object;
050: return dep.getId() + " - " //$NON-NLS-1$
051: + dep.getPluginBase().getId();
052: }
053:
054: if (object instanceof IPluginExtension) {
055: IPluginExtension extension = (IPluginExtension) object;
056: return extension.getPoint()
057: + " - " + extension.getPluginBase().getId(); //$NON-NLS-1$
058: }
059:
060: if (object instanceof IPluginExtensionPoint)
061: return ((IPluginExtensionPoint) object).getFullId();
062:
063: return PDEPlugin.getDefault().getLabelProvider().getText(
064: object);
065: }
066: }
067:
068: public PluginSearchResultPage() {
069: super ();
070: PDEPlugin.getDefault().getLabelProvider().connect(this );
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#fillContextMenu(org.eclipse.jface.action.IMenuManager)
075: */
076: protected void fillContextMenu(IMenuManager mgr) {
077: super .fillContextMenu(mgr);
078: mgr.add(new Separator());
079: IStructuredSelection selection = (IStructuredSelection) getViewer()
080: .getSelection();
081: ActionContext context = new ActionContext(selection);
082: PluginSearchActionGroup actionGroup = new PluginSearchActionGroup();
083: actionGroup.setContext(context);
084: actionGroup.fillContextMenu(mgr);
085: if (ImportActionGroup.canImport(selection)) {
086: mgr.add(new Separator());
087: ImportActionGroup importActionGroup = new ImportActionGroup();
088: importActionGroup.setContext(context);
089: importActionGroup.fillContextMenu(mgr);
090: }
091: mgr.add(new Separator());
092:
093: JavaSearchActionGroup jsActionGroup = new JavaSearchActionGroup();
094: jsActionGroup.setContext(new ActionContext(selection));
095: jsActionGroup.fillContextMenu(mgr);
096: }
097:
098: /* (non-Javadoc)
099: * @see org.eclipse.pde.internal.ui.search.AbstractSearchResultPage#createLabelProvider()
100: */
101: protected ILabelProvider createLabelProvider() {
102: return new SearchLabelProvider();
103: }
104:
105: /* (non-Javadoc)
106: * @see org.eclipse.pde.internal.ui.search.AbstractSearchResultPage#createViewerSorter()
107: */
108: protected ViewerComparator createViewerComparator() {
109: return new ViewerComparator();
110: }
111:
112: /* (non-Javadoc)
113: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#showMatch(org.eclipse.search.ui.text.Match, int, int, boolean)
114: */
115: protected void showMatch(Match match, int currentOffset,
116: int currentLength, boolean activate)
117: throws PartInitException {
118: ManifestEditorOpener.open(match, activate);
119: }
120:
121: /* (non-Javadoc)
122: * @see org.eclipse.search.ui.text.AbstractTextSearchViewPage#dispose()
123: */
124: public void dispose() {
125: PDEPlugin.getDefault().getLabelProvider().disconnect(this);
126: super.dispose();
127: }
128:
129: }
|