1 11 package org.eclipse.debug.ui; 12 13 14 import java.util.Set ; 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 76 public class DebugUITools { 77 78 92 public static Image getImage(String key) { 93 return DebugPluginImages.getImage(key); 94 } 95 96 107 public static ImageDescriptor getImageDescriptor(String key) { 108 return DebugPluginImages.getImageDescriptor(key); 109 } 110 111 115 public static ImageDescriptor getDefaultImageDescriptor(Object element) { 116 String imageKey= getDefaultImageKey(element); 117 if (imageKey == null) { 118 return null; 119 } 120 return DebugPluginImages.getImageDescriptor(imageKey); 121 } 122 123 private static String getDefaultImageKey(Object element) { 124 return ((DefaultLabelProvider)DebugUIPlugin.getDefaultLabelProvider()).getImageKey(element); 125 } 126 127 132 public static IPreferenceStore getPreferenceStore() { 133 return DebugUIPlugin.getDefault().getPreferenceStore(); 134 } 135 136 147 public static IDebugModelPresentation newDebugModelPresentation() { 148 return new DelegatingModelPresentation(); 149 } 150 151 164 public static IDebugModelPresentation newDebugModelPresentation(String 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 id= elt.getAttribute("id"); if (id != null && id.equals(identifier)) { 175 return new LazyModelPresentation(elt); 176 } 177 } 178 } 179 } 180 return null; 181 } 182 183 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 firstElement = selection.getFirstElement(); 203 if (firstElement instanceof IAdaptable) { 204 return (IAdaptable) firstElement; 205 } 206 } 207 } 208 } 209 return null; 210 } 211 212 220 public static IResource getSelectedResource() { 221 return SelectedResourceManager.getDefault().getSelectedResource(); 222 } 223 224 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 298 public static int openLaunchConfigurationDialog(Shell shell, IStructuredSelection selection, String 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 332 public static int openLaunchConfigurationDialogOnGroup(Shell shell, IStructuredSelection selection, String groupIdentifier) { 333 return openLaunchConfigurationDialogOnGroup(shell, selection, groupIdentifier, null); 334 } 335 336 367 public static int openLaunchConfigurationDialogOnGroup(final Shell shell, final IStructuredSelection selection, final String groupIdentifier, final IStatus status) { 368 final int[] result = new int[1]; 369 Runnable r = new Runnable () { 370 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 407 public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier) { 408 return openLaunchConfigurationPropertiesDialog(shell, configuration, groupIdentifier, null); 409 } 410 411 424 public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String 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 455 public static int openLaunchConfigurationDialog(Shell shell, ILaunchConfiguration configuration, String 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 487 public static boolean saveAndBuildBeforeLaunch() { 488 return DebugUIPlugin.saveAndBuild(); 489 } 490 491 508 public static boolean saveBeforeLaunch() { 509 return DebugUIPlugin.preLaunchSave(); 510 } 511 512 520 public static void launch(final ILaunchConfiguration configuration, final String 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 554 public static ILaunch buildAndLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { 555 return DebugUIPlugin.buildAndLaunch(configuration, mode, monitor); 556 } 557 558 571 public static String getLaunchPerspective(ILaunchConfigurationType type, String mode) { 572 return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, mode); 573 } 574 575 585 public static String getLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes) { 586 return DebugUIPlugin.getDefault().getPerspectiveManager().getLaunchPerspective(type, modes, delegate); 587 } 588 589 605 public static void setLaunchPerspective(ILaunchConfigurationType type, String mode, String perspective) { 606 DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, mode, perspective); 607 } 608 609 623 public static void setLaunchPerspective(ILaunchConfigurationType type, ILaunchDelegate delegate, Set modes, String perspectiveid) { 624 DebugUIPlugin.getDefault().getPerspectiveManager().setLaunchPerspective(type, modes, delegate, perspectiveid); 625 } 626 627 637 public static boolean isPrivate(ILaunchConfiguration configuration) { 638 return !LaunchConfigurationManager.isVisible(configuration); 639 } 640 641 652 public static void setUseStepFilters(boolean useStepFilters) { 653 DebugPlugin.setUseStepFilters(useStepFilters); 654 } 655 656 665 public static boolean isUseStepFilters() { 666 return DebugPlugin.isUseStepFilters(); 667 } 668 669 678 public static IConsole getConsole(IProcess process) { 679 return DebugUIPlugin.getDefault().getProcessConsoleManager().getConsole(process); 680 } 681 682 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 705 public static ILaunchGroup[] getLaunchGroups() { 706 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroups(); 707 } 708 709 719 public static ILaunchConfiguration getLastLaunch(String groupId) { 720 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLastLaunch(groupId); 721 } 722 723 733 public static ILaunchGroup getLaunchGroup(ILaunchConfiguration configuration, String mode) { 734 return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configuration, mode); 735 } 736 737 748 public static ISourceLookupResult lookupSource(Object artifact, ISourceLocator locator) { 749 return SourceLookupFacility.getDefault().lookup(artifact, locator); 750 } 751 752 763 public static void displaySource(ISourceLookupResult result, IWorkbenchPage page) { 764 SourceLookupFacility.getDefault().display(result, page); 765 } 766 767 773 public static IMemoryRenderingManager getMemoryRenderingManager() { 774 return MemoryRenderingManager.getDefault(); 775 } 776 777 787 public static Image getSourceContainerImage(String id){ 788 return SourceLookupUIUtils.getSourceContainerImage(id); 789 } 790 791 800 public static ISourceContainerBrowser getSourceContainerBrowser(String id) { 801 return SourceLookupUIUtils.getSourceContainerBrowser(id); 802 } 803 804 814 public static Color getPreferenceColor(String id) { 815 return DebugUIPlugin.getPreferenceColor(id); 816 } 817 818 824 public static IDebugContextManager getDebugContextManager() { 825 return DebugContextManager.getDefault(); 826 } 827 } 828 | Popular Tags |