KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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 import com.ibm.icu.text.MessageFormat;
14
15 import org.eclipse.core.runtime.IStatus;
16 import org.eclipse.debug.core.DebugException;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.ILaunchConfiguration;
19 import org.eclipse.debug.core.model.IDebugTarget;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.swt.custom.BusyIndicator;
24 import org.eclipse.swt.widgets.Composite;
25 import org.eclipse.swt.widgets.Shell;
26
27 /**
28  * An error dialog reporting a problem with a debug
29  * target which gives the user the option to continue
30  * or terminate/disconnect or restart the target.
31  */

32 public class HotCodeReplaceErrorDialog extends ErrorDialogWithToggle {
33
34     protected IDebugTarget target;
35     // The IDs of the buttons. Set to the sum of the other possible IDs generated by
36
// this dialog to ensure the IDs' uniqueness.
37
protected int TERMINATE_ID= IDialogConstants.OK_ID + IDialogConstants.DETAILS_ID + IDialogConstants.CANCEL_ID;
38     protected int DISCONNECT_ID= TERMINATE_ID + 1;
39     protected int RESTART_ID= TERMINATE_ID + 2;
40
41     /**
42      * Creates a new dialog which can terminate, disconnect or restart the given debug target.
43      *
44      * @param target the debug target
45      * @see ErrorDialogWithToggle#ErrorDialogWithToggle(Shell, String, String, IStatus, String, String, IPreferenceStore)
46      */

47     public HotCodeReplaceErrorDialog(Shell parentShell, String JavaDoc dialogTitle, String JavaDoc message, IStatus status, String JavaDoc preferenceKey, String JavaDoc toggleMessage, IPreferenceStore store, IDebugTarget target) {
48         super(parentShell, dialogTitle, message, status, preferenceKey, toggleMessage, store);
49         this.target = target;
50     }
51
52     /* (non-Javadoc)
53      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
54      */

55     protected void createButtonsForButtonBar(Composite parent) {
56         super.createButtonsForButtonBar(parent);
57         getButton(IDialogConstants.OK_ID).setText(DebugUIMessages.HotCodeReplaceErrorDialog_0);
58         boolean canTerminate= target.canTerminate();
59         boolean canDisconnect= target.canDisconnect();
60         if (canTerminate) {
61             createButton(parent, TERMINATE_ID, DebugUIMessages.HotCodeReplaceErrorDialog_1, false);
62         }
63         if (canDisconnect) {
64             createButton(parent, DISCONNECT_ID, DebugUIMessages.HotCodeReplaceErrorDialog_3, false);
65         }
66         if (canTerminate && !canDisconnect) {
67             createButton(parent, RESTART_ID, DebugUIMessages.HotCodeReplaceErrorDialog_7, false);
68         }
69     }
70
71     /* (non-Javadoc)
72      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
73      */

74     protected void buttonPressed(final int id) {
75         if (id == TERMINATE_ID || id == DISCONNECT_ID || id == RESTART_ID) {
76             final DebugException[] ex = new DebugException[1];
77             final String JavaDoc[] operation = new String JavaDoc[1];
78             ex[0] = null;
79             Runnable JavaDoc r = new Runnable JavaDoc() {
80                 public void run() {
81                     try {
82                         if (id == TERMINATE_ID) {
83                             operation[0]= DebugUIMessages.HotCodeReplaceErrorDialog_5;
84                             target.terminate();
85                         } else if (id == DISCONNECT_ID){
86                             operation[0]= DebugUIMessages.HotCodeReplaceErrorDialog_6;
87                             target.disconnect();
88                         } else {
89                             operation[0]= DebugUIMessages.HotCodeReplaceErrorDialog_8;
90                             ILaunch launch = target.getLaunch();
91                             launch.terminate();
92                             ILaunchConfiguration config = launch.getLaunchConfiguration();
93                             if (config != null && config.exists()) {
94                                 DebugUITools.launch(config, launch.getLaunchMode());
95                             }
96                         }
97                     } catch (DebugException e) {
98                         ex[0] = e;
99                     }
100                 }
101             };
102             BusyIndicator.showWhile(getShell().getDisplay(), r);
103             if (ex[0] != null) {
104                 JDIDebugUIPlugin.statusDialog(MessageFormat.format(DebugUIMessages.HotCodeReplaceErrorDialog_2, operation), ex[0].getStatus());
105             }
106             okPressed();
107         } else {
108             super.buttonPressed(id);
109         }
110     }
111 }
112
Popular Tags