1 11 package org.eclipse.pde.internal.ui.search.dependencies; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.core.IType; 15 import org.eclipse.jdt.core.JavaModelException; 16 import org.eclipse.jdt.ui.JavaElementLabelProvider; 17 import org.eclipse.jdt.ui.actions.FindReferencesInWorkingSetAction; 18 import org.eclipse.jdt.ui.actions.JavaSearchActionGroup; 19 import org.eclipse.jface.action.Action; 20 import org.eclipse.jface.action.IMenuManager; 21 import org.eclipse.jface.action.Separator; 22 import org.eclipse.jface.viewers.ILabelProvider; 23 import org.eclipse.jface.viewers.IStructuredSelection; 24 import org.eclipse.jface.viewers.ViewerComparator; 25 import org.eclipse.pde.core.plugin.IPluginExtension; 26 import org.eclipse.pde.core.plugin.IPluginExtensionPoint; 27 import org.eclipse.pde.core.plugin.IPluginObject; 28 import org.eclipse.pde.internal.ui.PDEPlugin; 29 import org.eclipse.pde.internal.ui.PDEUIMessages; 30 import org.eclipse.pde.internal.ui.search.AbstractSearchResultPage; 31 import org.eclipse.pde.internal.ui.search.ManifestEditorOpener; 32 import org.eclipse.pde.internal.ui.search.PluginSearchActionGroup; 33 import org.eclipse.search.ui.text.Match; 34 import org.eclipse.swt.graphics.Image; 35 import org.eclipse.ui.IWorkingSet; 36 import org.eclipse.ui.IWorkingSetManager; 37 import org.eclipse.ui.PartInitException; 38 import org.eclipse.ui.PlatformUI; 39 import org.eclipse.ui.actions.ActionContext; 40 41 42 public class DependencyExtentSearchResultPage extends 43 AbstractSearchResultPage { 44 45 46 class Comparator extends ViewerComparator { 47 50 public int category(Object element) { 51 try { 52 if (element instanceof IType) { 53 if (((IType)element).isClass()) 54 return 1; 55 return 0; 56 } 57 } catch (JavaModelException e) { 58 } 59 return 2; 60 } 61 } 62 63 class LabelProvider extends JavaElementLabelProvider { 64 67 public Image getImage(Object element) { 68 if (element instanceof IPluginObject) 69 return PDEPlugin.getDefault().getLabelProvider().getImage(element); 70 return super.getImage(element); 71 } 72 73 76 public String getText(Object element) { 77 if (element instanceof IPluginExtensionPoint) 78 return ((IPluginExtensionPoint) element).getFullId(); 79 80 if (element instanceof IPluginExtension) 81 return ((IPluginExtension)element).getPoint(); 82 83 if (element instanceof IJavaElement) { 84 IJavaElement javaElement = (IJavaElement) element; 85 String text = 86 super.getText(javaElement) 87 + " - " + javaElement 89 .getAncestor(IJavaElement.PACKAGE_FRAGMENT) 90 .getElementName(); 91 if (!(javaElement instanceof IType)) { 92 IJavaElement ancestor = javaElement.getAncestor(IJavaElement.TYPE); 93 if (ancestor == null) 94 ancestor = javaElement.getAncestor(IJavaElement.CLASS_FILE); 95 if (ancestor == null) 96 ancestor = javaElement.getAncestor(IJavaElement.COMPILATION_UNIT); 97 if (ancestor != null) 98 text += "." + ancestor.getElementName(); } 100 return text; 101 } 102 return super.getText(element); 103 } 104 } 105 106 public DependencyExtentSearchResultPage() { 107 PDEPlugin.getDefault().getLabelProvider().connect(this); 108 } 109 110 113 public void dispose() { 114 PDEPlugin.getDefault().getLabelProvider().disconnect(this); 115 super.dispose(); 116 } 117 118 121 protected void fillContextMenu(IMenuManager mgr) { 122 super.fillContextMenu(mgr); 123 mgr.add(new Separator()); 124 JavaSearchActionGroup group = new JavaSearchActionGroup(this); 125 group.setContext(new ActionContext(getViewer().getSelection())); 126 group.fillContextMenu(mgr); 127 addJavaSearchGroup(mgr); 128 PluginSearchActionGroup actionGroup = new PluginSearchActionGroup(); 129 actionGroup.setContext(new ActionContext(getViewer().getSelection())); 130 actionGroup.fillContextMenu(mgr); 131 } 132 133 private void addJavaSearchGroup(IMenuManager mgr) { 134 IStructuredSelection ssel = (IStructuredSelection)getViewer().getSelection(); 135 if (ssel.size() == 1) { 136 final Object object = ssel.getFirstElement(); 137 if (object instanceof IType) { 138 mgr.add(new Separator()); 139 mgr.add(new Action(PDEUIMessages.DependencyExtentSearchResultPage_referencesInPlugin) { 140 public void run() { 141 DependencyExtentQuery query = (DependencyExtentQuery)getInput().getQuery(); 142 IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager(); 143 IWorkingSet set = manager.createWorkingSet("temp", query.getDirectRoots()); new FindReferencesInWorkingSetAction(getViewPart().getSite(), new IWorkingSet[] {set}).run((IType)object); 145 manager.removeWorkingSet(set); 146 } 147 }); 148 } 149 } 150 } 151 152 155 protected void showMatch(Match match, int currentOffset, int currentLength, 156 boolean activate) throws PartInitException { 157 if (match.getElement() instanceof IPluginObject) { 158 ManifestEditorOpener.open(match, activate); 159 } else { 160 try { 161 JavaEditorOpener.open(match, currentOffset, currentLength, activate); 162 } catch (PartInitException e) { 163 } catch (JavaModelException e) { 164 } 165 } 166 } 167 168 171 protected ILabelProvider createLabelProvider() { 172 return new LabelProvider(); 173 } 174 175 178 protected ViewerComparator createViewerComparator() { 179 return new Comparator(); 180 } 181 182 } 183 | Popular Tags |