KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions;
12
13 import org.eclipse.debug.core.DebugException;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.model.ITerminate;
16 import org.eclipse.debug.internal.ui.DebugUIPlugin;
17
18 /**
19  * Action which terminates a launch and then relaunches it.
20  * This is equivalent to the Terminate action followed by
21  * Relaunch, but is provided to the user as a convenience.
22  */

23 public class TerminateAndRelaunchAction extends AbstractListenerActionDelegate {
24
25     protected void doAction(Object JavaDoc element) throws DebugException {
26         final ILaunch launch= RelaunchActionDelegate.getLaunch(element);
27         if (launch == null || !(element instanceof ITerminate)) {
28             // Shouldn't happen because of enablement check.
29
return;
30         }
31         
32         ((ITerminate)element).terminate();
33         DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
34             public void run() {
35                 // Must be run in the UI thread since the launch can require prompting to proceed
36
RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
37             }
38         });
39     }
40     
41     /**
42      * @see AbstractDebugActionDelegate#isRunInBackground()
43      */

44     protected boolean isRunInBackground() {
45         return true;
46     }
47
48     /**
49      * @see AbstractDebugActionDelegate#isEnabledFor(Object)
50      */

51     protected boolean isEnabledFor(Object JavaDoc element) {
52         return element instanceof ITerminate && ((ITerminate)element).canTerminate() &&
53             RelaunchActionDelegate.getLaunch(element) != null;
54     }
55 }
56
Popular Tags