KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > ui > DebugUITools


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.ui;
12
13
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IConfigurationElement;
20 import org.eclipse.core.runtime.IExtension;
21 import org.eclipse.core.runtime.IExtensionPoint;
22 import org.eclipse.core.runtime.IProgressMonitor;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.Platform;
25 import org.eclipse.debug.core.DebugPlugin;
26 import org.eclipse.debug.core.ILaunch;
27 import org.eclipse.debug.core.ILaunchConfiguration;
28 import org.eclipse.debug.core.ILaunchConfigurationType;
29 import org.eclipse.debug.core.ILaunchDelegate;
30 import org.eclipse.debug.core.model.IDebugElement;
31 import org.eclipse.debug.core.model.IDebugTarget;
32 import org.eclipse.debug.core.model.IProcess;
33 import org.eclipse.debug.core.model.ISourceLocator;
34 import org.eclipse.debug.internal.ui.DebugPluginImages;
35 import org.eclipse.debug.internal.ui.DebugUIPlugin;
36 import org.eclipse.debug.internal.ui.DefaultLabelProvider;
37 import org.eclipse.debug.internal.ui.DelegatingModelPresentation;
38 import org.eclipse.debug.internal.ui.LazyModelPresentation;
39 import org.eclipse.debug.internal.ui.contexts.DebugContextManager;
40 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog;
41 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
42 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPropertiesDialog;
43 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog;
44 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension;
45 import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager;
46 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility;
47 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils;
48 import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager;
49 import org.eclipse.debug.ui.contexts.IDebugContextManager;
50 import org.eclipse.debug.ui.memory.IMemoryRenderingManager;
51 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
52 import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult;
53 import org.eclipse.jface.preference.IPreferenceStore;
54 import org.eclipse.jface.resource.ImageDescriptor;
55 import org.eclipse.jface.viewers.ISelection;
56 import org.eclipse.jface.viewers.IStructuredSelection;
57 import org.eclipse.jface.window.Window;
58 import org.eclipse.swt.custom.BusyIndicator;
59 import org.eclipse.swt.graphics.Color;
60 import org.eclipse.swt.graphics.Image;
61 import org.eclipse.swt.widgets.Shell;
62 import org.eclipse.ui.IWorkbenchPage;
63 import org.eclipse.ui.IWorkbenchWindow;
64 import org.eclipse.ui.console.IConsole;
65
66 /**
67  * This class provides utilities for clients of the debug UI.
68  * <p>
69  * Images retrieved from this facility should not be disposed.
70  * The images will be disposed when this plug-in is shutdown.
71  * </p>
72  * <p>
73  * This class is not intended to be subclassed or instantiated.
74  * </p>
75  */

