1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IAdaptable; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.ILaunchConfiguration; 18 import org.eclipse.debug.core.ILaunchManager; 19 import org.eclipse.ui.IElementFactory; 20 import org.eclipse.ui.IMemento; 21 import org.eclipse.ui.IPersistableElement; 22 23 31 public class PersistableLaunchConfigurationFactory implements IPersistableElement, IElementFactory { 32 33 private ILaunchConfiguration fConfig; 34 35 private static final String KEY = "launchConfigMemento"; private static final String FACTORY_ID = "org.eclipse.debug.ui.PersistableLaunchConfigurationFactory"; 38 public PersistableLaunchConfigurationFactory() { 39 } 40 41 public PersistableLaunchConfigurationFactory(ILaunchConfiguration config) { 42 setConfig(config); 43 } 44 45 48 public String getFactoryId() { 49 return FACTORY_ID; 50 } 51 52 55 public void saveState(IMemento memento) { 56 try { 57 String configMemento = getConfig().getMemento(); 58 memento.putString(KEY, configMemento); 59 } catch (CoreException ce) { 60 } 61 } 62 63 66 public IAdaptable createElement(IMemento memento) { 67 try { 68 String launchConfigMemento = memento.getString(KEY); 69 return getLaunchManager().getLaunchConfiguration(launchConfigMemento); 70 } catch (CoreException ce) { 71 } 72 return null; 73 } 74 75 private void setConfig(ILaunchConfiguration config) { 76 fConfig = config; 77 } 78 79 private ILaunchConfiguration getConfig() { 80 return fConfig; 81 } 82 83 private ILaunchManager getLaunchManager() { 84 return DebugPlugin.getDefault().getLaunchManager(); 85 } 86 87 } 88 | Popular Tags |