KickJava   Java API By Example, From Geeks To Geeks.

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


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.IAdaptable;
15 import org.eclipse.debug.core.DebugPlugin;
16 import org.eclipse.debug.core.ILaunchConfigurationType;
17 import org.eclipse.debug.core.ILaunchManager;
18 import org.eclipse.ui.IElementFactory;
19 import org.eclipse.ui.IMemento;
20 import org.eclipse.ui.IPersistableElement;
21
22 /**
23  * This is a combination factory and persistable element for launch configuration types.
24  * This is necessary because the IPersistableElement/IElementFactory framework used by
25  * the platform working set support live in the UI plugin. Launch configuration types are
26  * defined in a non-UI plugin, thus we need this class to handle persistence and
27  * recreation on behalf of launch config types.
28  *
29  */

30 public class PersistableLaunchConfigurationTypeFactory implements IPersistableElement, IElementFactory {
31
32     private ILaunchConfigurationType fConfigType;
33
34     private static final String JavaDoc KEY = "launchConfigTypeID"; //$NON-NLS-1$
35
private static final String JavaDoc FACTORY_ID = "org.eclipse.debug.ui.PersistableLaunchConfigurationTypeFactory"; //$NON-NLS-1$
36

37     public PersistableLaunchConfigurationTypeFactory() {
38     }
39
40     public PersistableLaunchConfigurationTypeFactory(ILaunchConfigurationType configType) {
41         setConfigType(configType);
42     }
43
44     /**
45      * @see org.eclipse.ui.IPersistableElement#getFactoryId()
46      */

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

54     public void saveState(IMemento memento) {
55         String JavaDoc configTypeID = getConfigType().getIdentifier();
56         memento.putString(KEY, configTypeID);
57     }
58
59     /**
60      * @see org.eclipse.ui.IElementFactory#createElement(IMemento)
61      */

62     public IAdaptable createElement(IMemento memento) {
63         String JavaDoc configTypeID = memento.getString(KEY);
64         return getLaunchManager().getLaunchConfigurationType(configTypeID);
65     }
66
67     private void setConfigType(ILaunchConfigurationType configType) {
68         fConfigType = configType;
69     }
70
71     private ILaunchConfigurationType getConfigType() {
72         return fConfigType;
73     }
74
75     private ILaunchManager getLaunchManager() {
76         return DebugPlugin.getDefault().getLaunchManager();
77     }
78
79 }
80
Popular Tags