KickJava   Java API By Example, From Geeks To Geeks.

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


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.DebugEvent;
15 import org.eclipse.debug.core.DebugException;
16 import org.eclipse.debug.core.DebugPlugin;
17 import org.eclipse.debug.core.ILaunch;
18 import org.eclipse.debug.core.ILaunchManager;
19 import org.eclipse.jface.action.IAction;
20 import org.eclipse.jface.viewers.ISelection;
21 import org.eclipse.jface.viewers.IStructuredSelection;
22 import org.eclipse.jface.viewers.StructuredSelection;
23
24 /**
25  * Terminates all launches.
26  */

27 public class TerminateAllAction extends AbstractListenerActionDelegate {
28     
29     /* (non-Javadoc)
30      * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#doAction(java.lang.Object)
31      */

32     protected void doAction(Object JavaDoc element) throws DebugException {
33         if (element instanceof ILaunch) {
34             ILaunch launch = (ILaunch) element;
35             if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) {
36                 launch.terminate();
37             }
38         }
39     }
40     
41     /* (non-Javadoc)
42      * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#isRunInBackground()
43      */

44     protected boolean isRunInBackground() {
45         return true;
46     }
47     
48     /**
49      * Update the action enablement based on the launches present in
50      * the launch manager. selection is unused and can be <code>null</code>.
51      * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
52      */

53     protected void update(IAction action, ISelection selection) {
54         ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager();
55         ILaunch[] launches= lManager.getLaunches();
56         for (int i= 0; i< launches.length; i++) {
57             ILaunch launch= launches[i];
58             if (!launch.isTerminated()) {
59                 action.setEnabled(true);
60                 return;
61             }
62         }
63         action.setEnabled(false);
64     }
65
66     /* (non-Javadoc)
67      * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
68      */

69     public void selectionChanged(IAction action, ISelection selection) {
70         setAction(action);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.debug.internal.ui.actions.AbstractListenerActionDelegate#doHandleDebugEvent(org.eclipse.debug.core.DebugEvent)
75      */

76     protected void doHandleDebugEvent(DebugEvent event) {
77         switch (event.getKind()) {
78             case DebugEvent.TERMINATE :
79                 update(getAction(), null);
80                 break;
81             case DebugEvent.CREATE :
82                 update(getAction(), null);
83                 break;
84         }
85     }
86
87     /* (non-Javadoc)
88      * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#getSelection()
89      */

90     protected IStructuredSelection getSelection() {
91         return new StructuredSelection(DebugPlugin.getDefault().getLaunchManager().getLaunches());
92     }
93     
94     
95 }
96
Popular Tags