KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > RelaunchActionDelegate


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.actions;
12
13
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.ILaunchConfiguration;
16 import org.eclipse.debug.core.model.IDebugElement;
17 import org.eclipse.debug.core.model.IProcess;
18 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
19 import org.eclipse.debug.ui.DebugUITools;
20
21 public class RelaunchActionDelegate extends AbstractDebugActionDelegate {
22     
23     /**
24      * @see AbstractDebugActionDelegate#doAction(Object)
25      */

26     protected void doAction(Object JavaDoc object) {
27         ILaunch launch= getLaunch(object);
28         if (launch != null) {
29             relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
30         }
31     }
32     
33     public static ILaunch getLaunch(Object JavaDoc element) {
34         ILaunch launch= null;
35         if (element instanceof IDebugElement) {
36             launch= ((IDebugElement)element).getLaunch();
37         } else if (element instanceof ILaunch) {
38             launch= ((ILaunch)element);
39         } else if (element instanceof IProcess) {
40             launch= ((IProcess)element).getLaunch();
41         }
42         return launch;
43     }
44     
45     /**
46      * Re-launches the given configuration in the specified mode.
47      */

48     public static void relaunch(ILaunchConfiguration config, String JavaDoc mode) {
49         DebugUITools.launch(config, mode);
50     }
51     
52     /**
53      * @see AbstractDebugActionDelegate#isEnabledFor(Object)
54      */

55     protected boolean isEnabledFor(Object JavaDoc element) {
56         ILaunch launch= null;
57         if (element instanceof ILaunch) {
58             launch= (ILaunch)element;
59         } else if (element instanceof IDebugElement) {
60             launch= ((IDebugElement)element).getLaunch();
61         } else if (element instanceof IProcess) {
62             launch= ((IProcess)element).getLaunch();
63         }
64         
65         return launch != null && launch.getLaunchConfiguration() != null && LaunchConfigurationManager.isVisible(launch.getLaunchConfiguration());
66     }
67             
68     /**
69      * @see AbstractDebugActionDelegate#getErrorDialogMessage()
70      */

71     protected String JavaDoc getErrorDialogMessage() {
72         return ActionMessages.RelaunchActionDelegate_Launch_Failed_1;
73     }
74     
75     /**
76      * @see AbstractDebugActionDelegate#getStatusMessage()
77      */

78     protected String JavaDoc getStatusMessage() {
79         return ActionMessages.RelaunchActionDelegate_An_exception_occurred_while_launching_2;
80     }
81 }
82
Popular Tags