1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 14 import com.ibm.icu.text.MessageFormat; 15 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.debug.core.DebugException; 19 import org.eclipse.debug.core.ILaunch; 20 import org.eclipse.debug.ui.DebugUITools; 21 import org.eclipse.jdt.debug.core.IJavaDebugTarget; 22 import org.eclipse.jdt.debug.core.IJavaHotCodeReplaceListener; 23 import org.eclipse.jdt.internal.debug.ui.snippeteditor.ScrapbookLauncher; 24 import org.eclipse.jface.viewers.ILabelProvider; 25 import org.eclipse.swt.widgets.Display; 26 import org.eclipse.swt.widgets.Shell; 27 28 public class JavaHotCodeReplaceListener implements IJavaHotCodeReplaceListener { 29 30 private ILabelProvider fLabelProvider= DebugUITools.newDebugModelPresentation(); 31 32 35 public void hotCodeReplaceSucceeded(IJavaDebugTarget target) { 36 } 37 38 41 public void hotCodeReplaceFailed(final IJavaDebugTarget target, final DebugException exception) { 42 if ((exception != null &&!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED)) || 43 ((exception == null) && !JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED))) { 44 return; 45 } 46 ILaunch launch = target.getLaunch(); 50 if (launch.getAttribute(ScrapbookLauncher.SCRAPBOOK_LAUNCH) != null) { 51 if (!target.supportsHotCodeReplace()) { 52 return; 53 } 54 } 55 final Display display= JDIDebugUIPlugin.getStandardDisplay(); 56 if (display.isDisposed()) { 57 return; 58 } 59 60 String name = null; 61 try { 62 name = target.getName(); 63 } 64 catch(DebugException e) { 65 name = fLabelProvider.getText(target); 66 } 67 final String vmName = name; 68 final IStatus status; 69 final String preference; 70 final String alertMessage; 71 final String launchName = target.getLaunch().getLaunchConfiguration().getName(); 72 if (exception == null) { 73 status = new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_The_target_VM_does_not_support_hot_code_replace_1, null); 74 preference= IJDIPreferencesConstants.PREF_ALERT_HCR_NOT_SUPPORTED; 75 alertMessage= DebugUIMessages.JDIDebugUIPlugin_3; 76 } else { 77 status = new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, exception.getMessage(), exception.getCause()); 78 preference= IJDIPreferencesConstants.PREF_ALERT_HCR_FAILED; 79 alertMessage= DebugUIMessages.JDIDebugUIPlugin_1; 80 } 81 final String title = DebugUIMessages.JDIDebugUIPlugin_Hot_code_replace_failed_1; 82 final String message = MessageFormat.format(DebugUIMessages.JDIDebugUIPlugin__0__was_unable_to_replace_the_running_code_with_the_code_in_the_workspace__2, new Object [] {vmName, launchName}); 83 display.asyncExec(new Runnable () { 84 public void run() { 85 if (display.isDisposed()) { 86 return; 87 } 88 Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell(); 89 HotCodeReplaceErrorDialog dialog= new HotCodeReplaceErrorDialog(shell, title, message, status, preference, alertMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target); 90 dialog.setBlockOnOpen(false); 91 dialog.open(); 92 } 93 }); 94 } 95 96 99 public void obsoleteMethods(final IJavaDebugTarget target) { 100 if (!JDIDebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS)) { 101 return; 102 } 103 final Display display= JDIDebugUIPlugin.getStandardDisplay(); 104 if (display.isDisposed()) { 105 return; 106 } 107 final String vmName= fLabelProvider.getText(target); 108 final String dialogTitle= DebugUIMessages.JDIDebugUIPlugin_Obsolete_methods_remain_1; 109 final String message= MessageFormat.format(DebugUIMessages.JDIDebugUIPlugin__0__contains_obsolete_methods_1, new Object [] {vmName}); 110 final IStatus status= new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_Stepping_may_be_hazardous_1, null); 111 final String toggleMessage= DebugUIMessages.JDIDebugUIPlugin_2; 112 display.asyncExec(new Runnable () { 113 public void run() { 114 if (display.isDisposed()) { 115 return; 116 } 117 Shell shell= JDIDebugUIPlugin.getActiveWorkbenchShell(); 118 HotCodeReplaceErrorDialog dialog= new HotCodeReplaceErrorDialog(shell, dialogTitle, message, status, IJDIPreferencesConstants.PREF_ALERT_OBSOLETE_METHODS, 119 toggleMessage, JDIDebugUIPlugin.getDefault().getPreferenceStore(), target); 120 dialog.setBlockOnOpen(false); 121 dialog.open(); 122 } 123 }); 124 } 125 126 } 127 | Popular Tags |