76 public class DebugUITools {
77     
78     /**
79      * Returns the shared image managed under the given key, or <code>null</code>
80      * if none.
81      * <p>
82      * Note that clients <b>MUST NOT</b> dispose the image returned by this method.
83      * </p>
84      * <p>
85      * See <code>IDebugUIConstants</code> for available images.
86      * </p>
87      *
88      * @param key the image key
89      * @return the image, or <code>null</code> if none
90      * @see IDebugUIConstants
91      */

92     public static Image getImage(String JavaDoc key) {
93         return DebugPluginImages.getImage(key);
94     }
95     
96     /**
97      * Returns the shared image descriptor managed under the given key, or
98      * <code>null</code> if none.
99      * <p>
100      * See <code>IDebugUIConstants</code> for available image descriptors.
101      * </p>
102      *
103      * @param key the image descriptor key
104      * @return the image descriptor, or <code>null</code> if none
105      * @see IDebugUIConstants
106      */

107     public static ImageDescriptor getImageDescriptor(String JavaDoc key) {
108         return DebugPluginImages.getImageDescriptor(key);
109     }
110         
111     /**
112      * Returns the default image descriptor for the given element
113      * or <code>null</code> if none is defined.
114      */

115     public static ImageDescriptor getDefaultImageDescriptor(Object JavaDoc element) {
116         String JavaDoc imageKey= getDefaultImageKey(element);
117         if (imageKey == null) {
118             return null;
119         }
120         return DebugPluginImages.getImageDescriptor(imageKey);
121     }
122     
123     private static String JavaDoc getDefaultImageKey(Object JavaDoc element) {
124         return ((DefaultLabelProvider)DebugUIPlugin.getDefaultLabelProvider()).getImageKey(element);
125     }
126     
127     /**
128      * Returns the preference store for the debug UI plug-in.
129      *
130      * @return preference store
131      */

132     public static IPreferenceStore getPreferenceStore() {
133         return DebugUIPlugin.getDefault().getPreferenceStore();
134     }
135     
136     /**
137      * Returns a new debug model presentation that delegates to
138      * appropriate debug models.
139      * <p>
140      * It is the client's responsibility dispose the presentation.
141      * </p>
142      *
143      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
144      * @return a debug model presentation
145      * @since 2.0
146      */

147     public static IDebugModelPresentation newDebugModelPresentation() {
148         return new DelegatingModelPresentation();
149     }
150     
151     /**
152      * Returns a new debug model presentation for specified
153      * debug model, or <code>null</code> if a presentation does
154      * not exist.
155      * <p>
156      * It is the client's responsibility dispose the presentation.
157      * </p>
158      *
159      * @param identifier debug model identifier
160      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
161      * @return a debug model presentation, or <code>null</code>
162      * @since 2.0
163      */

164     public static IDebugModelPresentation newDebugModelPresentation(String JavaDoc identifier) {
165         IExtensionPoint point= Platform.getExtensionRegistry().getExtensionPoint(DebugUIPlugin.getUniqueIdentifier(), IDebugUIConstants.ID_DEBUG_MODEL_PRESENTATION);
166         if (point != null) {
167             IExtension[] extensions= point.getExtensions();
168             for (int i= 0; i < extensions.length; i++) {
169                 IExtension extension= extensions[i];
170                 IConfigurationElement[] configElements= extension.getConfigurationElements();
171                 for (int j= 0; j < configElements.length; j++) {
172                     IConfigurationElement elt= configElements[j];
173                     String JavaDoc id= elt.getAttribute("id"); //$NON-NLS-1$
174
if (id != null && id.equals(identifier)) {
175                         return new LazyModelPresentation(elt);
176                     }
177                 }
178             }
179         }
180         return null;
181     }
182     
183     /**
184      * Returns the currently selected element in the
185      * debug view of the current workbench page,
186      * or <code>null</code> if there is no current
187      * debug context.
188      * <p>
189      * This method used to return <code>null</code> when called from a non-UI thread,
190      * but since 3.1, this methods also works when called from a non-UI thread.
191      * </p>
192      * @return the currently selected debug context, or <code>null</code>
193      * @since 2.0
194      */

195     public static IAdaptable getDebugContext() {
196         IWorkbenchWindow activeWindow = SelectedResourceManager.getDefault().getActiveWindow();
197         if (activeWindow != null) {
198             ISelection activeContext = DebugUITools.getDebugContextManager().getContextService(activeWindow).getActiveContext();
199             if (activeContext instanceof IStructuredSelection) {
200                 IStructuredSelection selection = (IStructuredSelection) activeContext;
201                 if (!selection.isEmpty()) {
202                     Object JavaDoc firstElement = selection.getFirstElement();
203                     if (firstElement instanceof IAdaptable) {
204                         return (IAdaptable) firstElement;
205                     }
206                 }
207             }
208         }
209         return null;
210     }
211
212     /**
213      * Returns the currently selected resource in the active workbench window,
214      * or <code>null</code> if none. If an editor is active, the resource adapter
215      * associated with the editor is returned, if any.
216      *
217      * @return selected resource or <code>null</code>
218      * @since 3.0
219      */

220     public static IResource getSelectedResource() {
221         return SelectedResourceManager.getDefault().getSelectedResource();
222     }
223             
224     /**
225      * Returns the process associated with the current debug context.
226      * If there is no debug context currently, the most recently
227      * launched process is returned. If there is no current process
228      * <code>null</code> is returned.
229      *
230      * @return the current process, or <code>null</code>
231      * @since 2.0
232      */

233     public static IProcess getCurrentProcess() {
234         IAdaptable context = getDebugContext();
235         if (context == null) {
236             ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
237             if (launches.length > 0) {
238                 context = launches[launches.length - 1];
239             }
240         }
241         
242         if (context instanceof IDebugElement) {
243             return ((IDebugElement)context).getDebugTarget().getProcess();
244         }
245         
246         if (context instanceof IProcess) {
247             return (IProcess)context;
248         }
249         
250         if (context instanceof ILaunch) {
251             ILaunch launch= (ILaunch)context;
252             IDebugTarget target= launch.getDebugTarget();
253             if (target != null) {
254                 IProcess process = target.getProcess();
255                 if (process != null) {
256                     return process;
257                 }
258             }
259             IProcess[] ps = launch.getProcesses();
260             if (ps.length > 0) {
261                 return ps[ps.length - 1];
262             }
263         }
264         
265         if (context != null) {
266             return (IProcess) context.getAdapter(IProcess.class);
267         }
268         
269         return null;
270     }
271
272     /**
273      * Open the launch configuration dialog with the specified initial selection.
274      * The selection may be <code>null</code>, or contain any mix of
275      * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
276      * elements.
277      * <p>
278      * Before opening a new dialog, this method checks if there is an existing open
279      * launch configuration dialog. If there is, this dialog is used with the
280      * specified selection. If there is no existing dialog, a new one is created.
281      * </p>
282      * <p>
283      * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
284      * and the existing dialog keeps its original mode.
285      * </p>
286      *
287      * @param shell the parent shell for the launch configuration dialog
288      * @param selection the initial selection for the dialog
289      * @param mode the mode (run or debug) in which to open the launch configuration dialog.
290      * This should be one of the constants defined in <code>ILaunchManager</code>.
291      * @return the return code from opening the launch configuration dialog -
292      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
293      * @since 2.0
294      * @deprecated use openLaunchConfigurationDialogOnGroup(Shell, IStructuredSelection, String)
295      * to specify the launch group that the dialog should be opened on. This method will open
296      * on the launch group with the specified mode and a <code>null</code> category
297      */

298     public static int openLaunchConfigurationDialog(Shell shell, IStructuredSelection selection, String JavaDoc mode) {
299         ILaunchGroup[] groups = getLaunchGroups();
300         for (int i = 0; i < groups.length; i++) {
301             ILaunchGroup group = groups[i];
302             if (group.getMode().equals(mode) && group.getCategory() == null) {
303                 return openLaunchConfigurationDialogOnGroup(shell, selection, group.getIdentifier());
304             }
305         }
306         return Window.CANCEL;
307     }
308     
309     /**
310      * Open the launch configuration dialog with the specified initial selection.
311      * The selection may be <code>null</code>, or contain any mix of
312      * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
313      * elements.
314      * <p>
315      * Before opening a new dialog, this method checks if there is an existing open
316      * launch configuration dialog. If there is, this dialog is used with the
317      * specified selection. If there is no existing dialog, a new one is created.
318      * </p>
319      * <p>
320      * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
321      * and the existing dialog keeps its original mode.
322      * </p>
323      *
324      * @param shell the parent shell for the launch configuration dialog
325      * @param selection the initial selection for the dialog
326      * @param groupIdentifier the identifier of the launch group to display (corresponds to
327      * the identifier of a launch group extension)
328      * @return the return code from opening the launch configuration dialog -
329      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
330      * @since 2.1
331      */

332     public static int openLaunchConfigurationDialogOnGroup(Shell shell, IStructuredSelection selection, String JavaDoc groupIdentifier) {
333         return openLaunchConfigurationDialogOnGroup(shell, selection, groupIdentifier, null);
334     }
335     
336     /**
337      * Open the launch configuration dialog with the specified initial selection.
338      * The selection may be <code>null</code>, or contain any mix of
339      * <code>ILaunchConfiguration</code> or <code>ILaunchConfigurationType</code>
340      * elements.
341      * <p>
342      * Before opening a new dialog, this method checks if there is an existing open
343      * launch configuration dialog. If there is, this dialog is used with the
344      * specified selection. If there is no existing dialog, a new one is created.
345      * </p>
346      * <p>
347      * Note that if an existing dialog is reused, the <code>mode</code> argument is ignored
348      * and the existing dialog keeps its original mode.
349      * </p>
350      * <p>
351      * If a status is specified, a status handler is consulted to handle the
352      * status. The status handler is passed the instance of the launch
353      * configuration dialog that is opened. This gives the status handler an
354      * opportunity to perform error handling/initialization as required.
355      * </p>
356      * @param shell the parent shell for the launch configuration dialog
357      * @param selection the initial selection for the dialog
358      * @param groupIdentifier the identifier of the launch group to display (corresponds to
359      * the identifier of a launch group extension)
360      * @param status the status to display in the dialog, or <code>null</code>
361      * if none
362      * @return the return code from opening the launch configuration dialog -
363      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
364      * @see org.eclipse.debug.core.IStatusHandler
365      * @since 2.1
366      */

367     public static int openLaunchConfigurationDialogOnGroup(final Shell shell, final IStructuredSelection selection, final String JavaDoc groupIdentifier, final IStatus status) {
368         final int[] result = new int[1];
369         Runnable JavaDoc r = new Runnable JavaDoc() {
370             /**
371              * @see java.lang.Runnable#run()
372              */

373             public void run() {
374                 LaunchConfigurationsDialog dialog = (LaunchConfigurationsDialog) LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog();
375                 if (dialog != null) {
376                     dialog.setInitialSelection(selection);
377                     dialog.doInitialTreeSelection();
378                     if (status != null) {
379                         dialog.handleStatus(status);
380                     }
381                     result[0] = Window.OK;
382                 } else {
383                     dialog = new LaunchConfigurationsDialog(shell, DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier));
384                     dialog.setOpenMode(LaunchConfigurationsDialog.LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION);
385                     dialog.setInitialSelection(selection);
386                     dialog.setInitialStatus(status);
387                     result[0] = dialog.open();
388                 }
389             }
390         };
391         BusyIndicator.showWhile(DebugUIPlugin.getStandardDisplay(), r);
392         return result[0];
393     }
394         
395     /**
396      * Open the launch configuration properties dialog on the specified launch
397      * configuration.
398      *
399      * @param shell the parent shell for the launch configuration dialog
400      * @param configuration the configuration to display
401      * @param groupIdentifier group identifier of the launch group the launch configuration
402      * belongs to
403      * @return the return code from opening the launch configuration dialog -
404      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
405      * @since 2.1
406      */

