org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.114 - (view) (download)

1 : droberts 1.45 /*******************************************************************************
2 : darin 1.111 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 : darins 1.85 * All rights reserved. This program and the accompanying materials
4 :     * are made available under the terms of the Eclipse Public License v1.0
5 : droberts 1.45 * which accompanies this distribution, and is available at
6 : darins 1.85 * http://www.eclipse.org/legal/epl-v10.html
7 : darin 1.92 *
8 : droberts 1.45 * Contributors:
9 :     * IBM Corporation - initial API and implementation
10 :     *******************************************************************************/
11 : jburns 1.28 package org.eclipse.debug.ui;
12 :    
13 : darin 1.32
14 : mrennie 1.102 import java.util.Set;
15 :    
16 : ppiech 1.113 import org.eclipse.core.commands.ExecutionEvent;
17 :     import org.eclipse.core.commands.ExecutionException;
18 : darin 1.61 import org.eclipse.core.resources.IResource;
19 : darin 1.32 import org.eclipse.core.runtime.CoreException;
20 : jburns 1.28 import org.eclipse.core.runtime.IAdaptable;
21 :     import org.eclipse.core.runtime.IConfigurationElement;
22 :     import org.eclipse.core.runtime.IExtension;
23 :     import org.eclipse.core.runtime.IExtensionPoint;
24 : darin 1.32 import org.eclipse.core.runtime.IProgressMonitor;
25 : darin 1.41 import org.eclipse.core.runtime.IStatus;
26 : darins 1.75 import org.eclipse.core.runtime.Platform;
27 : jburns 1.28 import org.eclipse.debug.core.DebugPlugin;
28 :     import org.eclipse.debug.core.ILaunch;
29 : darin 1.32 import org.eclipse.debug.core.ILaunchConfiguration;
30 : darin 1.46 import org.eclipse.debug.core.ILaunchConfigurationType;
31 : mrennie 1.102 import org.eclipse.debug.core.ILaunchDelegate;
32 : jburns 1.28 import org.eclipse.debug.core.model.IDebugElement;
33 :     import org.eclipse.debug.core.model.IDebugTarget;
34 :     import org.eclipse.debug.core.model.IProcess;
35 : darin 1.82 import org.eclipse.debug.core.model.ISourceLocator;
36 : ppiech 1.113 import org.eclipse.debug.internal.core.IConfigurationElementConstants;
37 : jburns 1.28 import org.eclipse.debug.internal.ui.DebugPluginImages;
38 :     import org.eclipse.debug.internal.ui.DebugUIPlugin;
39 :     import org.eclipse.debug.internal.ui.DefaultLabelProvider;
40 :     import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
41 :     import org.eclipse.debug.internal.ui.LazyModelPresentation;
42 : darin 1.91 import org.eclipse.debug.internal.ui.contexts.DebugContextManager;
43 : darin 1.42 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog;
44 : darin 1.58 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
45 : darin 1.38 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPropertiesDialog;
46 : darin 1.36 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
47 : darin 1.37 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
48 : darin 1.83 import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager;
49 : darin 1.82 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility;
50 : darin 1.87 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils;
51 : darin 1.61 import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
52 : darin 1.99 import org.eclipse.debug.ui.contexts.IDebugContextManager;
53 : darin 1.83 import org.eclipse.debug.ui.memory.IMemoryRenderingManager;
54 : darin 1.87 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
55 : darin 1.82 import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult;
56 : jburns 1.28 import org.eclipse.jface.preference.IPreferenceStore;
57 :     import org.eclipse.jface.resource.ImageDescriptor;
58 : darin 1.91 import org.eclipse.jface.viewers.ISelection;
59 : jburns 1.28 import org.eclipse.jface.viewers.IStructuredSelection;
60 : darin 1.36 import org.eclipse.jface.window.Window;
61 : darin 1.40 import org.eclipse.swt.custom.BusyIndicator;
62 : schan 1.88 import org.eclipse.swt.graphics.Color;
63 : jburns 1.28 import org.eclipse.swt.graphics.Image;
64 :     import org.eclipse.swt.widgets.Shell;
65 : darin 1.82 import org.eclipse.ui.IWorkbenchPage;
66 : darin 1.91 import org.eclipse.ui.IWorkbenchWindow;
67 : darin 1.66 import org.eclipse.ui.console.IConsole;
68 : ppiech 1.113 import org.eclipse.ui.handlers.HandlerUtil;
69 : jburns 1.28
70 :     /**
71 :     * This class provides utilities for clients of the debug UI.
72 :     * <p>
73 :     * Images retrieved from this facility should not be disposed.
74 : darins 1.90 * The images will be disposed when this plug-in is shutdown.
75 : jburns 1.28 * </p>
76 : mrennie 1.108 * @noinstantiate This class is not intended to be instantiated by clients.
77 :     * @noextend This class is not intended to be subclassed by clients.
78 : jburns 1.28 */
79 :     public class DebugUITools {
80 :    
81 :     /**
82 :     * Returns the shared image managed under the given key, or <code>null</code>
83 :     * if none.
84 :     * <p>
85 :     * Note that clients <b>MUST NOT</b> dispose the image returned by this method.
86 :     * </p>
87 :     * <p>
88 :     * See <code>IDebugUIConstants</code> for available images.
89 :     * </p>
90 :     *
91 :     * @param key the image key
92 :     * @return the image, or <code>null</code> if none
93 :     * @see IDebugUIConstants
94 :     */
95 :     public static Image getImage(String key) {
96 :     return DebugPluginImages.getImage(key);
97 :     }
98 :    
99 :     /**
100 :     * Returns the shared image descriptor managed under the given key, or
101 :     * <code>null</code> if none.
102 :     * <p>
103 :     * See <code>IDebugUIConstants</code> for available image descriptors.
104 :     * </p>
105 :     *
106 :     * @param key the image descriptor key
107 :     * @return the image descriptor, or <code>null</code> if none
108 :     * @see IDebugUIConstants
109 :     */
110 :     public static ImageDescriptor getImageDescriptor(String key) {
111 :     return DebugPluginImages.getImageDescriptor(key);
112 :     }
113 :    
114 :     /**
115 :     * Returns the default image descriptor for the given element
116 :     * or <code>null</code> if none is defined.
117 :     */
118 :     public static ImageDescriptor getDefaultImageDescriptor(Object element) {
119 :     String imageKey= getDefaultImageKey(element);
120 :     if (imageKey == null) {
121 :     return null;
122 :     }
123 :     return DebugPluginImages.getImageDescriptor(imageKey);
124 :     }
125 :    
126 :     private static String getDefaultImageKey(Object element) {
127 :     return ((DefaultLabelProvider)DebugUIPlugin.getDefaultLabelProvider()).getImageKey(element);
128 :     }
129 :    
130 :     /**
131 : darins 1.90 * Returns the preference store for the debug UI plug-in.
132 : jburns 1.28 *
133 :     * @return preference store
134 :     */
135 :     public static IPreferenceStore getPreferenceStore() {
136 :     return DebugUIPlugin.getDefault().getPreferenceStore();
137 : jburns 1.47 }
138 :    
139 :     /**
140 : jburns 1.28 * Returns a new debug model presentation that delegates to
141 :     * appropriate debug models.
142 :     * <p>
143 :     * It is the client's responsibility dispose the presentation.
144 :     * </p>
145 :     *
146 :     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
147 :     * @return a debug model presentation
148 :     * @since 2.0
149 :     */
150 :     public static IDebugModelPresentation newDebugModelPresentation() {
151 :     return new DelegatingModelPresentation();
152 :     }
153 :    
154 :     /**
155 :     * Returns a new debug model presentation for specified
156 :     * debug model, or <code>null</code> if a presentation does
157 :     * not exist.
158 :     * <p>
159 :     * It is the client's responsibility dispose the presentation.
160 :     * </p>
161 :     *
162 :     * @param identifier debug model identifier
163 :     * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
164 :     * @return a debug model presentation, or <code>null</code>
165 :     * @since 2.0
166 :     */
167 :     public static IDebugModelPresentation newDebugModelPresentation(String identifier) {
168 : darins 1.75 IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.ID_DEBUG_MODEL_PRESENTATION);
169 : jburns 1.28 if (point != null) {
170 :     IExtension[] extensions= point.getExtensions();
171 :     for (int i= 0; i < extensions.length; i++) {
172 :     IExtension extension= extensions[i];
173 :     IConfigurationElement[] configElements= extension.getConfigurationElements();
174 :     for (int j= 0; j < configElements.length; j++) {
175 :     IConfigurationElement elt= configElements[j];
176 :     String id= elt.getAttribute("id"); //$NON-NLS-1$
177 :     if (id != null && id.equals(identifier)) {
178 :     return new LazyModelPresentation(elt);
179 :     }
180 :     }
181 :     }
182 :     }
183 :     return null;
184 :     }
185 :    
186 :     /**
187 :     * Returns the currently selected element in the
188 :     * debug view of the current workbench page,
189 :     * or <code>null</code> if there is no current
190 : darin 1.78 * debug context.
191 :     * <p>
192 :     * This method used to return <code>null</code> when called from a non-UI thread,
193 :     * but since 3.1, this methods also works when called from a non-UI thread.
194 :     * </p>
195 : jburns 1.28 * @return the currently selected debug context, or <code>null</code>
196 :     * @since 2.0
197 :     */
198 :     public static IAdaptable getDebugContext() {
199 : darin 1.91 IWorkbenchWindow activeWindow = SelectedResourceManager.getDefault().getActiveWindow();
200 :     if (activeWindow != null) {
201 : darin 1.99 ISelection activeContext = DebugUITools.getDebugContextManager().getContextService(activeWindow).getActiveContext();
202 : darin 1.91 if (activeContext instanceof IStructuredSelection) {
203 :     IStructuredSelection selection = (IStructuredSelection) activeContext;
204 :     if (!selection.isEmpty()) {
205 :     Object firstElement = selection.getFirstElement();
206 :     if (firstElement instanceof IAdaptable) {
207 :     return (IAdaptable) firstElement;
208 :     }
209 :     }
210 :     }
211 :     }
212 :     return null;
213 : darin 1.61 }
214 :    
215 :     /**
216 :     * Returns the currently selected resource in the active workbench window,
217 : darins 1.90 * or <code>null</code> if none. If an editor is active, the resource adapter
218 :     * associated with the editor is returned, if any.
219 : darin 1.61 *
220 :     * @return selected resource or <code>null</code>
221 :     * @since 3.0
222 :     */
223 :     public static IResource getSelectedResource() {
224 :     return SelectedResourceManager.getDefault().getSelectedResource();
225 : jburns 1.28 }
226 :    
227 :     /**
228 :     * Returns the process associated with the current debug context.
229 :     * If there is no debug context currently, the most recently
230 :     * launched process is returned. If there is no current process
231 :     * <code>null</code> is returned.
232 :     *
233 :     * @return the current process, or <code>null</code>
234 :     * @since 2.0
235 :     */
236 :     public static IProcess getCurrentProcess() {
237 :     IAdaptable context = getDebugContext();
238 :     if (context == null) {
239 :     ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
240 :     if (launches.length > 0) {
241 :     context = launches[launches.length - 1];
242 :     }
243 :     }
244 : darin 1.93
245 : jburns 1.28 if (context instanceof IDebugElement) {
246 :     return ((IDebugElement)context).getDebugTarget().getProcess();
247 :     }
248 : darin 1.93
249 :     if (context instanceof IProcess) {
250 : jburns 1.28 return (IProcess)context;
251 :     }
252 : darin 1.93
253 :     if (context instanceof ILaunch) {
254 : jburns 1.28 ILaunch launch= (ILaunch)context;
255 :     IDebugTarget target= launch.getDebugTarget();
256 :     if (target != null) {
257 :     IProcess process = target.getProcess();
258 :     if (process != null) {
259 :     return process;
260 :     }
261 :     }
262 :     IProcess[] ps = launch.getProcesses();
263 :     if (ps.length > 0) {
264 :     return ps[ps.length - 1];
265 :     }
266 :     }
267 : darin 1.93
268 :     if (context != null) {
269 :     return (IProcess) context.getAdapter(IProcess.class);
270 :     }
271 :    
272 : jburns 1.28 return null;
273 :     }
274 :    
275 :     /**
276 :     * Open the launch configuration dialog with the specified initial selection.
277 :     * The selection may be <code>null</code>, or contain any mix of
278 :     * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
279 :     * elements.
280 : jszursze 1.29 * <p>
281 :     * Before opening a new dialog, this method checks if there is an existing open
282 :     * launch configuration dialog. If there is, this dialog is used with the
283 :     * specified selection. If there is no existing dialog, a new one is created.
284 :     * </p>
285 :     * <p>
286 :     * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
287 :     * and the existing dialog keeps its original mode.
288 :     * </p>
289 : jburns 1.28 *
290 :     * @param shell the parent shell for the launch configuration dialog
291 :     * @param selection the initial selection for the dialog
292 :     * @param mode the mode (run or debug) in which to open the launch configuration dialog.
293 :     * This should be one of the constants defined in <code>ILaunchManager</code>.
294 : darin 1.35 * @return the return code from opening the launch configuration dialog -
295 : darin 1.112 * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
296 :     * is returned if an invalid launch group identifier is provided.
297 :     * @see ILaunchGroup
298 : jburns 1.28 * @since 2.0
299 : darin 1.73 * @deprecated use openLaunchConfigurationDialogOnGroup(Shell, IStructuredSelection, String)
300 :     * to specify the launch group that the dialog should be opened on. This method will open
301 :     * on the launch group with the specified mode and a <code>null</code> category
302 : jburns 1.28 */
303 :     public static int openLaunchConfigurationDialog(Shell shell, IStructuredSelection selection, String mode) {
304 : darin 1.73 ILaunchGroup[] groups = getLaunchGroups();
305 :     for (int i = 0; i < groups.length; i++) {
306 :     ILaunchGroup group = groups[i];
307 :     if (group.getMode().equals(mode) && group.getCategory() == null) {
308 :     return openLaunchConfigurationDialogOnGroup(shell, selection, group.getIdentifier());
309 :     }
310 : jszursze 1.29 }
311 : darin 1.73 return Window.CANCEL;
312 : jburns 1.28 }
313 :    
314 : darin 1.30 /**
315 :     * Open the launch configuration dialog with the specified initial selection.
316 :     * The selection may be <code>null</code>, or contain any mix of
317 :     * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
318 :     * elements.
319 :     * <p>
320 :     * Before opening a new dialog, this method checks if there is an existing open
321 :     * launch configuration dialog. If there is, this dialog is used with the
322 :     * specified selection. If there is no existing dialog, a new one is created.
323 :     * </p>
324 :     * <p>
325 :     * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
326 :     * and the existing dialog keeps its original mode.
327 :     * </p>
328 :     *
329 :     * @param shell the parent shell for the launch configuration dialog
330 :     * @param selection the initial selection for the dialog
331 : darin 1.33 * @param groupIdentifier the identifier of the launch group to display (corresponds to
332 : darins 1.43 * the identifier of a launch group extension)
333 : darin 1.112 * @return The return code from opening the launch configuration dialog -
334 :     * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
335 :     * is returned if an invalid launch group identifier is provided.
336 :     * @see ILaunchGroup
337 : darin 1.30 * @since 2.1
338 :     */
339 : darin 1.41 public static int openLaunchConfigurationDialogOnGroup(Shell shell, IStructuredSelection selection, String groupIdentifier) {
340 :     return openLaunchConfigurationDialogOnGroup(shell, selection, groupIdentifier, null);
341 :     }
342 :    
343 :     /**
344 :     * Open the launch configuration dialog with the specified initial selection.
345 :     * The selection may be <code>null</code>, or contain any mix of
346 :     * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
347 :     * elements.
348 :     * <p>
349 :     * Before opening a new dialog, this method checks if there is an existing open
350 :     * launch configuration dialog. If there is, this dialog is used with the
351 :     * specified selection. If there is no existing dialog, a new one is created.
352 :     * </p>
353 :     * <p>
354 :     * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
355 :     * and the existing dialog keeps its original mode.
356 :     * </p>
357 : darin 1.42 * <p>
358 : darin 1.41 * If a status is specified, a status handler is consulted to handle the
359 :     * status. The status handler is passed the instance of the launch
360 :     * configuration dialog that is opened. This gives the status handler an
361 :     * opportunity to perform error handling/initialization as required.
362 :     * </p>
363 :     * @param shell the parent shell for the launch configuration dialog
364 :     * @param selection the initial selection for the dialog
365 :     * @param groupIdentifier the identifier of the launch group to display (corresponds to
366 : darins 1.43 * the identifier of a launch group extension)
367 : darin 1.41 * @param status the status to display in the dialog, or <code>null</code>
368 :     * if none
369 :     * @return the return code from opening the launch configuration dialog -
370 : darin 1.112 * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
371 :     * is returned if an invalid launch group identifier is provided.
372 : darin 1.41 * @see org.eclipse.debug.core.IStatusHandler
373 : darin 1.112 * @see ILaunchGroup
374 : darin 1.41 * @since 2.1
375 :     */
376 :     public static int openLaunchConfigurationDialogOnGroup(final Shell shell, final IStructuredSelection selection, final String groupIdentifier, final IStatus status) {
377 : darin 1.40 final int[] result = new int[1];
378 :     Runnable r = new Runnable() {
379 :     /**
380 :     * @see java.lang.Runnable#run()
381 :     */
382 :     public void run() {
383 : darin 1.81 LaunchConfigurationsDialog dialog = (LaunchConfigurationsDialog) LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog();
384 :     if (dialog != null) {
385 :     dialog.setInitialSelection(selection);
386 :     dialog.doInitialTreeSelection();
387 :     if (status != null) {
388 :     dialog.handleStatus(status);
389 : darin 1.41 }
390 : darin 1.81 result[0] = Window.OK;
391 :     } else {
392 : mrennie 1.107 LaunchGroupExtension ext = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier);
393 :     if(ext != null) {
394 :     dialog = new LaunchConfigurationsDialog(shell, ext);
395 :     dialog.setOpenMode(LaunchConfigurationsDialog.LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION);
396 :     dialog.setInitialSelection(selection);
397 :     dialog.setInitialStatus(status);
398 :     result[0] = dialog.open();
399 :     }
400 :     else {
401 :     result[0] = Window.CANCEL;
402 :     }
403 : darin 1.81 }
404 : darin 1.40 }
405 :     };
406 :     BusyIndicator.showWhile(DebugUIPlugin.getStandardDisplay(), r);
407 :     return result[0];
408 : darin 1.30 }
409 : darin 1.41
410 : darin 1.37 /**
411 :     * Open the launch configuration properties dialog on the specified launch
412 :     * configuration.
413 :     *
414 :     * @param shell the parent shell for the launch configuration dialog
415 :     * @param configuration the configuration to display
416 : darins 1.77 * @param groupIdentifier group identifier of the launch group the launch configuration
417 : darin 1.38 * belongs to
418 : darin 1.37 * @return the return code from opening the launch configuration dialog -
419 : darin 1.112 * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
420 :     * is returned if an invalid launch group identifier is provided.
421 :     * @see ILaunchGroup
422 : darin 1.37 * @since 2.1
423 :     */
424 :     public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier) {
425 : darins 1.74 return openLaunchConfigurationPropertiesDialog(shell, configuration, groupIdentifier, null);
426 :     }
427 :    
428 :     /**
429 :     * Open the launch configuration properties dialog on the specified launch
430 :     * configuration.
431 :     *
432 :     * @param shell the parent shell for the launch configuration dialog
433 :     * @param configuration the configuration to display
434 : darins 1.77 * @param groupIdentifier group identifier of the launch group the launch configuration
435 : darins 1.74 * belongs to
436 :     * @param status the status to display, or <code>null</code> if none
437 :     * @return the return code from opening the launch configuration dialog -
438 : darin 1.112 * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
439 :     * is returned if an invalid launch group identifier is provided.
440 :     * @see ILaunchGroup
441 : darins 1.74 * @since 3.0
442 :     */
443 :     public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier, IStatus status) {
444 : darin 1.39 LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier);
445 : darin 1.37 if (group != null) {
446 :     LaunchConfigurationPropertiesDialog dialog = new LaunchConfigurationPropertiesDialog(shell, configuration, group);
447 : darins 1.74 dialog.setInitialStatus(status);
448 : darin 1.37 return dialog.open();
449 : darins 1.76 }
450 :    
451 :     return Window.CANCEL;
452 : darin 1.37 }
453 :    
454 : darin 1.42 /**
455 : darin 1.79 * Open the launch configuration dialog on the specified launch
456 :     * configuration. The dialog displays the tabs for a single configuration
457 :     * only (a tree of launch configuration is not displayed), and provides a
458 :     * launch (run or debug) button.
459 :     * <p>
460 :     * If a status is specified, a status handler is consulted to handle the
461 :     * status. The status handler is passed the instance of the launch
462 :     * configuration dialog that is opened. This gives the status handler an
463 :     * opportunity to perform error handling/initialization as required.
464 :     * </p>
465 :     * @param shell the parent shell for the launch configuration dialog
466 :     * @param configuration the configuration to display
467 :     * @param groupIdentifier group identifier of the launch group the launch configuration
468 :     * belongs to
469 :     * @param status the status to display, or <code>null</code> if none
470 :     * @return the return code from opening the launch configuration dialog -
471 : darin 1.112 * one of <code>Window.OK</code> or <code>Window.CANCEL</code>. <code>Window.CANCEL</code>
472 :     * is returned if an invalid launch group identifier is provided.
473 :     * @see ILaunchGroup
474 : darin 1.79 * @since 2.1
475 :     */
476 :     public static int openLaunchConfigurationDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier, IStatus status) {
477 :     LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier);
478 :     if (group != null) {
479 :     LaunchConfigurationDialog dialog = new LaunchConfigurationDialog(shell, configuration, group);
480 :     dialog.setInitialStatus(status);
481 :     return dialog.open();
482 :     }
483 :    
484 :     return Window.CANCEL;
485 :     }
486 : darin 1.97
487 : jburns 1.28 /**
488 :     * Saves all dirty editors and builds the workspace according to current
489 :     * preference settings, and returns whether a launch should proceed.
490 :     * <p>
491 :     * The following preferences effect whether dirty editors are saved,
492 : darins 1.90 * and/or if the user is prompted to save dirty editors:<ul>
493 : jburns 1.28 * <li>PREF_NEVER_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
494 :     * <li>PREF_PROMPT_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
495 :     * <li>PREF_AUTOSAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
496 :     * </ul>
497 :     * The following preference effects whether a build is performed before
498 :     * launching (if required):<ul>
499 :     * <li>PREF_BUILD_BEFORE_LAUNCH</li>
500 :     * </ul>
501 :     * </p>
502 :     *
503 :     * @return whether a launch should proceed
504 :     * @since 2.0
505 : schan 1.86 * @deprecated Saving has been moved to the launch delegate <code>LaunchConfigurationDelegate</code> to allow for scoped saving
506 :     * of resources that are only involved in the current launch, no longer the entire workspace
507 : jburns 1.28 */
508 :     public static boolean saveAndBuildBeforeLaunch() {
509 :     return DebugUIPlugin.saveAndBuild();
510 : darin 1.32 }
511 :    
512 :     /**
513 : darin 1.44 * Saves all dirty editors according to current
514 :     * preference settings, and returns whether a launch should proceed.
515 :     * <p>
516 :     * The following preferences effect whether dirty editors are saved,
517 : darins 1.90 * and/or if the user is prompted to save dirty editors:<ul>
518 : darin 1.44 * <li>PREF_NEVER_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
519 :     * <li>PREF_PROMPT_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
520 :     * <li>PREF_AUTOSAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
521 :     * </ul>
522 :     * </p>
523 :     *
524 :     * @return whether a launch should proceed
525 :     * @since 2.1
526 : schan 1.86 * @deprecated Saving has been moved to the launch delegate <code>LaunchConfigurationDelegate</code> to allow for scoped saving
527 :     * of resources that are only involved in the current launch, no longer the entire workspace
528 : darin 1.44 */
529 :     public static boolean saveBeforeLaunch() {
530 :     return DebugUIPlugin.preLaunchSave();
531 : jburns 1.53 }
532 : darin 1.44
533 :     /**
534 :     * Saves and builds the workspace according to current preference settings, and
535 : jburns 1.56 * launches the given launch configuration in the specified mode.
536 : darin 1.110 * <p>
537 :     * This method must be called in the UI thread.
538 :     * </p>
539 : darin 1.32 * @param configuration the configuration to launch
540 :     * @param mode launch mode - run or debug
541 : darin 1.52 * @since 2.1
542 : darin 1.32 */
543 : jburns 1.53 public static void launch(final ILaunchConfiguration configuration, final String mode) {
544 : jburns 1.60 boolean launchInBackground= true;
545 :     try {
546 :     launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
547 :     } catch (CoreException e) {
548 :     DebugUIPlugin.log(e);
549 :     }
550 :     if (launchInBackground) {
551 : krbarnes 1.69 DebugUIPlugin.launchInBackground(configuration, mode);
552 : jburns 1.60 } else {
553 : krbarnes 1.69 DebugUIPlugin.launchInForeground(configuration, mode);
554 : jburns 1.56 }
555 :     }
556 :    
557 : krbarnes 1.69
558 : darin 1.44
559 :     /**
560 :     * Builds the workspace according to current preference settings, and launches
561 :     * the given configuration in the specified mode, returning the resulting launch
562 :     * object.
563 :     * <p>
564 :     * The following preference effects whether a build is performed before
565 :     * launching (if required):<ul>
566 :     * <li>PREF_BUILD_BEFORE_LAUNCH</li>
567 :     * </ul>
568 :     * </p>
569 :     *
570 :     * @param configuration the configuration to launch
571 :     * @param mode the mode to launch in
572 : jburns 1.53 * @param monitor progress monitor
573 : darin 1.44 * @return the resulting launch object
574 :     * @throws CoreException if building or launching fails
575 :     * @since 2.1
576 :     */
577 :     public static ILaunch buildAndLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException {
578 :     return DebugUIPlugin.buildAndLaunch(configuration, mode, monitor);
579 : jburns 1.28 }
580 : darin 1.46
581 :     /**
582 :     * Returns the perspective to switch to when a configuration of the given type
583 :     * is launched in the given mode, or <code>null</code> if no switch should take
584 :     * place.
585 :     *
586 : mrennie 1.102 * In 3.3 this method is equivalent to calling <code>getLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate)</code>,
587 :     * with the 'mode' parameter comprising a single element set and passing <code>null</code> as the launch delegate.
588 :     *
589 : darin 1.46 * @param type launch configuration type
590 :     * @param mode launch mode identifier
591 :     * @return perspective identifier or <code>null</code>
592 :     * @since 3.0
593 :     */
594 :     public static String getLaunchPerspective(ILaunchConfigurationType type, String mode) {
595 :     return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, mode);
596 :     }
597 :    
598 :     /**
599 : mrennie 1.102 * Returns the perspective id to switch to when a configuration of the given type launched with the specified delegate
600 :     * is launched in the given mode set, or <code>null</code> if no switch should occurr.
601 :     * @param type the configuration type
602 :     * @param delegate the launch delegate
603 :     * @param modes the set of modes
604 :     * @return the perspective id or <code>null</code> if no switch should occur
605 :     *
606 :     * @since 3.3
607 :     */
608 :     public static String getLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes) {
609 :     return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, modes, delegate);
610 :     }
611 :    
612 :     /**
613 : darin 1.46 * Sets the perspective to switch to when a configuration of the given type
614 :     * is launched in the given mode. <code>PERSPECTIVE_NONE</code> indicates no
615 :     * perspective switch should take place. <code>PERSPECTIVE_DEFAULT</code> indicates
616 :     * a default perspective switch should take place, as defined by the associated
617 :     * launch tab group extension.
618 :     *
619 : mrennie 1.102 * In 3.3 this method is equivalent to calling <code>setLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate, String perspectiveid)</code>,
620 :     * with the parameter 'mode' used in the set modes, and null passed as the delegate
621 :     *
622 : darin 1.46 * @param type launch configuration type
623 :     * @param mode launch mode identifier
624 :     * @param perspective identifier, <code>PERSPECTIVE_NONE</code>, or
625 :     * <code>PERSPECTIVE_DEFAULT</code>
626 :     * @since 3.0
627 :     */
628 :     public static void setLaunchPerspective(ILaunchConfigurationType type, String mode, String perspective) {
629 :     DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, mode, perspective);
630 :     }
631 : mrennie 1.102
632 :     /**
633 :     * Sets the perspective to switch to when a configuration of the specified type and launched using the
634 :     * specified launch delegate is launched in the specified modeset. <code>PERSPECTIVE_NONE</code> indicates no
635 :     * perspective switch should take place.
636 :     *
637 :     * Passing <code>null</code> for the launch delegate is quivalent to using the default perspective for the specified
638 :     * type.
639 :     * @param type the configuration type
640 :     * @param delegate the launch delegate
641 :     * @param modes the set of modes
642 :     * @param perspectiveid identifier or <code>PERSPECTIVE_NONE</code>
643 :     *
644 :     * @since 3.3
645 :     */
646 :     public static void setLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes, String perspectiveid) {
647 :     DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, modes, delegate, perspectiveid);
648 :     }
649 :    
650 : darin 1.58 /**
651 : darins 1.90 * Returns whether the given launch configuration is private. Generally,
652 : darin 1.58 * private launch configurations should not be displayed to the user. The
653 :     * private status of a launch configuration is determined by the
654 :     * <code>IDebugUIConstants.ATTR_PRIVATE</code> attribute.
655 :     *
656 :     * @param configuration launch configuration
657 :     * @return whether the given launch configuration is private
658 :     * @since 3.0
659 :     */
660 :     public static boolean isPrivate(ILaunchConfiguration configuration) {
661 :     return !LaunchConfigurationManager.isVisible(configuration);
662 :     }
663 : darin 1.64
664 :     /**
665 :     * Sets whether step filters should be applied to step commands. This
666 :     * setting is a global option applied to all registered debug targets.
667 : darin 1.101 * <p>
668 :     * Since 3.3, this is equivalent to calling <code>DebugPlugin.setUseStepFilters(boolean)</code>.
669 :     * </p>
670 : darin 1.64 * @param useStepFilters whether step filters should be applied to step
671 :     * commands
672 :     * @since 3.0
673 :     * @see org.eclipse.debug.core.model.IStepFilters
674 :     */
675 :     public static void setUseStepFilters(boolean useStepFilters) {
676 : darin 1.101 DebugPlugin.setUseStepFilters(useStepFilters);
677 : darin 1.64 }
678 : darin 1.58
679 : darin 1.64 /**
680 :     * Returns whether step filters are applied to step commands.
681 : darin 1.101 * <p>
682 :     * Since 3.3, this is equivalent to calling <code>DebugPlugin.isUseStepFilters()</code>.
683 :     * </p>
684 : darin 1.64 * @return whether step filters are applied to step commands
685 :     * @since 3.0
686 :     * @see org.eclipse.debug.core.model.IStepFilters
687 :     */
688 :     public static boolean isUseStepFilters() {
689 : darin 1.101 return DebugPlugin.isUseStepFilters();
690 : darin 1.65 }
691 : darin 1.70
692 : darin 1.66 /**
693 :     * Returns the console associated with the given process, or
694 :     * <code>null</code> if none.
695 :     *
696 :     * @param process a process
697 :     * @return console associated with the given process, or
698 :     * <code>null</code> if none
699 :     * @since 3.0
700 :     */
701 : darins 1.67 public static IConsole getConsole(IProcess process) {
702 : krbarnes 1.80 return DebugUIPlugin.getDefault().getProcessConsoleManager().getConsole(process);
703 : darin 1.66 }
704 :    
705 :     /**
706 :     * Returns the console associated with the given debug element, or
707 :     * <code>null</code> if none.
708 :     *
709 :     * @param element a debug model element
710 :     * @return console associated with the given element, or
711 :     * <code>null</code> if none
712 :     * @since 3.0
713 :     */
714 : darins 1.67 public static IConsole getConsole(IDebugElement element) {
715 : darin 1.66 IProcess process = element.getDebugTarget().getProcess();
716 :     if (process != null) {
717 :     return getConsole(process);
718 :     }
719 :     return null;
720 :     }
721 : darin 1.72
722 :     /**
723 :     * Returns all registered launch group extensions.
724 :     *
725 :     * @return all registered launch group extensions
726 :     * @since 3.0
727 :     */
728 :     public static ILaunchGroup[] getLaunchGroups() {
729 :     return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroups();
730 :     }
731 :    
732 :     /**
733 : darin 1.96 * Returns the last configuration that was launched for specified launch group or
734 : mrennie 1.106 * <code>null</code>, if there is not one. This method does not provide any form of
735 :     * filtering on the returned launch configurations.
736 : mrennie 1.94 *
737 : darin 1.96 * @param groupId the unique identifier of a launch group
738 : mrennie 1.94 * @return the last launched configuration for the specified group or <code>null</code>.
739 : darin 1.96 * @see DebugUITools#getLaunchGroups()
740 : mrennie 1.94 * @since 3.3
741 :     */
742 : mrennie 1.95 public static ILaunchConfiguration getLastLaunch(String groupId) {
743 : mrennie 1.94 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLastLaunch(groupId);
744 :     }
745 :    
746 :     /**
747 : darin 1.72 * Returns the launch group that the given launch configuration belongs
748 :     * to, for the specified mode, or <code>null</code> if none.
749 :     *
750 :     * @param configuration
751 :     * @param mode
752 :     * @return the launch group the given launch configuration belongs to, for
753 :     * the specified mode, or <code>null</code> if none
754 : darin 1.82 * @since 3.0
755 : darin 1.72 */
756 :     public static ILaunchGroup getLaunchGroup(ILaunchConfiguration configuration, String mode) {
757 : mrennie 1.107 try {
758 :     return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configuration.getType(), mode);
759 :     }
760 :     catch(CoreException ce) {
761 :     return null;
762 :     }
763 : darin 1.79 }
764 :    
765 : darin 1.82 /**
766 :     * Performs source lookup on the given artifact and returns the result.
767 :     * Optionally, a source locator may be specified.
768 :     *
769 :     * @param artifact object for which source is to be resolved
770 :     * @param locator the source locator to use, or <code>null</code>. When <code>null</code>
771 :     * a source locator is determined from the artifact, if possible. If the artifact
772 :     * is a debug element, the source locator from its associated launch is used.
773 :     * @return a source lookup result
774 :     * @since 3.1
775 :     */
776 :     public static ISourceLookupResult lookupSource(Object artifact, ISourceLocator locator) {
777 :     return SourceLookupFacility.getDefault().lookup(artifact, locator);
778 :     }
779 :    
780 :     /**
781 :     * Displays the given source lookup result in an editor in the given workbench
782 :     * page. Has no effect if the result has an unknown editor id or editor input.
783 :     * The editor is opened, positioned, and annotated.
784 :     * <p>
785 :     * Honors user preference for editors re-use.
786 :     * </p>
787 :     * @param result source lookup result to display
788 :     * @param page the page to display the result in
789 :     * @since 3.1
790 :     */
791 :     public static void displaySource(ISourceLookupResult result, IWorkbenchPage page) {
792 :     SourceLookupFacility.getDefault().display(result, page);
793 : darin 1.83 }
794 :    
795 :     /**
796 :     * Returns the memory rendering manager.
797 :     *
798 :     * @return the memory rendering manager
799 :     * @since 3.1
800 :     */
801 : darin 1.84 public static IMemoryRenderingManager getMemoryRenderingManager() {
802 : darin 1.83 return MemoryRenderingManager.getDefault();
803 : darin 1.82 }
804 : darin 1.87
805 :     /**
806 :     * Returns the image associated with the specified type of source container
807 :     * or <code>null</code> if none.
808 :     *
809 :     * @param id unique identifier for a source container type
810 : darins 1.90 * @return image associated with the specified type of source container
811 : darin 1.87 * or <code>null</code> if none
812 :     * @since 3.2
813 :     * @see org.eclipse.debug.core.sourcelookup.ISourceContainerType
814 :     */
815 :     public static Image getSourceContainerImage(String id){
816 :     return SourceLookupUIUtils.getSourceContainerImage(id);
817 :     }
818 :    
819 :     /**
820 :     * Returns a new source container browser for the specified type of source container
821 :     * or <code>null</code> if a browser has not been registered.
822 :     *
823 :     * @param id unique identifier for a source container type
824 :     * @return source container browser or <code>null</code> if none
825 :     * @since 3.2
826 :     * @see org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser
827 :     */
828 :     public static ISourceContainerBrowser getSourceContainerBrowser(String id) {
829 :     return SourceLookupUIUtils.getSourceContainerBrowser(id);
830 :     }
831 : schan 1.88
832 :     /**
833 : darin 1.89 * Returns the color associated with the specified preference identifier or
834 :     * <code>null</code> if none.
835 :     *
836 : schan 1.88 * @param id preference identifier of the color
837 :     * @return the color associated with the specified preference identifier
838 : darin 1.89 * or <code>null</code> if none
839 : schan 1.88 * @since 3.2
840 : darin 1.89 * @see IDebugUIConstants
841 : schan 1.88 */
842 : darin 1.89 public static Color getPreferenceColor(String id) {
843 : schan 1.88 return DebugUIPlugin.getPreferenceColor(id);
844 :     }
845 : darin 1.99
846 :     /**
847 :     * Returns the debug context manager.
848 :     *
849 :     * @return debug context manager
850 :     * @since 3.3
851 :     */
852 :     public static IDebugContextManager getDebugContextManager() {
853 :     return DebugContextManager.getDefault();
854 :     }
855 : ppiech 1.113
856 :     /**
857 : darin 1.114 * Return the debug context for the given executionEvent or <code>null</code> if none.
858 : ppiech 1.113 *
859 :     * @param event The execution event that contains the application context
860 :     * @return the current debug context, or <code>null</code>.
861 :     *
862 :     * @since 3.5
863 :     */
864 :     public static ISelection getDebugContextForEvent(ExecutionEvent event) {
865 :     Object o = HandlerUtil.getVariable(event, IConfigurationElementConstants.DEBUG_CONTEXT);
866 :     if (o instanceof ISelection) {
867 :     return (ISelection) o;
868 :     }
869 :     return null;
870 :     }
871 :    
872 :     /**
873 :     * Return the debug context for the given executionEvent.
874 :     *
875 :     * @param event The execution event that contains the application context
876 :     * @return the debug context. Will not return <code>null</code>.
877 :     * @throws ExecutionException If the current selection variable is not found.
878 :     *
879 :     * @since 3.5
880 :     */
881 :     public static ISelection getDebugContextForEventChecked(ExecutionEvent event)
882 :     throws ExecutionException {
883 :     Object o = HandlerUtil.getVariableChecked(event, IConfigurationElementConstants.DEBUG_CONTEXT);
884 :     if (!(o instanceof ISelection)) {
885 :     throw new ExecutionException("Incorrect type for " //$NON-NLS-1$
886 :     + IConfigurationElementConstants.DEBUG_CONTEXT
887 :     + " found while executing " //$NON-NLS-1$
888 :     + event.getCommand().getId()
889 :     + ", expected " + ISelection.class.getName() //$NON-NLS-1$
890 :     + " found " + o.getClass().getName()); //$NON-NLS-1$
891 :     }
892 :     return (ISelection) o;
893 :     }
894 :    
895 : droberts 1.45 }