1 12 package org.eclipse.debug.internal.ui; 13 14 15 import java.io.ByteArrayOutputStream ; 16 import java.io.IOException ; 17 import java.lang.reflect.InvocationTargetException ; 18 import java.net.URL ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Set ; 22 23 import javax.xml.parsers.DocumentBuilder ; 24 import javax.xml.parsers.DocumentBuilderFactory ; 25 import javax.xml.parsers.ParserConfigurationException ; 26 import javax.xml.transform.OutputKeys ; 27 import javax.xml.transform.Transformer ; 28 import javax.xml.transform.TransformerException ; 29 import javax.xml.transform.TransformerFactory ; 30 import javax.xml.transform.dom.DOMSource ; 31 import javax.xml.transform.stream.StreamResult ; 32 33 import org.eclipse.core.resources.ISaveContext; 34 import org.eclipse.core.resources.ISaveParticipant; 35 import org.eclipse.core.resources.IncrementalProjectBuilder; 36 import org.eclipse.core.resources.ResourcesPlugin; 37 import org.eclipse.core.runtime.CoreException; 38 import org.eclipse.core.runtime.FileLocator; 39 import org.eclipse.core.runtime.IAdapterManager; 40 import org.eclipse.core.runtime.IConfigurationElement; 41 import org.eclipse.core.runtime.IProgressMonitor; 42 import org.eclipse.core.runtime.IStatus; 43 import org.eclipse.core.runtime.Path; 44 import org.eclipse.core.runtime.Platform; 45 import org.eclipse.core.runtime.Status; 46 import org.eclipse.core.runtime.SubProgressMonitor; 47 import org.eclipse.core.runtime.jobs.IJobChangeEvent; 48 import org.eclipse.core.runtime.jobs.IJobChangeListener; 49 import org.eclipse.core.runtime.jobs.IJobManager; 50 import org.eclipse.core.runtime.jobs.Job; 51 import org.eclipse.debug.core.DebugException; 52 import org.eclipse.debug.core.DebugPlugin; 53 import org.eclipse.debug.core.IExpressionManager; 54 import org.eclipse.debug.core.ILaunch; 55 import org.eclipse.debug.core.ILaunchConfiguration; 56 import org.eclipse.debug.core.ILaunchConfigurationType; 57 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy; 58 import org.eclipse.debug.core.ILaunchListener; 59 import org.eclipse.debug.core.ILaunchManager; 60 import org.eclipse.debug.core.IStatusHandler; 61 import org.eclipse.debug.core.Launch; 62 import org.eclipse.debug.core.model.IDebugElement; 63 import org.eclipse.debug.core.model.IDebugTarget; 64 import org.eclipse.debug.core.model.IExpression; 65 import org.eclipse.debug.core.model.IMemoryBlockRetrieval; 66 import org.eclipse.debug.core.model.IProcess; 67 import org.eclipse.debug.core.model.IRegister; 68 import org.eclipse.debug.core.model.IRegisterGroup; 69 import org.eclipse.debug.core.model.IStackFrame; 70 import org.eclipse.debug.core.model.IThread; 71 import org.eclipse.debug.core.model.IVariable; 72 import org.eclipse.debug.internal.ui.contextlaunching.LaunchingResourceManager; 73 import org.eclipse.debug.internal.ui.contexts.SuspendTriggerAdapterFactory; 74 import org.eclipse.debug.internal.ui.launchConfigurations.ClosedProjectFilter; 75 import org.eclipse.debug.internal.ui.launchConfigurations.DeletedProjectFilter; 76 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationEditDialog; 77 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; 78 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPropertiesDialog; 79 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationTypeFilter; 80 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchGroupExtension; 81 import org.eclipse.debug.internal.ui.launchConfigurations.PerspectiveManager; 82 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; 83 import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupManager; 84 import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager; 85 import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointOrganizerManager; 86 import org.eclipse.debug.internal.ui.views.breakpoints.OtherBreakpointCategory; 87 import org.eclipse.debug.internal.ui.views.console.ProcessConsoleManager; 88 import org.eclipse.debug.internal.ui.views.launch.DebugElementAdapterFactory; 89 import org.eclipse.debug.internal.ui.views.launch.DebugElementHelper; 90 import org.eclipse.debug.internal.ui.views.memory.renderings.MemorySegment; 91 import org.eclipse.debug.ui.DebugUITools; 92 import org.eclipse.debug.ui.IDebugModelPresentation; 93 import org.eclipse.debug.ui.IDebugUIConstants; 94 import org.eclipse.debug.ui.ILaunchGroup; 95 import org.eclipse.jface.dialogs.ErrorDialog; 96 import org.eclipse.jface.dialogs.IDialogConstants; 97 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 98 import org.eclipse.jface.operation.IRunnableWithProgress; 99 import org.eclipse.jface.preference.IPreferenceStore; 100 import org.eclipse.jface.preference.PreferenceConverter; 101 import org.eclipse.jface.resource.ImageDescriptor; 102 import org.eclipse.jface.resource.ImageRegistry; 103 import org.eclipse.jface.viewers.ILabelProvider; 104 import org.eclipse.jface.viewers.StructuredSelection; 105 import org.eclipse.jface.window.Window; 106 import org.eclipse.swt.custom.BusyIndicator; 107 import org.eclipse.swt.graphics.Color; 108 import org.eclipse.swt.widgets.Display; 109 import org.eclipse.swt.widgets.Shell; 110 import org.eclipse.ui.IWorkbench; 111 import org.eclipse.ui.IWorkbenchWindow; 112 import org.eclipse.ui.PlatformUI; 113 import org.eclipse.ui.plugin.AbstractUIPlugin; 114 import org.eclipse.ui.progress.IProgressService; 115 import org.osgi.framework.Bundle; 116 import org.osgi.framework.BundleContext; 117 import org.osgi.service.packageadmin.PackageAdmin; 118 import org.osgi.util.tracker.ServiceTracker; 119 import org.w3c.dom.Document ; 120 121 import com.ibm.icu.text.MessageFormat; 122 123 135 public class DebugUIPlugin extends AbstractUIPlugin implements ILaunchListener { 136 137 138 141 private static DebugUIPlugin fgDebugUIPlugin = null; 142 143 146 protected static IDebugModelPresentation fgPresentation = null; 147 148 151 private static DefaultLabelProvider fgDefaultLabelProvider; 152 153 159 public static String ATTR_LAUNCHING_CONFIG_HANDLE= getUniqueIdentifier() + "launching_config_handle"; 161 164 private ProcessConsoleManager fProcessConsoleManager = null; 165 166 169 private PerspectiveManager fPerspectiveManager = null; 170 171 174 private LaunchConfigurationManager fLaunchConfigurationManager = null; 175 176 179 private LaunchingResourceManager fContextLaunchingManager = null; 180 181 186 private ImageDescriptorRegistry fImageDescriptorRegistry; 187 188 192 private ServiceTracker fServiceTracker; 193 private PackageAdmin fPackageAdminService; 194 195 200 private Set fSaveParticipants = new HashSet (); 201 202 public static boolean DEBUG = false; 203 204 210 public static class PendingLaunch extends Launch { 211 private Job fJob; 212 public PendingLaunch(ILaunchConfiguration launchConfiguration, String mode, Job job) { 213 super(launchConfiguration, mode, null); 214 fJob= job; 215 } 216 217 public boolean canTerminate() { 220 return true; 221 } 222 223 public void terminate() throws DebugException { 224 fJob.cancel(); 225 } 226 } 227 228 236 public Bundle getBundle(Class clazz) { 237 if (fPackageAdminService != null) { 238 return fPackageAdminService.getBundle(clazz); 239 } 240 return null; 241 } 242 243 246 public DebugUIPlugin() { 247 super(); 248 fgDebugUIPlugin= this; 249 } 250 251 255 public static void debug(String message) { 256 if (DEBUG) { 257 System.out.println(message); 258 } 259 } 260 261 264 public static DebugUIPlugin getDefault() { 265 if(fgDebugUIPlugin == null) { 266 fgDebugUIPlugin = new DebugUIPlugin(); 267 } 268 return fgDebugUIPlugin; 269 } 270 271 274 public static String getUniqueIdentifier() { 275 return IDebugUIConstants.PLUGIN_ID; 276 } 277 278 282 public static IDebugModelPresentation getModelPresentation() { 283 if (fgPresentation == null) { 284 fgPresentation = new DelegatingModelPresentation(); 285 } 286 return fgPresentation; 287 } 288 289 293 public LaunchConfigurationManager getLaunchConfigurationManager() { 294 if (fLaunchConfigurationManager == null) { 295 fLaunchConfigurationManager = new LaunchConfigurationManager(); 296 } 297 return fLaunchConfigurationManager; 298 } 299 300 307 public LaunchingResourceManager getLaunchingResourceManager() { 308 if(fContextLaunchingManager == null) { 309 fContextLaunchingManager = new LaunchingResourceManager(); 310 fContextLaunchingManager.startup(); 311 } 312 return fContextLaunchingManager; 313 } 314 315 321 public static IWorkbenchWindow getActiveWorkbenchWindow() { 322 return getDefault().getWorkbench().getActiveWorkbenchWindow(); 323 } 324 325 331 public static Shell getShell() { 332 IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); 333 if (window == null) { 334 IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); 335 if (windows.length > 0) { 336 return windows[0].getShell(); 337 } 338 } 339 else { 340 return window.getShell(); 341 } 342 return null; 343 } 344 345 348 public static ILabelProvider getDefaultLabelProvider() { 349 if (fgDefaultLabelProvider == null) { 350 fgDefaultLabelProvider = new DefaultLabelProvider(); 351 } 352 return fgDefaultLabelProvider; 353 } 354 355 364 public static Object createExtension(final IConfigurationElement element, final String classAttribute) throws CoreException { 365 Bundle bundle = Platform.getBundle(element.getContributor().getName()); 368 if (bundle.getState() == Bundle.ACTIVE) { 369 return element.createExecutableExtension(classAttribute); 370 } 371 final Object [] ret = new Object [1]; 372 final CoreException [] exc = new CoreException[1]; 373 BusyIndicator.showWhile(null, new Runnable () { 374 public void run() { 375 try { 376 ret[0] = element.createExecutableExtension(classAttribute); 377 } catch (CoreException e) { 378 exc[0] = e; 379 } 380 } 381 }); 382 if (exc[0] != null) { 383 throw exc[0]; 384 } 385 return ret[0]; 386 } 387 388 391 protected ImageRegistry createImageRegistry() { 392 return DebugPluginImages.initializeImageRegistry(); 393 } 394 395 398 public void stop(BundleContext context) throws Exception { 399 try { 400 if (fProcessConsoleManager != null) { 401 fProcessConsoleManager.shutdown(); 402 } 403 404 BreakpointOrganizerManager.getDefault().shutdown(); 405 406 if (fPerspectiveManager != null) { 407 fPerspectiveManager.shutdown(); 408 } 409 if (fLaunchConfigurationManager != null) { 410 fLaunchConfigurationManager.shutdown(); 411 } 412 if(fContextLaunchingManager != null) { 413 fContextLaunchingManager.shutdown(); 414 } 415 416 ColorManager.getDefault().dispose(); 417 418 if (fgPresentation != null) { 419 fgPresentation.dispose(); 420 } 421 422 if (fImageDescriptorRegistry != null) { 423 fImageDescriptorRegistry.dispose(); 424 } 425 426 SourceLookupFacility.shutdown(); 427 428 DebugElementHelper.dispose(); 429 430 fServiceTracker.close(); 431 fPackageAdminService = null; 432 433 fSaveParticipants.clear(); 434 435 ResourcesPlugin.getWorkspace().removeSaveParticipant(this); 436 437 } finally { 438 super.stop(context); 439 } 440 } 441 442 449 public boolean addSaveParticipant(ISaveParticipant participant) { 450 return fSaveParticipants.add(participant); 451 } 452 453 461 public boolean removeSaveParticipant(ISaveParticipant participant) { 462 return fSaveParticipants.remove(participant); 463 } 464 465 468 public void start(BundleContext context) throws Exception { 469 super.start(context); 470 ResourcesPlugin.getWorkspace().addSaveParticipant(this, 471 new ISaveParticipant() { 472 public void saving(ISaveContext saveContext) throws CoreException { 473 savePluginPreferences(); 474 for(Iterator iter = fSaveParticipants.iterator(); iter.hasNext();) { 475 ((ISaveParticipant)iter.next()).saving(saveContext); 476 } 477 } 478 public void rollback(ISaveContext saveContext) { 479 for(Iterator iter = fSaveParticipants.iterator(); iter.hasNext();) { 480 ((ISaveParticipant)iter.next()).rollback(saveContext); 481 } 482 } 483 public void prepareToSave(ISaveContext saveContext) throws CoreException { 484 for(Iterator iter = fSaveParticipants.iterator(); iter.hasNext();) { 485 ((ISaveParticipant)iter.next()).prepareToSave(saveContext); 486 } 487 } 488 public void doneSaving(ISaveContext saveContext) { 489 for(Iterator iter = fSaveParticipants.iterator(); iter.hasNext();) { 490 ((ISaveParticipant)iter.next()).doneSaving(saveContext); 491 } 492 } 493 }); 494 DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.debug.ui/debug")); 496 fPerspectiveManager = new PerspectiveManager(); 499 fPerspectiveManager.startup(); 500 501 getLaunchingResourceManager(); 502 503 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 505 506 BreakpointOrganizerManager.getDefault(); 508 509 IAdapterManager manager= Platform.getAdapterManager(); 510 DebugElementAdapterFactory propertiesFactory = new DebugElementAdapterFactory(); 511 manager.registerAdapters(propertiesFactory, ILaunchManager.class); 512 manager.registerAdapters(propertiesFactory, ILaunch.class); 513 manager.registerAdapters(propertiesFactory, IDebugTarget.class); 514 manager.registerAdapters(propertiesFactory, IProcess.class); 515 manager.registerAdapters(propertiesFactory, IThread.class); 516 manager.registerAdapters(propertiesFactory, IStackFrame.class); 517 manager.registerAdapters(propertiesFactory, IRegisterGroup.class); 518 manager.registerAdapters(propertiesFactory, IVariable.class); 519 manager.registerAdapters(propertiesFactory, IRegister.class); 520 manager.registerAdapters(propertiesFactory, IExpression.class); 521 manager.registerAdapters(propertiesFactory, IExpressionManager.class); 522 manager.registerAdapters(propertiesFactory, OtherBreakpointCategory.class); 523 manager.registerAdapters(propertiesFactory, IDebugElement.class); 524 manager.registerAdapters(propertiesFactory, IMemoryBlockRetrieval.class); 525 manager.registerAdapters(propertiesFactory, MemorySegment.class); 526 DebugUIAdapterFactory uiFactory = new DebugUIAdapterFactory(); 527 manager.registerAdapters(uiFactory, ILaunchConfiguration.class); 528 manager.registerAdapters(uiFactory, ILaunchConfigurationType.class); 529 SuspendTriggerAdapterFactory factory = new SuspendTriggerAdapterFactory(); 530 manager.registerAdapters(factory, ILaunch.class); 531 532 getStandardDisplay().asyncExec( 533 new Runnable () { 534 public void run() { 535 SelectedResourceManager.getDefault(); 537 getLaunchConfigurationManager().getLaunchShortcuts(); 539 } 540 }); 541 542 fServiceTracker = new ServiceTracker(context, PackageAdmin.class.getName(), null); 543 fServiceTracker.open(); 544 fPackageAdminService = (PackageAdmin) fServiceTracker.getService(); 545 546 getLaunchConfigurationManager().startup(); 547 } 548 549 552 public static void errorDialog(Shell shell, String title, String message, IStatus s) { 553 if (s != null && message.equals(s.getMessage())) { 556 message= null; 557 } 558 ErrorDialog.openError(shell, title, message, s); 559 } 560 561 564 public static void errorDialog(Shell shell, String title, String message, Throwable t) { 565 IStatus status; 566 if (t instanceof CoreException) { 567 status= ((CoreException)t).getStatus(); 568 if (status != null && message.equals(status.getMessage())) { 571 message= null; 572 } 573 } else { 574 status= new Status(IStatus.ERROR, getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR, "Error within Debug UI: ", t); log(status); 576 } 577 ErrorDialog.openError(shell, title, message, status); 578 } 579 580 585 public static void log(IStatus status) { 586 getDefault().getLog().log(status); 587 } 588 589 594 public static void log(Throwable t) { 595 log(newErrorStatus("Error logged from Debug UI: ", t)); } 597 598 603 public static void logErrorMessage(String message) { 604 log(newErrorStatus("Internal message logged from Debug UI: " + message, null)); } 608 609 615 public static IStatus newErrorStatus(String message, Throwable exception) { 616 return new Status(IStatus.ERROR, getUniqueIdentifier(), IDebugUIConstants.INTERNAL_ERROR, message, exception); 617 } 618 619 641 public static int openLaunchConfigurationEditDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier, IStatus status, boolean showCancel) { 642 LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier); 643 if (group != null) { 644 LaunchConfigurationEditDialog dialog = new LaunchConfigurationEditDialog(shell, configuration, group, showCancel); 645 dialog.setInitialStatus(status); 646 return dialog.open(); 647 } 648 return Window.CANCEL; 649 } 650 651 675 public static int openLaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration configuration, String groupIdentifier, Set reservednames, IStatus status, boolean setDefaults) { 676 LaunchGroupExtension group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupIdentifier); 677 if (group != null) { 678 LaunchConfigurationPropertiesDialog dialog = new LaunchConfigurationPropertiesDialog(shell, configuration, group, reservednames); 679 dialog.setInitialStatus(status); 680 dialog.setDefaultsOnOpen(setDefaults); 681 return dialog.open(); 682 } 683 return Window.CANCEL; 684 } 685 686 694 protected static boolean saveAllEditors(boolean confirm) { 695 if (getActiveWorkbenchWindow() == null) { 696 return false; 697 } 698 return PlatformUI.getWorkbench().saveAllEditors(confirm); 699 } 700 701 708 public static boolean saveAndBuild() { 709 boolean status = true; 710 String saveDirty = getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH); 711 boolean buildBeforeLaunch = getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH); 712 713 if (saveDirty.equals(MessageDialogWithToggle.NEVER)) { 715 if (buildBeforeLaunch) { 716 return doBuild(); 717 } 718 } else { 719 status = saveAllEditors(saveDirty.equals(MessageDialogWithToggle.PROMPT)); 720 if (status && buildBeforeLaunch) { 721 status = doBuild(); 722 } 723 } 724 725 return status; 726 } 727 728 private static boolean doBuild() { 729 try { 730 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new IRunnableWithProgress() { 731 public void run(IProgressMonitor monitor) throws InvocationTargetException { 732 try { 733 ResourcesPlugin.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); 734 } catch (CoreException e) { 735 throw new InvocationTargetException (e); 736 } 737 } 738 }); 739 } catch (InterruptedException e) { 740 return false; 742 } catch (InvocationTargetException e) { 743 String title= DebugUIMessages.DebugUIPlugin_Run_Debug_1; 744 String message= DebugUIMessages.DebugUIPlugin_Build_error__Check_log_for_details__2; 745 Throwable t = e.getTargetException(); 746 errorDialog(getShell(), title, message, t); 747 return false; 748 } 749 return true; 750 } 751 752 758 public static Display getStandardDisplay() { 759 Display display= Display.getCurrent(); 760 if (display == null) { 761 display= Display.getDefault(); 762 } 763 return display; 764 } 765 766 774 public static Color getPreferenceColor(String type) { 775 return ColorManager.getDefault().getColor(PreferenceConverter.getColor(getDefault().getPreferenceStore(), type)); 776 } 777 778 784 public ProcessConsoleManager getProcessConsoleManager() { 785 if (fProcessConsoleManager == null) { 786 fProcessConsoleManager = new ProcessConsoleManager(); 787 } 788 return fProcessConsoleManager; 789 } 790 791 800 public static String serializeDocument(Document doc) throws TransformerException , IOException { 801 ByteArrayOutputStream s= new ByteArrayOutputStream (); 802 803 TransformerFactory factory= TransformerFactory.newInstance(); 804 805 Transformer transformer= factory.newTransformer(); 806 transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); 809 DOMSource source= new DOMSource (doc); 810 StreamResult outputTarget= new StreamResult (s); 811 transformer.transform(source, outputTarget); 812 813 return s.toString("UTF8"); } 815 816 822 public static Document getDocument() throws ParserConfigurationException { 823 DocumentBuilderFactory dfactory= DocumentBuilderFactory.newInstance(); 824 825 DocumentBuilder docBuilder= dfactory.newDocumentBuilder(); 826 Document doc= docBuilder.newDocument(); 827 return doc; 828 } 829 830 842 public void launchAdded(ILaunch launch) { 843 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); 844 getProcessConsoleManager().startup(); 845 SourceLookupManager.getDefault(); 846 } 847 848 853 public PerspectiveManager getPerspectiveManager() { 854 return fPerspectiveManager; 855 } 856 857 860 public void launchChanged(ILaunch launch) {} 861 862 865 public void launchRemoved(ILaunch launch) {} 866 867 874 public static boolean preLaunchSave() { 875 String saveDirty = getDefault().getPreferenceStore().getString(IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH); 876 if (saveDirty.equals(MessageDialogWithToggle.NEVER)) { 877 return true; 878 } 879 return saveAllEditors(saveDirty.equals(MessageDialogWithToggle.PROMPT)); 880 } 881 882 893 public static ILaunch buildAndLaunch(ILaunchConfiguration configuration, String mode, IProgressMonitor monitor) throws CoreException { 894 boolean buildBeforeLaunch = getDefault().getPreferenceStore().getBoolean(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH); 895 896 monitor.beginTask("", 1); try 898 { 899 return configuration.launch( 900 mode, 901 new SubProgressMonitor(monitor, 1), 902 buildBeforeLaunch); 903 } 904 finally 905 { 906 monitor.done(); 907 } 908 } 909 910 920 public static void launchInForeground(final ILaunchConfiguration configuration, final String mode) { 921 final IJobManager jobManager = Job.getJobManager(); 922 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 923 boolean wait = false; 924 925 if (jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD).length > 0 || jobManager.find(ResourcesPlugin.FAMILY_MANUAL_BUILD).length >0) { 926 String waitForBuild = store.getString(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); 927 928 if (waitForBuild.equals(MessageDialogWithToggle.PROMPT)) { 929 MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(), DebugUIMessages.DebugUIPlugin_23, DebugUIMessages.DebugUIPlugin_24, null, false, store, IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); 931 switch (dialog.getReturnCode()) { 932 case IDialogConstants.CANCEL_ID: 933 return; 934 case IDialogConstants.YES_ID: 935 wait = false; 936 break; 937 case IDialogConstants.NO_ID: 938 wait = true; 939 break; 940 } 941 } else if (waitForBuild.equals(MessageDialogWithToggle.ALWAYS)) { 942 wait = true; 943 } 944 } 945 946 if (wait) { 947 IWorkbench workbench = DebugUIPlugin.getDefault().getWorkbench(); 948 IProgressService progressService = workbench.getProgressService(); 949 final IRunnableWithProgress runnable = new IRunnableWithProgress() { 950 public void run(IProgressMonitor monitor) throws InvocationTargetException { 951 954 monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object [] {configuration.getName()}), 100); 955 956 try { 957 jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, new SubProgressMonitor(monitor, 1)); 958 jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1)); 959 } 960 catch (InterruptedException e) {} 961 if (!monitor.isCanceled()) { 962 try { 963 buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98)); 964 } 965 catch (CoreException e) { 966 throw new InvocationTargetException (e); 967 } 968 } 969 } 970 }; 971 try { 972 progressService.busyCursorWhile(runnable); 973 } 974 catch (InterruptedException e) {} 975 catch (InvocationTargetException e2) { 976 handleInvocationTargetException(e2, configuration, mode); 977 } 978 } else { 979 IRunnableWithProgress runnable = new IRunnableWithProgress() { 980 public void run(IProgressMonitor monitor) throws InvocationTargetException { 981 983 monitor.beginTask(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object [] {configuration.getName()}), 1); 984 try { 985 buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 1)); 986 } 987 catch (CoreException e) { 988 throw new InvocationTargetException (e); 989 } 990 } 991 }; 992 try { 993 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable); 994 } 995 catch (InvocationTargetException e) { 996 handleInvocationTargetException(e, configuration, mode); 997 } 998 catch (InterruptedException e) {} 999 1000 } 1001 } 1002 1003 private static void handleInvocationTargetException(InvocationTargetException e, ILaunchConfiguration configuration, String mode) { 1004 Throwable targetException = e.getTargetException(); 1005 Throwable t = e; 1006 if (targetException instanceof CoreException) { 1007 t = targetException; 1008 } 1009 if (t instanceof CoreException) { 1010 CoreException ce = (CoreException)t; 1011 IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(ce.getStatus()); 1012 if (handler != null) { 1013 ILaunchGroup group = DebugUITools.getLaunchGroup(configuration, mode); 1014 if (group != null) { 1015 DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(configuration), group.getIdentifier(), ce.getStatus()); 1016 return; 1017 } 1018 } 1019 if ((ce.getStatus().getSeverity() & (IStatus.ERROR | IStatus.WARNING)) == 0) { 1020 return; 1023 } 1024 } 1025 DebugUIPlugin.errorDialog(DebugUIPlugin.getShell(), DebugUIMessages.DebugUITools_Error_1, DebugUIMessages.DebugUITools_Exception_occurred_during_launch_2, t); } 1027 1028 1038 public static void launchInBackground(final ILaunchConfiguration configuration, final String mode) { 1039 final IJobManager jobManager = Job.getJobManager(); 1040 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 1041 boolean wait = (jobManager.find(ResourcesPlugin.FAMILY_AUTO_BUILD).length > 0) || (jobManager.find(ResourcesPlugin.FAMILY_MANUAL_BUILD).length > 0); 1042 String waitPref = store.getString(IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); 1043 if (wait) { if (waitPref.equals(MessageDialogWithToggle.PROMPT)) { 1045 MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(getShell(), DebugUIMessages.DebugUIPlugin_23, DebugUIMessages.DebugUIPlugin_24, null, false, store, IInternalDebugUIConstants.PREF_WAIT_FOR_BUILD); switch (dialog.getReturnCode()) { 1047 case IDialogConstants.CANCEL_ID: 1048 return; 1049 case IDialogConstants.YES_ID: 1050 wait = true; 1051 break; 1052 case IDialogConstants.NO_ID: 1053 wait = false; 1054 break; 1055 } 1056 } 1057 else { 1058 wait = waitPref.equals(MessageDialogWithToggle.ALWAYS); 1059 } 1060 } 1061 final boolean waitInJob = wait; 1062 Job job = new Job(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object [] {configuration.getName()})) { 1063 public IStatus run(final IProgressMonitor monitor) { 1064 1067 monitor.beginTask(DebugUIMessages.DebugUITools_3, 100); 1068 try { 1069 if(waitInJob) { 1070 StringBuffer buffer = new StringBuffer (configuration.getName()); 1071 buffer.append(DebugUIMessages.DebugUIPlugin_0); 1072 ILaunchConfigurationWorkingCopy workingCopy = configuration.copy(buffer.toString()); 1073 workingCopy.setAttribute(ATTR_LAUNCHING_CONFIG_HANDLE, configuration.getMemento()); 1074 final ILaunch pendingLaunch = new PendingLaunch(workingCopy, mode, this); 1075 DebugPlugin.getDefault().getLaunchManager().addLaunch(pendingLaunch); 1076 IJobChangeListener listener= new IJobChangeListener() { 1077 public void sleeping(IJobChangeEvent event) {} 1078 public void scheduled(IJobChangeEvent event) {} 1079 public void running(IJobChangeEvent event) {} 1080 public void awake(IJobChangeEvent event) {} 1081 public void aboutToRun(IJobChangeEvent event) {} 1082 public void done(IJobChangeEvent event) { 1083 DebugPlugin dp = DebugPlugin.getDefault(); 1084 if (dp != null) { 1085 dp.getLaunchManager().removeLaunch(pendingLaunch); 1086 } 1087 removeJobChangeListener(this); 1088 } 1089 }; 1090 addJobChangeListener(listener); 1091 try { 1092 jobManager.join(ResourcesPlugin.FAMILY_MANUAL_BUILD, new SubProgressMonitor(monitor, 1)); 1093 jobManager.join(ResourcesPlugin.FAMILY_AUTO_BUILD, new SubProgressMonitor(monitor, 1)); 1094 } 1095 catch (InterruptedException e) {} 1096 DebugPlugin.getDefault().getLaunchManager().removeLaunch(pendingLaunch); 1097 } 1098 else { 1099 monitor.worked(2); 1100 } 1101 if (!monitor.isCanceled()) { 1102 buildAndLaunch(configuration, mode, new SubProgressMonitor(monitor, 98)); 1103 } 1104 } catch (CoreException e) { 1105 final IStatus status = e.getStatus(); 1106 IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status); 1107 if (handler == null) { 1108 return status; 1109 } 1110 final ILaunchGroup group = DebugUITools.getLaunchGroup(configuration, mode); 1111 if (group == null) { 1112 return status; 1113 } 1114 Runnable r = new Runnable () { 1115 public void run() { 1116 DebugUITools.openLaunchConfigurationDialogOnGroup(DebugUIPlugin.getShell(), new StructuredSelection(configuration), group.getIdentifier(), status); 1117 } 1118 }; 1119 DebugUIPlugin.getStandardDisplay().asyncExec(r); 1120 } 1121 finally { 1122 monitor.done(); 1123 } 1124 1125 return Status.OK_STATUS; 1126 } 1127 }; 1128 1129 IWorkbench workbench = DebugUIPlugin.getDefault().getWorkbench(); 1130 IProgressService progressService = workbench.getProgressService(); 1131 1132 job.setPriority(Job.INTERACTIVE); 1133 job.setName(MessageFormat.format(DebugUIMessages.DebugUIPlugin_25, new Object [] {configuration.getName()})); 1134 1135 if (wait) { 1136 progressService.showInDialog(workbench.getActiveWorkbenchWindow().getShell(), job); 1137 } 1138 job.schedule(); 1139 } 1140 1141 1146 public static String removeAccelerators(String label) { 1147 String title = label; 1148 if (title != null) { 1149 int index = title.indexOf('&'); 1151 if (index == 0) { 1152 title = title.substring(1); 1153 } else if (index > 0) { 1154 if (title.charAt(index - 1) == '(' && title.length() >= index + 3 && title.charAt(index + 2) == ')') { 1156 String first = title.substring(0, index - 1); 1157 String last = title.substring(index + 3); 1158 title = first + last; 1159 } else if (index < (title.length() - 1)) { 1160 String first = title.substring(0, index); 1161 String last = title.substring(index + 1); 1162 title = first + last; 1163 } 1164 } 1165 } 1166 return title; 1167 } 1168 1169 1175 public static String adjustDBCSAccelerator(String label) { 1176 String title = label; 1177 if (title != null) { 1178 int index = title.indexOf('&'); 1180 if (index > 0) { 1181 if (title.charAt(index - 1) == '(' && title.length() >= index + 3 && title.charAt(index + 2) == ')') { 1183 String first = title.substring(0, index - 1); 1184 String accel = title.substring(index - 1, index + 3); 1185 String last = title.substring(index + 3); 1186 title = first + last; 1187 if (title.endsWith("...")) { title = title.substring(0, title.length() - 3); 1189 title = title + accel + "..."; } else { 1191 title = title + accel; 1192 } 1193 } 1194 } 1195 } 1196 return title; 1197 } 1198 1199 1204 public static ImageDescriptorRegistry getImageDescriptorRegistry() { 1205 if (getDefault().fImageDescriptorRegistry == null) { 1206 getDefault().fImageDescriptorRegistry = new ImageDescriptorRegistry(); 1207 } 1208 return getDefault().fImageDescriptorRegistry; 1209 } 1210 1211 1219 public static ImageDescriptor getImageDescriptor(IConfigurationElement element, String attr) { 1220 Bundle bundle = Platform.getBundle(element.getContributor().getName()); 1221 String iconPath = element.getAttribute(attr); 1222 if (iconPath != null) { 1223 URL iconURL = FileLocator.find(bundle , new Path(iconPath), null); 1224 if (iconURL != null) { 1225 return ImageDescriptor.createFromURL(iconURL); 1226 } 1227 } 1228 return null; 1229 } 1230 1231 1240 public static ImageDescriptor getImageDescriptor(String name, String path) { 1241 Bundle bundle = Platform.getBundle(name); 1242 if (path != null) { 1243 URL iconURL = FileLocator.find(bundle , new Path(path), null); 1244 if (iconURL != null) { 1245 return ImageDescriptor.createFromURL(iconURL); 1246 } 1247 } 1248 return null; 1249 } 1250 1251 1258 public static boolean doLaunchConfigurationFiltering(ILaunchConfiguration config) { 1259 boolean ret = true; 1260 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED)) { 1261 ret &= new ClosedProjectFilter().select(null, null, config); 1262 } 1263 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED)) { 1264 ret &= new DeletedProjectFilter().select(null, null, config); 1265 } 1266 if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) { 1267 try { 1268 ret &= new LaunchConfigurationTypeFilter().select(null, null, config.getType()); 1269 } 1270 catch(CoreException e) { 1271 DebugUIPlugin.log(e); 1272 } 1273 } 1274 return ret; 1275 } 1276} 1277 1278 | Popular Tags |