407     public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String JavaDoc groupIdentifier) {
408         return openLaunchConfigurationPropertiesDialog(shell, configuration, groupIdentifier, null);
409     }
410     
411     /**
412      * Open the launch configuration properties dialog on the specified launch
413      * configuration.
414      *
415      * @param shell the parent shell for the launch configuration dialog
416      * @param configuration the configuration to display
417      * @param groupIdentifier group identifier of the launch group the launch configuration
418      * belongs to
419      * @param status the status to display, or <code>null</code> if none
420      * @return the return code from opening the launch configuration dialog -
421      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
422      * @since 3.0
423      */

424     public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String JavaDoc groupIdentifier, IStatus status) {
425         LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier);
426         if (group != null) {
427             LaunchConfigurationPropertiesDialog dialog = new LaunchConfigurationPropertiesDialog(shell, configuration, group);
428             dialog.setInitialStatus(status);
429             return dialog.open();
430         }
431         
432         return Window.CANCEL;
433     }
434     
435     /**
436      * Open the launch configuration dialog on the specified launch
437      * configuration. The dialog displays the tabs for a single configuration
438      * only (a tree of launch configuration is not displayed), and provides a
439      * launch (run or debug) button.
440      * <p>
441      * If a status is specified, a status handler is consulted to handle the
442      * status. The status handler is passed the instance of the launch
443      * configuration dialog that is opened. This gives the status handler an
444      * opportunity to perform error handling/initialization as required.
445      * </p>
446      * @param shell the parent shell for the launch configuration dialog
447      * @param configuration the configuration to display
448      * @param groupIdentifier group identifier of the launch group the launch configuration
449      * belongs to
450      * @param status the status to display, or <code>null</code> if none
451      * @return the return code from opening the launch configuration dialog -
452      * one of <code>Window.OK</code> or <code>Window.CANCEL</code>
453      * @since 2.1
454      */

