KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > console > ConsoleRemoveAllTerminatedAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.views.console;
12
13 import org.eclipse.debug.core.DebugPlugin;
14 import org.eclipse.debug.core.ILaunch;
15 import org.eclipse.debug.core.ILaunchesListener2;
16 import org.eclipse.debug.internal.ui.DebugPluginImages;
17 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.actions.RemoveAllTerminatedAction;
20 import org.eclipse.debug.ui.IDebugUIConstants;
21 import org.eclipse.jface.action.Action;
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.texteditor.IUpdate;
24
25 /**
26  * ConsoleRemoveAllTerminatedAction
27  */

28 public class ConsoleRemoveAllTerminatedAction extends Action implements IUpdate, ILaunchesListener2 {
29
30     public void dispose() {
31         DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
32     }
33     
34     /* (non-Javadoc)
35      * @see org.eclipse.ui.texteditor.IUpdate#update()
36      */

37     public void update() {
38         ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
39         for (int i = 0; i < launches.length; i++) {
40             ILaunch launch = launches[i];
41             if (launch.isTerminated()) {
42                 setEnabled(true);
43                 return;
44             }
45         }
46         setEnabled(false);
47
48     }
49
50     /* (non-Javadoc)
51      * @see org.eclipse.jface.action.IAction#run()
52      */

53     public void run() {
54         ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
55         RemoveAllTerminatedAction.removeTerminatedLaunches(launches);
56     }
57     
58     public ConsoleRemoveAllTerminatedAction() {
59         super(ConsoleMessages.ConsoleRemoveAllTerminatedAction_0);
60         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONSOLE_REMOVE_ALL_TERMINATED);
61         setToolTipText(ConsoleMessages.ConsoleRemoveAllTerminatedAction_1);
62         setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE_ALL));
63         setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_REMOVE_ALL));
64         setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE_ALL));
65         DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
66         update();
67     }
68
69     /* (non-Javadoc)
70      * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[])
71      */

72     public void launchesRemoved(ILaunch[] launches) {
73        if (isEnabled()) {
74            update();
75        }
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[])
80      */

81     public void launchesAdded(ILaunch[] launches) {
82     }
83
84     /* (non-Javadoc)
85      * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[])
86      */

87     public void launchesChanged(ILaunch[] launches) {
88     }
89
90     /* (non-Javadoc)
91      * @see org.eclipse.debug.core.ILaunchesListener2#launchesTerminated(org.eclipse.debug.core.ILaunch[])
92      */

93     public void launchesTerminated(ILaunch[] launches) {
94         update();
95     }
96 }
97
Popular Tags