KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > EditorInputAdapterFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
29  * Adapter factory to support basic UI operations for for editor inputs.
30  */

31 public class EditorInputAdapterFactory implements IAdapterFactory {
32     
33     private static Class JavaDoc[] PROPERTIES= new Class JavaDoc[] {IJavaElement.class};
34     
35     private Object JavaDoc fSearchPageScoreComputer;
36
37     public Class JavaDoc[] getAdapterList() {
38         updateLazyLoadedAdapters();
39         return PROPERTIES;
40     }
41
42     public Object JavaDoc getAdapter(Object JavaDoc element, Class JavaDoc 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                     // Fall through
56
}
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 JavaDoc[] {ISearchPageScoreComputer.class, IJavaElement.class};
70     }
71 }
72
Popular Tags