1 11 package org.eclipse.jdt.internal.ui; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IAdapterFactory; 15 16 import org.eclipse.ui.IEditorInput; 17 import org.eclipse.ui.IStorageEditorInput; 18 19 import org.eclipse.search.ui.ISearchPageScoreComputer; 20 21 import org.eclipse.jdt.core.IJavaElement; 22 23 import org.eclipse.jdt.ui.JavaUI; 24 25 import org.eclipse.jdt.internal.ui.search.JavaSearchPageScoreComputer; 26 import org.eclipse.jdt.internal.ui.search.SearchUtil; 27 28 31 public class EditorInputAdapterFactory implements IAdapterFactory { 32 33 private static Class [] PROPERTIES= new Class [] {IJavaElement.class}; 34 35 private Object fSearchPageScoreComputer; 36 37 public Class [] getAdapterList() { 38 updateLazyLoadedAdapters(); 39 return PROPERTIES; 40 } 41 42 public Object getAdapter(Object element, Class key) { 43 updateLazyLoadedAdapters(); 44 if (fSearchPageScoreComputer != null && ISearchPageScoreComputer.class.equals(key)) 45 return fSearchPageScoreComputer; 46 47 if (IJavaElement.class.equals(key) && element instanceof IEditorInput) { 48 IJavaElement je= JavaUI.getWorkingCopyManager().getWorkingCopy((IEditorInput)element); 49 if (je != null) 50 return je; 51 if (element instanceof IStorageEditorInput) { 52 try { 53 return ((IStorageEditorInput)element).getStorage().getAdapter(key); 54 } catch (CoreException ex) { 55 } 57 } 58 } 59 return null; 60 } 61 62 private void updateLazyLoadedAdapters() { 63 if (fSearchPageScoreComputer == null && SearchUtil.isSearchPlugInActivated()) 64 createSearchPageScoreComputer(); 65 } 66 67 private void createSearchPageScoreComputer() { 68 fSearchPageScoreComputer= new JavaSearchPageScoreComputer(); 69 PROPERTIES= new Class [] {ISearchPageScoreComputer.class, IJavaElement.class}; 70 } 71 } 72 | Popular Tags |