KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > JavaHotCodeReplaceListener


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.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     /**
33      * @see IJavaHotCodeReplaceListener#hotCodeReplaceSucceeded(IJavaDebugTarget)
34      */

35     public void hotCodeReplaceSucceeded(IJavaDebugTarget target) {
36     }
37
38     /**
39      * @see IJavaHotCodeReplaceListener#hotCodeReplaceFailed(IJavaDebugTarget, DebugException)
40      */

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         // do not report errors for snippet editor targets
47
// that do not support HCR. HCR is simulated by using
48
// a new class loader for each evaluation
49
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 JavaDoc name = null;
61         try {
62             name = target.getName();
63         }
64         catch(DebugException e) {
65             name = fLabelProvider.getText(target);
66         }
67         final String JavaDoc vmName = name;
68         final IStatus status;
69         final String JavaDoc preference;
70         final String JavaDoc alertMessage;
71         final String JavaDoc 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 JavaDoc title = DebugUIMessages.JDIDebugUIPlugin_Hot_code_replace_failed_1;
82         final String JavaDoc message = MessageFormat.format(DebugUIMessages.JDIDebugUIPlugin__0__was_unable_to_replace_the_running_code_with_the_code_in_the_workspace__2, new Object JavaDoc[] {vmName, launchName});
83         display.asyncExec(new Runnable JavaDoc() {
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     /**
97      * @see IJavaHotCodeReplaceListener#obsoleteMethods(IJavaDebugTarget)
98      */

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 JavaDoc vmName= fLabelProvider.getText(target);
108         final String JavaDoc dialogTitle= DebugUIMessages.JDIDebugUIPlugin_Obsolete_methods_remain_1;
109         final String JavaDoc message= MessageFormat.format(DebugUIMessages.JDIDebugUIPlugin__0__contains_obsolete_methods_1, new Object JavaDoc[] {vmName});
110         final IStatus status= new Status(IStatus.WARNING, JDIDebugUIPlugin.getUniqueIdentifier(), IStatus.WARNING, DebugUIMessages.JDIDebugUIPlugin_Stepping_may_be_hazardous_1, null);
111         final String JavaDoc toggleMessage= DebugUIMessages.JDIDebugUIPlugin_2;
112         display.asyncExec(new Runnable JavaDoc() {
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