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.views.console; 12 13 import org.eclipse.debug.internal.ui.actions.TerminateActionDelegate; 14 import org.eclipse.jface.viewers.ISelectionChangedListener; 15 import org.eclipse.jface.viewers.IStructuredSelection; 16 import org.eclipse.jface.viewers.StructuredSelection; 17 import org.eclipse.ui.IViewPart; 18 import org.eclipse.ui.console.IConsole; 19 import org.eclipse.ui.console.IConsoleView; 20 21 /** 22 * Terminate action delegate for the console. The selection must be computed 23 * by getting the process from the associated process console, rather than 24 * the selection in the view (which is text viewer/text selection). 25 * 26 * @since 3.1 27 */ 28 public class ConsoleTerminateActionDelegate extends TerminateActionDelegate { 29 30 private IConsoleView fConsoleView; 31 32 /* (non-Javadoc) 33 * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#getSelection() 34 */ 35 protected IStructuredSelection getSelection() { 36 IConsole console = fConsoleView.getConsole(); 37 if (console instanceof ProcessConsole) { 38 return new StructuredSelection(((ProcessConsole)console).getProcess()); 39 } 40 return StructuredSelection.EMPTY; 41 } 42 43 44 /* (non-Javadoc) 45 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart) 46 */ 47 public void init(IViewPart view) { 48 fConsoleView = (IConsoleView) view; 49 super.init(view); 50 } 51 52 public synchronized void dispose() { 53 super.dispose(); 54 IViewPart view = getView(); 55 if (view != null) { 56 view.getSite().getSelectionProvider().removeSelectionChangedListener((ISelectionChangedListener) getAction()); 57 } 58 } 59 60 61 } 62