455     public static int openLaunchConfigurationDialog(Shell shell, ILaunchConfiguration configuration, String JavaDoc groupIdentifier, IStatus status) {
456         LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier);
457         if (group != null) {
458             LaunchConfigurationDialog dialog = new LaunchConfigurationDialog(shell, configuration, group);
459             dialog.setInitialStatus(status);
460             return dialog.open();
461         }
462             
463         return Window.CANCEL;
464     }
465     
466     /**
467      * Saves all dirty editors and builds the workspace according to current
468      * preference settings, and returns whether a launch should proceed.
469      * <p>
470      * The following preferences effect whether dirty editors are saved,
471      * and/or if the user is prompted to save dirty editors:<ul>
472      * <li>PREF_NEVER_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
473      * <li>PREF_PROMPT_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
474      * <li>PREF_AUTOSAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
475      * </ul>
476      * The following preference effects whether a build is performed before
477      * launching (if required):<ul>
478      * <li>PREF_BUILD_BEFORE_LAUNCH</li>
479      * </ul>
480      * </p>
481      *
482      * @return whether a launch should proceed
483      * @since 2.0
484      * @deprecated Saving has been moved to the launch delegate <code>LaunchConfigurationDelegate</code> to allow for scoped saving
485      * of resources that are only involved in the current launch, no longer the entire workspace
486      */

