1 11 package org.eclipse.ui.part; 12 13 import org.eclipse.core.resources.IFile; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.ui.IElementFactory; 18 import org.eclipse.ui.IMemento; 19 20 29 public class FileEditorInputFactory implements IElementFactory { 30 34 private static final String ID_FACTORY = "org.eclipse.ui.part.FileEditorInputFactory"; 36 39 private static final String TAG_PATH = "path"; 41 44 public FileEditorInputFactory() { 45 } 46 47 50 public IAdaptable createElement(IMemento memento) { 51 String fileName = memento.getString(TAG_PATH); 53 if (fileName == null) { 54 return null; 55 } 56 57 IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile( 60 new Path(fileName)); 61 if (file != null) { 62 return new FileEditorInput(file); 63 } else { 64 return null; 65 } 66 } 67 68 73 public static String getFactoryId() { 74 return ID_FACTORY; 75 } 76 77 83 public static void saveState(IMemento memento, FileEditorInput input) { 84 IFile file = input.getFile(); 85 memento.putString(TAG_PATH, file.getFullPath().toString()); 86 } 87 } 88 | Popular Tags |