01: /*******************************************************************************
02: * Copyright (c) 2000, 2005 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.console.actions;
11:
12: import org.eclipse.jface.action.Action;
13: import org.eclipse.jface.text.IDocument;
14: import org.eclipse.jface.text.ITextViewer;
15: import org.eclipse.swt.custom.BusyIndicator;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.console.ConsolePlugin;
18: import org.eclipse.ui.console.IConsoleConstants;
19: import org.eclipse.ui.console.TextConsole;
20: import org.eclipse.ui.internal.console.ConsoleMessages;
21: import org.eclipse.ui.internal.console.ConsolePluginImages;
22: import org.eclipse.ui.internal.console.IConsoleHelpContextIds;
23: import org.eclipse.ui.internal.console.IInternalConsoleConstants;
24:
25: /**
26: * Clears the output in a text console.
27: * <p>
28: * Clients may instantiate this class; this class is not intended to
29: * be subclassed.
30: * </p>
31: * @since 3.0
32: */
33: public class ClearOutputAction extends Action {
34:
35: private ITextViewer fViewer;
36: private TextConsole fIOConsole;
37:
38: /**
39: * Constructs a clear output action.
40: *
41: * @since 3.1
42: */
43: private ClearOutputAction() {
44: super (ConsoleMessages.ClearOutputAction_title);
45: setToolTipText(ConsoleMessages.ClearOutputAction_toolTipText);
46: setHoverImageDescriptor(ConsolePluginImages
47: .getImageDescriptor(IConsoleConstants.IMG_LCL_CLEAR));
48: setDisabledImageDescriptor(ConsolePluginImages
49: .getImageDescriptor(IInternalConsoleConstants.IMG_DLCL_CLEAR));
50: setImageDescriptor(ConsolePluginImages
51: .getImageDescriptor(IInternalConsoleConstants.IMG_ELCL_CLEAR));
52: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
53: IConsoleHelpContextIds.CLEAR_CONSOLE_ACTION);
54: }
55:
56: /**
57: * Constructs a clear output action for an I/O console. Clearing an I/O console
58: * is performed via API on the <code>IOConsole</code>, rather than clearing
59: * its document directly.
60: *
61: * @param ioConsole I/O console the action is associated with
62: * @since 3.1
63: */
64: public ClearOutputAction(TextConsole ioConsole) {
65: this ();
66: fIOConsole = ioConsole;
67: }
68:
69: /**
70: * Constructs an action to clear the document associated with a text viewer.
71: *
72: * @param viewer viewer whose document this action is associated with
73: */
74: public ClearOutputAction(ITextViewer viewer) {
75: this ();
76: fViewer = viewer;
77: }
78:
79: /* (non-Javadoc)
80: * @see org.eclipse.jface.action.IAction#run()
81: */
82: public void run() {
83: BusyIndicator.showWhile(ConsolePlugin.getStandardDisplay(),
84: new Runnable() {
85: public void run() {
86: if (fIOConsole == null) {
87: IDocument document = fViewer.getDocument();
88: if (document != null) {
89: document.set(""); //$NON-NLS-1$
90: }
91: fViewer.setSelectedRange(0, 0);
92: } else {
93: fIOConsole.clearConsole();
94: }
95: }
96: });
97: }
98: }
|