KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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 java.util.ArrayList JavaDoc;
15 import java.util.HashMap JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.Hashtable JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20 import java.util.Set JavaDoc;
21
22 import org.eclipse.core.runtime.CoreException;
23 import org.eclipse.core.runtime.IConfigurationElement;
24 import org.eclipse.debug.internal.core.IConfigurationElementConstants;
25 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
26
27
28 /**
29  * Proxy to a launch configuration tab group element
30  */

31 public class LaunchConfigurationTabGroupExtension {
32     
33     /**
34      * The configuration element defining this tab group.
35      */

36     private IConfigurationElement fConfig = null;
37     
38     /**
39      * A list of sets of modes that this tab group supports
40      * @since 3.3
41      */

42     private List JavaDoc fModes = null;
43     
44     /**
45      * A map of mode sets to descriptions
46      * @since 3.3
47      */

48     private Map JavaDoc fDescriptions = null;
49     
50     /**
51      * Perspectives for each mode
52      */

53     private Map JavaDoc fPerspectives = null;
54         
55     /**
56      * Constructs a launch configuration tab extension based
57      * on the given configuration element
58      *
59      * @param element the configuration element defining the
60      * attributes of this launch configuration tab extension
61      * @return a new launch configuration tab extension
62      */

63     public LaunchConfigurationTabGroupExtension(IConfigurationElement element) {
64         setConfigurationElement(element);
65     }
66     
67     /**
68      * Sets the configuration element that defines the attributes
69      * for this launch configuration tab group extension.
70      *
71      * @param element configuration element
72      */

73     private void setConfigurationElement(IConfigurationElement element) {
74         fConfig = element;
75     }
76     
77     /**
78      * Returns the configuration element that defines the attributes
79      * for this launch configuration tab group extension.
80      *
81      * @param configuration element that defines the attributes
82      * for this launch configuration tab extension
83      */

84     protected IConfigurationElement getConfigurationElement() {
85         return fConfig;
86     }
87     
88     /**
89      * Returns the set of modes specified in the configuration data, or <code>null</code>
90      * if none (i.e. default tab group)
91      *
92      * @return the set of modes specified in the configuration data, or
93      * <code>null</code>
94      */

95     protected List JavaDoc getModes() {
96         if (fModes == null) {
97             fModes = new ArrayList JavaDoc();
98             fPerspectives = new Hashtable JavaDoc();
99             IConfigurationElement[] modes = fConfig.getChildren(IConfigurationElementConstants.LAUNCH_MODE);
100             if (modes.length > 0) {
101                 IConfigurationElement element = null;
102                 String JavaDoc perspective = null, mode = null;
103                 Set JavaDoc mset = null;
104                 for (int i = 0; i < modes.length; i++) {
105                     element = modes[i];
106                     mode = element.getAttribute(IConfigurationElementConstants.MODE);
107                     mset = new HashSet JavaDoc();
108                     mset.add(mode);
109                     fModes.add(mset);
110                     perspective = element.getAttribute(IConfigurationElementConstants.PERSPECTIVE);
111                     if (perspective != null) {
112                         fPerspectives.put(mset, perspective);
113                     }
114                 }
115             }
116         }
117         return fModes;
118     }
119     
120     /**
121      * Returns the perspective associated with the given launch
122      * mode, as specified in plug-in XML, or <code>null</code> if none.
123      *
124      * @param modes the set of launch modes
125      * @return perspective identifier, or <code>null</code>
126      */

127     protected String JavaDoc getPerspective(Set JavaDoc modes) {
128         getModes();
129         return (String JavaDoc)fPerspectives.get(modes);
130     }
131     
132     /**
133      * Returns the identifier of the type of launch configuration this
134      * tab group is associated with
135      *
136      * @return the identifier of the type of launch configuration this
137      * tab group is associated with
138      */

139     protected String JavaDoc getTypeIdentifier() {
140         return getConfigurationElement().getAttribute(IConfigurationElementConstants.TYPE);
141     }
142     
143     /**
144      * Returns the identifier of the help context associated with this tab
145      * group, or <code>null</code> if one was not specified.
146      *
147      * @return the identifier of this tab group's help context or
148      * <code>null</code>
149      * @since 2.1
150      */

151     protected String JavaDoc getHelpContextId() {
152         return getConfigurationElement().getAttribute(IConfigurationElementConstants.HELP_CONTEXT_ID);
153     }
154     
155     /**
156      * Returns the identifier of the tab group
157      * @return the id of the tab group
158      *
159      * @since 3.3
160      */

161     protected String JavaDoc getIdentifier() {
162         return getConfigurationElement().getAttribute(IConfigurationElementConstants.ID);
163     }
164     
165     /**
166      * Returns a new tab group defined by this extension
167      *
168      * @return a new tab group defined by this extension
169      * @exception CoreException if an exception occurs instantiating
170      * the tab group
171      */

172     public ILaunchConfigurationTabGroup newTabGroup() throws CoreException {
173         return (ILaunchConfigurationTabGroup)getConfigurationElement().createExecutableExtension(IConfigurationElementConstants.CLASS);
174     }
175
176     /**
177      * Returns this tab group's description in the given mode set.
178      *
179      * @param modes the set of modes
180      * @return a description of the Launch Mode if available. If not available, attempts to return
181      * a description of the Launch Configuration. If no appropriate description is found an empty string is returned.
182      */

183     public String JavaDoc getDescription(Set JavaDoc modes) {
184         String JavaDoc description = null;
185         if(fDescriptions == null) {
186             fDescriptions = new HashMap JavaDoc();
187             IConfigurationElement[] children = fConfig.getChildren(IConfigurationElementConstants.LAUNCH_MODE);
188             IConfigurationElement child = null;
189             String JavaDoc mode = null;
190             HashSet JavaDoc set = null;
191             for (int i = 0; i < children.length; i++) {
192                 child = children[i];
193                 mode = child.getAttribute(IConfigurationElementConstants.MODE);
194                 if(mode != null) {
195                     set = new HashSet JavaDoc();
196                     set.add(mode);
197                 }
198                 description = child.getAttribute(IConfigurationElementConstants.DESCRIPTION);
199                 if(description != null) {
200                     fDescriptions.put(set, description);
201                 }
202             }
203             
204         }
205         description = (String JavaDoc) fDescriptions.get(modes);
206         if(description == null) {
207             description = fConfig.getAttribute(IConfigurationElementConstants.DESCRIPTION);
208             
209         }
210         return (description == null ? "" : description); //$NON-NLS-1$
211
}
212     
213 }
214
215
Popular Tags