1 11 package org.eclipse.ui.console.actions; 12 13 14 import org.eclipse.jface.action.Action; 15 import org.eclipse.jface.text.IDocument; 16 import org.eclipse.jface.text.ITextViewer; 17 import org.eclipse.swt.custom.BusyIndicator; 18 import org.eclipse.ui.PlatformUI; 19 import org.eclipse.ui.console.ConsolePlugin; 20 import org.eclipse.ui.console.IConsoleConstants; 21 import org.eclipse.ui.console.TextConsole; 22 import org.eclipse.ui.internal.console.ConsoleMessages; 23 import org.eclipse.ui.internal.console.ConsolePluginImages; 24 import org.eclipse.ui.internal.console.IConsoleHelpContextIds; 25 import org.eclipse.ui.internal.console.IInternalConsoleConstants; 26 27 35 public class ClearOutputAction extends Action { 36 37 private ITextViewer fViewer; 38 private TextConsole fIOConsole; 39 40 45 private ClearOutputAction() { 46 super(ConsoleMessages.ClearOutputAction_title); 47 setToolTipText(ConsoleMessages.ClearOutputAction_toolTipText); 48 setHoverImageDescriptor(ConsolePluginImages.getImageDescriptor(IConsoleConstants.IMG_LCL_CLEAR)); 49 setDisabledImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_DLCL_CLEAR)); 50 setImageDescriptor(ConsolePluginImages.getImageDescriptor(IInternalConsoleConstants.IMG_ELCL_CLEAR)); 51 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IConsoleHelpContextIds.CLEAR_CONSOLE_ACTION); 52 } 53 54 62 public ClearOutputAction(TextConsole ioConsole) { 63 this(); 64 fIOConsole = ioConsole; 65 } 66 67 72 public ClearOutputAction(ITextViewer viewer) { 73 this(); 74 fViewer = viewer; 75 } 76 77 80 public void run() { 81 BusyIndicator.showWhile(ConsolePlugin.getStandardDisplay(), new Runnable () { 82 public void run() { 83 if (fIOConsole == null) { 84 IDocument document = fViewer.getDocument(); 85 if (document != null) { 86 document.set(""); } 88 fViewer.setSelectedRange(0, 0); 89 } else { 90 fIOConsole.clearConsole(); 91 } 92 } 93 }); 94 } 95 } 96 | Popular Tags |