1 11 package org.eclipse.jdt.internal.ui.javaeditor; 12 13 14 import org.eclipse.core.runtime.IAdaptable; 15 16 import org.eclipse.ui.IElementFactory; 17 import org.eclipse.ui.IMemento; 18 19 import org.eclipse.jdt.core.IClassFile; 20 import org.eclipse.jdt.core.IJavaElement; 21 import org.eclipse.jdt.core.IJavaProject; 22 import org.eclipse.jdt.core.IType; 23 import org.eclipse.jdt.core.JavaCore; 24 import org.eclipse.jdt.core.JavaModelException; 25 26 import org.eclipse.jdt.internal.corext.util.JavaModelUtil; 27 28 32 public class ClassFileEditorInputFactory implements IElementFactory { 33 34 public final static String ID= "org.eclipse.jdt.ui.ClassFileEditorInputFactory"; public final static String KEY= "org.eclipse.jdt.ui.ClassFileIdentifier"; 37 public ClassFileEditorInputFactory() { 38 } 39 40 43 public IAdaptable createElement(IMemento memento) { 44 String identifier= memento.getString(KEY); 45 if (identifier == null) 46 return null; 47 48 IJavaElement element= JavaCore.create(identifier); 49 try { 50 if (!element.exists() && element instanceof IClassFile) { 51 55 IClassFile cf= (IClassFile)element; 56 IType type= cf.getType(); IJavaProject project= element.getJavaProject(); 58 if (project != null) { 59 type= JavaModelUtil.findType(project, type.getFullyQualifiedName()); 60 if (type == null) 61 return null; 62 element= type.getParent(); 63 } 64 } 65 return EditorUtility.getEditorInput(element); 66 } catch (JavaModelException x) { 67 return null; 69 } 70 } 71 72 public static void saveState(IMemento memento, InternalClassFileEditorInput input) { 73 IClassFile c= input.getClassFile(); 74 memento.putString(KEY, c.getHandleIdentifier()); 75 } 76 } 77 | Popular Tags |