1 11 package org.eclipse.pde.internal.ui.search; 12 13 import org.eclipse.jface.action.IMenuManager; 14 import org.eclipse.jface.action.Separator; 15 import org.eclipse.jface.viewers.ILabelProvider; 16 import org.eclipse.jface.viewers.IStructuredSelection; 17 import org.eclipse.jface.viewers.LabelProvider; 18 import org.eclipse.jface.viewers.ViewerComparator; 19 import org.eclipse.pde.core.plugin.IPluginBase; 20 import org.eclipse.pde.core.plugin.IPluginExtension; 21 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 22 import org.eclipse.pde.core.plugin.IPluginImport; 23 import org.eclipse.pde.internal.ui.PDEPlugin; 24 import org.eclipse.pde.internal.ui.views.plugins.ImportActionGroup; 25 import org.eclipse.pde.internal.ui.views.plugins.JavaSearchActionGroup; 26 import org.eclipse.search.ui.text.Match; 27 import org.eclipse.swt.graphics.Image; 28 import org.eclipse.ui.PartInitException; 29 import org.eclipse.ui.actions.ActionContext; 30 31 32 public class PluginSearchResultPage extends AbstractSearchResultPage { 33 34 class SearchLabelProvider extends LabelProvider { 35 38 public Image getImage(Object element) { 39 return PDEPlugin.getDefault().getLabelProvider().getImage(element); 40 } 41 42 45 public String getText(Object object) { 46 if (object instanceof IPluginBase) 47 return ((IPluginBase)object).getId(); 48 49 if (object instanceof IPluginImport) { 50 IPluginImport dep = (IPluginImport)object; 51 return dep.getId() 52 + " - " + dep.getPluginBase().getId(); 54 } 55 56 if (object instanceof IPluginExtension) { 57 IPluginExtension extension = (IPluginExtension)object; 58 return extension.getPoint() + " - " + extension.getPluginBase().getId(); } 60 61 if (object instanceof IPluginExtensionPoint) 62 return ((IPluginExtensionPoint)object).getFullId(); 63 64 return PDEPlugin.getDefault().getLabelProvider().getText(object); 65 } 66 } 67 68 public PluginSearchResultPage() { 69 super(); 70 PDEPlugin.getDefault().getLabelProvider().connect(this); 71 } 72 75 protected void fillContextMenu(IMenuManager mgr) { 76 super.fillContextMenu(mgr); 77 mgr.add(new Separator()); 78 IStructuredSelection selection = (IStructuredSelection)getViewer().getSelection(); 79 ActionContext context = new ActionContext(selection); 80 PluginSearchActionGroup actionGroup = new PluginSearchActionGroup(); 81 actionGroup.setContext(context); 82 actionGroup.fillContextMenu(mgr); 83 if (ImportActionGroup.canImport(selection)) { 84 mgr.add(new Separator()); 85 ImportActionGroup importActionGroup = new ImportActionGroup(); 86 importActionGroup.setContext(context); 87 importActionGroup.fillContextMenu(mgr); 88 } 89 mgr.add(new Separator()); 90 91 JavaSearchActionGroup jsActionGroup = new JavaSearchActionGroup(); 92 jsActionGroup.setContext(new ActionContext(selection)); 93 jsActionGroup.fillContextMenu(mgr); 94 } 95 96 99 protected ILabelProvider createLabelProvider() { 100 return new SearchLabelProvider(); 101 } 102 103 106 protected ViewerComparator createViewerComparator() { 107 return new ViewerComparator(); 108 } 109 110 113 protected void showMatch(Match match, int currentOffset, int currentLength, 114 boolean activate) throws PartInitException { 115 ManifestEditorOpener.open(match, activate); 116 } 117 118 121 public void dispose() { 122 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 123 super.dispose(); 124 } 125 126 } 127 | Popular Tags |