487     public static boolean saveAndBuildBeforeLaunch() {
488         return DebugUIPlugin.saveAndBuild();
489     }
490     
491     /**
492      * Saves all dirty editors according to current
493      * preference settings, and returns whether a launch should proceed.
494      * <p>
495      * The following preferences effect whether dirty editors are saved,
496      * and/or if the user is prompted to save dirty editors:<ul>
497      * <li>PREF_NEVER_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
498      * <li>PREF_PROMPT_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
499      * <li>PREF_AUTOSAVE_DIRTY_EDITORS_BEFORE_LAUNCH</li>
500      * </ul>
501      * </p>
502      *
503      * @return whether a launch should proceed
504      * @since 2.1
505      * @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      */

508     public static boolean saveBeforeLaunch() {
509         return DebugUIPlugin.preLaunchSave();
510     }
511     
512     /**
513      * Saves and builds the workspace according to current preference settings, and
514      * launches the given launch configuration in the specified mode.
515      *
516      * @param configuration the configuration to launch
517      * @param mode launch mode - run or debug
518      * @since 2.1
519      */

520     public static void launch(final ILaunchConfiguration configuration, final String JavaDoc mode) {
521         boolean launchInBackground= true;
522         try {
523             launchInBackground= configuration.getAttribute(IDebugUIConstants.ATTR_LAUNCH_IN_BACKGROUND, true);
524         } catch (CoreException e) {
525             DebugUIPlugin.log(e);
526         }
527         if (launchInBackground) {
528             DebugUIPlugin.launchInBackground(configuration, mode);
529         } else {
530             DebugUIPlugin.launchInForeground(configuration, mode);
531         }
532     }
533     
534
535     
536     /**
537      * Builds the workspace according to current preference settings, and launches
538      * the given configuration in the specified mode, returning the resulting launch
539      * object.
540      * <p>
541      * The following preference effects whether a build is performed before
542      * launching (if required):<ul>
543      * <li>PREF_BUILD_BEFORE_LAUNCH</li>
544      * </ul>
545      * </p>
546      *
547      * @param configuration the configuration to launch
548      * @param mode the mode to launch in
549      * @param monitor progress monitor
550      * @return the resulting launch object
551      * @throws CoreException if building or launching fails
552      * @since 2.1
553      */

554     public static ILaunch buildAndLaunch(ILaunchConfiguration configuration, String JavaDoc mode, IProgressMonitor monitor) throws CoreException {
555         return DebugUIPlugin.buildAndLaunch(configuration, mode, monitor);
556     }
557     
558     /**
559      * Returns the perspective to switch to when a configuration of the given type
560      * is launched in the given mode, or <code>null</code> if no switch should take
561      * place.
562      *
563      * In 3.3 this method is equivalent to calling <code>getLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate)</code>,
564      * with the 'mode' parameter comprising a single element set and passing <code>null</code> as the launch delegate.
565      *
566      * @param type launch configuration type
567      * @param mode launch mode identifier
568      * @return perspective identifier or <code>null</code>
569      * @since 3.0
570      */

571     public static String JavaDoc getLaunchPerspective(ILaunchConfigurationType type, String JavaDoc mode) {
572         return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, mode);
573     }
574     
575     /**
576      * Returns the perspective id to switch to when a configuration of the given type launched with the specified delegate
577      * is launched in the given mode set, or <code>null</code> if no switch should occurr.
578      * @param type the configuration type
579      * @param delegate the launch delegate
580      * @param modes the set of modes
581      * @return the perspective id or <code>null</code> if no switch should occur
582      *
583      * @since 3.3
584      */

