KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > PersistableLaunchConfigurationFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
24  * This is a combination factory and persistable element for launch configurations.
25  * This is necessary because the IPersistableElement/IElementFactory framework used by
26  * the platform working set support live in the UI plugin. Launch configurations are
27  * defined in a non-UI plugin, thus we need this class to handle persistence and
28  * recreation on behalf of launch configs.
29  *
30  */

31 public class PersistableLaunchConfigurationFactory implements IPersistableElement, IElementFactory {
32
33     private ILaunchConfiguration fConfig;
34     
35     private static final String JavaDoc KEY = "launchConfigMemento"; //$NON-NLS-1$
36
private static final String JavaDoc FACTORY_ID = "org.eclipse.debug.ui.PersistableLaunchConfigurationFactory"; //$NON-NLS-1$
37

38     public PersistableLaunchConfigurationFactory() {
39     }
40
41     public PersistableLaunchConfigurationFactory(ILaunchConfiguration config) {
42         setConfig(config);
43     }
44
45     /**
46      * @see org.eclipse.ui.IPersistableElement#getFactoryId()
47      */

48     public String JavaDoc getFactoryId() {
49         return FACTORY_ID;
50     }
51
52     /**
53      * @see org.eclipse.ui.IPersistableElement#saveState(IMemento)
54      */

55     public void saveState(IMemento memento) {
56         try {
57             String JavaDoc configMemento = getConfig().getMemento();
58             memento.putString(KEY, configMemento);
59         } catch (CoreException ce) {
60         }
61     }
62
63     /**
64      * @see org.eclipse.ui.IElementFactory#createElement(IMemento)
65      */

66     public IAdaptable createElement(IMemento memento) {
67         try {
68             String JavaDoc 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