KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > DebugModePromptStatusHandler


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.debug.internal.ui.launchConfigurations;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.ILaunchManager;
17 import org.eclipse.debug.core.IStatusHandler;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.jface.dialogs.IDialogConstants;
22 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
23 import org.eclipse.jface.preference.IPreferenceStore;
24 import org.eclipse.swt.widgets.Shell;
25
26
27 public class DebugModePromptStatusHandler implements IStatusHandler {
28     
29     /* (non-Javadoc)
30      * @see org.eclipse.debug.core.IStatusHandler#handleStatus(org.eclipse.core.runtime.IStatus, java.lang.Object)
31      */

32     public Object JavaDoc handleStatus(IStatus status, Object JavaDoc source) throws CoreException {
33         if (source instanceof ILaunchConfiguration) {
34             ILaunchConfiguration config = (ILaunchConfiguration)source;
35             if (DebugUITools.isPrivate(config)) {
36                 return Boolean.FALSE;
37             }
38         }
39         
40         IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
41         ILaunchConfiguration configuration = (ILaunchConfiguration)source;
42         String JavaDoc pref = store.getString(IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE);
43         if (pref != null) {
44             if (pref.equals(MessageDialogWithToggle.NEVER)) {
45                 return Boolean.FALSE;
46             } else if (pref.equals(MessageDialogWithToggle.ALWAYS)) {
47                 relaunchInDebugMode(configuration);
48                 return Boolean.TRUE;
49             }
50         }
51         
52         Shell activeShell = DebugUIPlugin.getShell();
53         String JavaDoc title = LaunchConfigurationsMessages.DebugModePromptStatusHandler_0;
54         String JavaDoc message = LaunchConfigurationsMessages.DebugModePromptStatusHandler_1;
55         
56         MessageDialogWithToggle dialog = MessageDialogWithToggle.openYesNoCancelQuestion(activeShell, title, message, null, false, store, IInternalDebugUIConstants.PREF_RELAUNCH_IN_DEBUG_MODE);
57         int buttonId = dialog.getReturnCode();
58         if (buttonId == IDialogConstants.YES_ID) {
59             relaunchInDebugMode(configuration);
60             return Boolean.TRUE; // stops launch
61
} else if (buttonId == IDialogConstants.NO_ID) {
62             return Boolean.FALSE; // continue launch
63
} else { //CANCEL
64
return Boolean.TRUE; // stops the launch
65
}
66     }
67     /**
68      * @param configuration
69      */

70     private void relaunchInDebugMode(ILaunchConfiguration configuration) {
71         DebugUITools.launch(configuration, ILaunchManager.DEBUG_MODE);
72     }
73 }
74
Popular Tags