1 11 package org.eclipse.jdt.internal.ui; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 import org.eclipse.jdt.core.IJavaElement; 15 import org.eclipse.jdt.core.JavaCore; 16 import org.eclipse.ui.IElementFactory; 17 import org.eclipse.ui.IMemento; 18 import org.eclipse.ui.IPersistableElement; 19 20 29 public class PersistableJavaElementFactory implements IElementFactory, IPersistableElement { 30 31 private static final String KEY= "elementID"; private static final String FACTORY_ID= "org.eclipse.jdt.ui.PersistableJavaElementFactory"; 34 private IJavaElement fElement; 35 36 39 public PersistableJavaElementFactory() { 40 } 41 42 46 public PersistableJavaElementFactory(IJavaElement element) { 47 fElement= element; 48 } 49 50 53 public IAdaptable createElement(IMemento memento) { 54 55 String identifier= memento.getString(KEY); 56 if (identifier != null) { 57 return JavaCore.create(identifier); 58 } 59 return null; 60 } 61 62 65 public String getFactoryId() { 66 return FACTORY_ID; 67 } 68 71 public void saveState(IMemento memento) { 72 memento.putString(KEY, fElement.getHandleIdentifier()); 73 } 74 } 75 | Popular Tags |