1 11 package org.eclipse.jdt.internal.ui.workingsets; 12 13 import org.eclipse.core.runtime.IAdaptable; 14 15 import org.eclipse.ui.IElementFactory; 16 import org.eclipse.ui.IMemento; 17 import org.eclipse.ui.IPersistableElement; 18 import org.eclipse.ui.PlatformUI; 19 20 public class Mementos { 21 22 public static final String TAG_FACTORY_ID = "factoryID"; public static final String TAG_ITEM = "item"; 25 public static void saveItem(IMemento memento, IAdaptable element) { 26 IPersistableElement persistable= (IPersistableElement)element.getAdapter(IPersistableElement.class); 27 if (persistable != null) { 28 memento.putString( 29 TAG_FACTORY_ID, 30 persistable.getFactoryId()); 31 persistable.saveState(memento); 32 } 33 34 } 35 36 public static IAdaptable restoreItem(IMemento memento) { 37 return restoreItem(memento, TAG_FACTORY_ID); 38 } 39 40 public static IAdaptable restoreItem(IMemento memento, String factoryTag) { 41 if (memento == null) 42 return null; 43 String factoryID = memento.getString(factoryTag); 44 if (factoryID == null) return null; 45 IElementFactory factory = PlatformUI.getWorkbench().getElementFactory(factoryID); 46 if (factory == null) return null; 47 return factory.createElement(memento); 48 } 49 } 50 | Popular Tags |