585     public static String JavaDoc getLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set JavaDoc modes) {
586         return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, modes, delegate);
587     }
588     
589     /**
590      * Sets the perspective to switch to when a configuration of the given type
591      * is launched in the given mode. <code>PERSPECTIVE_NONE</code> indicates no
592      * perspective switch should take place. <code>PERSPECTIVE_DEFAULT</code> indicates
593      * a default perspective switch should take place, as defined by the associated
594      * launch tab group extension.
595      *
596      * In 3.3 this method is equivalent to calling <code>setLaunchPerspective(ILaunchConfigurationType type, Set modes, ILaunchDelegate delegate, String perspectiveid)</code>,
597      * with the parameter 'mode' used in the set modes, and null passed as the delegate
598      *
599      * @param type launch configuration type
600      * @param mode launch mode identifier
601      * @param perspective identifier, <code>PERSPECTIVE_NONE</code>, or
602      * <code>PERSPECTIVE_DEFAULT</code>
603      * @since 3.0
604      */

605     public static void setLaunchPerspective(ILaunchConfigurationType type, String JavaDoc mode, String JavaDoc perspective) {
606         DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, mode, perspective);
607     }
608     
609     /**
610      * Sets the perspective to switch to when a configuration of the specified type and launched using the
611      * specified launch delegate is launched in the specified modeset. <code>PERSPECTIVE_NONE</code> indicates no
612      * perspective switch should take place.
613      *
614      * Passing <code>null</code> for the launch delegate is quivalent to using the default perspective for the specified
615      * type.
616      * @param type the configuration type
617      * @param delegate the launch delegate
618      * @param modes the set of modes
619      * @param perspectiveid identifier or <code>PERSPECTIVE_NONE</code>
620      *
621      * @since 3.3
622      */

623     public static void setLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set JavaDoc modes, String JavaDoc perspectiveid) {
624         DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, modes, delegate, perspectiveid);
625     }
626     
627     /**
628      * Returns whether the given launch configuration is private. Generally,
629      * private launch configurations should not be displayed to the user. The
630      * private status of a launch configuration is determined by the
631      * <code>IDebugUIConstants.ATTR_PRIVATE</code> attribute.
632      *
633      * @param configuration launch configuration
634      * @return whether the given launch configuration is private
635      * @since 3.0
636      */

637     public static boolean isPrivate(ILaunchConfiguration configuration) {
638         return !LaunchConfigurationManager.isVisible(configuration);
639     }
640
641     /**
642      * Sets whether step filters should be applied to step commands. This
643      * setting is a global option applied to all registered debug targets.
644      * <p>
645      * Since 3.3, this is equivalent to calling <code>DebugPlugin.setUseStepFilters(boolean)</code>.
646      * </p>
647      * @param useStepFilters whether step filters should be applied to step
648      * commands
649      * @since 3.0
650      * @see org.eclipse.debug.core.model.IStepFilters
651      */

652     public static void setUseStepFilters(boolean useStepFilters) {
653         DebugPlugin.setUseStepFilters(useStepFilters);
654     }
655         
656     /**
657      * Returns whether step filters are applied to step commands.
658      * <p>
659      * Since 3.3, this is equivalent to calling <code>DebugPlugin.isUseStepFilters()</code>.
660      * </p>
661      * @return whether step filters are applied to step commands
662      * @since 3.0
663      * @see org.eclipse.debug.core.model.IStepFilters
664      */

665     public static boolean isUseStepFilters() {
666         return DebugPlugin.isUseStepFilters();
667     }
668         
669     /**
670      * Returns the console associated with the given process, or
671      * <code>null</code> if none.
672      *
673      * @param process a process
674      * @return console associated with the given process, or
675      * <code>null</code> if none
676      * @since 3.0
677      */

678     public static IConsole getConsole(IProcess process) {
679         return DebugUIPlugin.getDefault().getProcessConsoleManager().getConsole(process);
680     }
681     
682     /**
683      * Returns the console associated with the given debug element, or
684      * <code>null</code> if none.
685      *
686      * @param element a debug model element
687      * @return console associated with the given element, or
688      * <code>null</code> if none
689      * @since 3.0
690      */

691     public static IConsole getConsole(IDebugElement element) {
692         IProcess process = element.getDebugTarget().getProcess();
693         if (process != null) {
694             return getConsole(process);
695         }
696         return null;
697     }
698     
699     /**
700      * Returns all registered launch group extensions.
701      *
702      * @return all registered launch group extensions
703      * @since 3.0
704      */

