KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > console > actions > ClearOutputAction


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.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 /**
28  * Clears the output in a text console.
29  * <p>
30  * Clients may instantiate this class; this class is not intended to
31  * be subclassed.
32  * </p>
33  * @since 3.0
34  */

35 public class ClearOutputAction extends Action {
36
37     private ITextViewer fViewer;
38     private TextConsole fIOConsole;
39
40     /**
41      * Constructs a clear output action.
42      *
43      * @since 3.1
44      */

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     /**
55      * Constructs a clear output action for an I/O console. Clearing an I/O console
56      * is performed via API on the <code>IOConsole</code>, rather than clearing
57      * its document directly.
58      *
59      * @param ioConsole I/O console the action is associated with
60      * @since 3.1
61      */

62     public ClearOutputAction(TextConsole ioConsole) {
63         this();
64         fIOConsole = ioConsole;
65     }
66     
67     /**
68      * Constructs an action to clear the document associated with a text viewer.
69      *
70      * @param viewer viewer whose document this action is associated with
71      */

72     public ClearOutputAction(ITextViewer viewer) {
73         this();
74         fViewer = viewer;
75     }
76
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.action.IAction#run()
79      */

80     public void run() {
81         BusyIndicator.showWhile(ConsolePlugin.getStandardDisplay(), new Runnable JavaDoc() {
82             public void run() {
83                 if (fIOConsole == null) {
84                     IDocument document = fViewer.getDocument();
85                     if (document != null) {
86                         document.set(""); //$NON-NLS-1$
87
}
88                     fViewer.setSelectedRange(0, 0);
89                 } else {
90                     fIOConsole.clearConsole();
91                 }
92             }
93         });
94     }
95 }
96
Popular Tags