blob: f8f805ee0ada9f4afc6bf2fbba2e82670a7d2891 [file] [log] [blame]
package org.eclipse.debug.internal.ui;
/*
* Licensed Materials - Property of IBM,
* WebSphere Studio Workbench
* (c) Copyright IBM Corp 2000
*/
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.core.model.IProcess;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.texteditor.IUpdate;
/**
* Removes all terminated/detached launches from the UI.
* Clears the launches output as well.
*/
public class RemoveTerminatedAction extends Action implements IUpdate {
private static final String PREFIX= "remove_all_terminated_action.";
boolean fRemoveDebug;
public RemoveTerminatedAction(boolean removeDebug) {
super(DebugUIUtils.getResourceString(PREFIX + TEXT));
setToolTipText(DebugUIUtils.getResourceString(PREFIX + TOOL_TIP_TEXT));
fRemoveDebug= removeDebug;
setEnabled(false);
}
/**
* Removes all of the terminated launches relevant to the
* current perspective. Has the
* side effect of clearing the console output.
* @see IAction
*/
public void run() {
ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager();
Object[] launches= lManager.getLaunches();
for (int i= 0; i < launches.length; i++) {
ILaunch launch= (ILaunch)launches[i];
if (launch.isTerminated() && isLaunchRelevantToCurrentPerpective(launch)) {
lManager.deregisterLaunch(launch);
}
}
}
/**
* Updates the enabled state of this action to enabled if at
* least one launch is terminated and relative to the current perspective.
* @see IUpdate
*/
public void update() {
ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager();
ILaunch[] launches= lManager.getLaunches();
for (int i= 0; i < launches.length; i++) {
ILaunch launch= launches[i];
if (launch.isTerminated() && isLaunchRelevantToCurrentPerpective(launch)) {
setEnabled(true);
return;
}
}
setEnabled(false);
}
/**
* Returns whether this launch is relevant to the
* current perspective...ie Run or Debug.
* For example, if in the debug perspective (fRemoveDebug= true)
* and the launch does not have a debug target, <code>false</code>
* will be returned.
*/
protected boolean isLaunchRelevantToCurrentPerpective(ILaunch launch) {
if (fRemoveDebug) {
return launch.getDebugTarget() != null;
}
IProcess[] processes= launch.getProcesses();
return (processes != null && processes.length > 0);
}
}