705     public static ILaunchGroup[] getLaunchGroups() {
706         return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroups();
707     }
708     
709     /**
710      * Returns the last configuration that was launched for specified launch group or
711      * <code>null</code>, if there is not one. This method does not provide any form of
712      * filtering on the returned launch configurations.
713      *
714      * @param groupId the unique identifier of a launch group
715      * @return the last launched configuration for the specified group or <code>null</code>.
716      * @see DebugUITools#getLaunchGroups()
717      * @since 3.3
718      */

719     public static ILaunchConfiguration getLastLaunch(String JavaDoc groupId) {
720         return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLastLaunch(groupId);
721     }
722     
723     /**
724      * Returns the launch group that the given launch configuration belongs
725      * to, for the specified mode, or <code>null</code> if none.
726      *
727      * @param configuration
728      * @param mode
729      * @return the launch group the given launch configuration belongs to, for
730      * the specified mode, or <code>null</code> if none
731      * @since 3.0
732      */

733     public static ILaunchGroup getLaunchGroup(ILaunchConfiguration configuration, String JavaDoc mode) {
734         return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configuration, mode);
735     }
736     
737     /**
738      * Performs source lookup on the given artifact and returns the result.
739      * Optionally, a source locator may be specified.
740      *
741      * @param artifact object for which source is to be resolved
742      * @param locator the source locator to use, or <code>null</code>. When <code>null</code>
743      * a source locator is determined from the artifact, if possible. If the artifact
744      * is a debug element, the source locator from its associated launch is used.
745      * @return a source lookup result
746      * @since 3.1
747      */

748     public static ISourceLookupResult lookupSource(Object JavaDoc artifact, ISourceLocator locator) {
749         return SourceLookupFacility.getDefault().lookup(artifact, locator);
750     }
751     
752     /**
753      * Displays the given source lookup result in an editor in the given workbench
754      * page. Has no effect if the result has an unknown editor id or editor input.
755      * The editor is opened, positioned, and annotated.
756      * <p>
757      * Honors user preference for editors re-use.
758      * </p>
759      * @param result source lookup result to display
760      * @param page the page to display the result in
761      * @since 3.1
762      */

763     public static void displaySource(ISourceLookupResult result, IWorkbenchPage page) {
764         SourceLookupFacility.getDefault().display(result, page);
765     }
766     
767     /**
768      * Returns the memory rendering manager.
769      *
770      * @return the memory rendering manager
771      * @since 3.1
772      */

773     public static IMemoryRenderingManager getMemoryRenderingManager() {
774         return MemoryRenderingManager.getDefault();
775     }
776     
777     /**
778      * Returns the image associated with the specified type of source container
779      * or <code>null</code> if none.
780      *
781      * @param id unique identifier for a source container type
782      * @return image associated with the specified type of source container
783      * or <code>null</code> if none
784      * @since 3.2
785      * @see org.eclipse.debug.core.sourcelookup.ISourceContainerType
786      */

787     public static Image getSourceContainerImage(String JavaDoc id){
788         return SourceLookupUIUtils.getSourceContainerImage(id);
789     }
790     
791     /**
792      * Returns a new source container browser for the specified type of source container
793      * or <code>null</code> if a browser has not been registered.
794      *
795      * @param id unique identifier for a source container type
796      * @return source container browser or <code>null</code> if none
797      * @since 3.2
798      * @see org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser
799      */

800     public static ISourceContainerBrowser getSourceContainerBrowser(String JavaDoc id) {
801         return SourceLookupUIUtils.getSourceContainerBrowser(id);
802     }
803     
804     /**
805      * Returns the color associated with the specified preference identifier or
806      * <code>null</code> if none.
807      *
808      * @param id preference identifier of the color
809      * @return the color associated with the specified preference identifier
810      * or <code>null</code> if none
811      * @since 3.2
812      * @see IDebugUIConstants
813      */

814     public static Color getPreferenceColor(String JavaDoc id) {
815         return DebugUIPlugin.getPreferenceColor(id);
816     }
817     
818     /**
819      * Returns the debug context manager.
820      *
821      * @return debug context manager
822      * @since 3.3
823      */

824     public static IDebugContextManager getDebugContextManager() {
825         return DebugContextManager.getDefault();
826     }
827 }
828
Popular Tags