1 11 package org.eclipse.jdt.internal.ui.search; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.PlatformObject; 16 import org.eclipse.jdt.core.IJavaElement; 17 import org.eclipse.jdt.core.JavaCore; 18 import org.eclipse.jdt.internal.ui.JavaPlugin; 19 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 20 import org.eclipse.jdt.internal.ui.util.SelectionUtil; 21 import org.eclipse.jface.action.MenuManager; 22 import org.eclipse.jface.util.Assert; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.ISelectionChangedListener; 25 import org.eclipse.jface.viewers.ISelectionProvider; 26 import org.eclipse.jface.viewers.SelectionChangedEvent; 27 import org.eclipse.jface.viewers.StructuredSelection; 28 import org.eclipse.search.ui.ISearchResultViewEntry; 29 import org.eclipse.swt.widgets.Shell; 30 import org.eclipse.ui.IKeyBindingService; 31 import org.eclipse.ui.IWorkbenchPage; 32 import org.eclipse.ui.IWorkbenchPartSite; 33 import org.eclipse.ui.IWorkbenchSite; 34 import org.eclipse.ui.IWorkbenchWindow; 35 36 43 class SearchViewSiteAdapter extends PlatformObject implements IWorkbenchPartSite { 44 45 private ISelectionProvider fProvider; 46 private IWorkbenchSite fSite; 47 48 private ISelectionChangedListener fListener; 49 50 public SearchViewSiteAdapter(IWorkbenchSite site){ 51 fSite= site; 52 setSelectionProvider(site.getSelectionProvider()); 53 } 54 55 public IWorkbenchPage getPage() { 56 return fSite.getPage(); 57 } 58 59 public ISelectionProvider getSelectionProvider() { 60 return fProvider; 61 } 62 63 public Shell getShell() { 64 return JavaPlugin.getActiveWorkbenchShell(); 65 } 66 67 public IWorkbenchWindow getWorkbenchWindow() { 68 return fSite.getWorkbenchWindow(); 69 } 70 71 public void setSelectionProvider(final ISelectionProvider provider) { 72 Assert.isNotNull(provider); 73 fProvider= 74 new ISelectionProvider() { 75 public void addSelectionChangedListener(final ISelectionChangedListener listener) { 76 fListener= 77 new ISelectionChangedListener() { 78 public void selectionChanged(SelectionChangedEvent event) { 79 listener.selectionChanged(new SelectionChangedEvent(fProvider, convertSelection(event.getSelection()))); 80 } 81 }; 82 provider.addSelectionChangedListener(fListener); 83 } 84 public ISelection getSelection() { 85 return convertSelection(provider.getSelection()); 86 } 87 public void removeSelectionChangedListener(ISelectionChangedListener listener) { 88 provider.removeSelectionChangedListener(fListener); 89 } 90 public void setSelection(ISelection selection) { 91 } 92 }; 93 } 94 95 private ISelection convertSelection(ISelection selection) { 96 Object element= SelectionUtil.getSingleElement(selection); 97 if (element instanceof ISearchResultViewEntry) { 98 IMarker marker= ((ISearchResultViewEntry)element).getSelectedMarker(); 99 if (marker != null && marker.exists()) 100 try { 101 IJavaElement je= JavaCore.create((String )marker.getAttribute(IJavaSearchUIConstants.ATT_JE_HANDLE_ID)); 102 if (je != null) 103 return new StructuredSelection(je); 104 } catch (CoreException ex) { 105 ExceptionHandler.log(ex, SearchMessages.getString("Search.Error.createJavaElement.message")); } 107 } 108 return StructuredSelection.EMPTY; 109 } 110 111 113 116 public String getId() { 117 return null; 118 } 119 120 123 public IKeyBindingService getKeyBindingService() { 124 return null; 125 } 126 127 130 public String getPluginId() { 131 return null; 132 } 133 134 137 public String getRegisteredName() { 138 return null; 139 } 140 141 144 public void registerContextMenu(MenuManager menuManager, ISelectionProvider selectionProvider) { 145 } 146 147 150 public void registerContextMenu(String menuId, MenuManager menuManager, ISelectionProvider selectionProvider) { 151 } 152 } 153 | Popular Tags |