KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > CloseAllAction


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.internal;
12
13 import org.eclipse.ui.IWorkbenchPage;
14 import org.eclipse.ui.IWorkbenchPart;
15 import org.eclipse.ui.IWorkbenchWindow;
16
17 /**
18  * Closes all active editors
19  */

20 public class CloseAllAction extends PageEventAction {
21
22     /**
23      * Create an instance of this class.
24      *
25      * @param window the window
26      */

27     public CloseAllAction(IWorkbenchWindow window) {
28         super(WorkbenchMessages.CloseAllAction_text, window);
29         setToolTipText(WorkbenchMessages.CloseAllAction_toolTip);
30         setEnabled(false);
31         setId("closeAll"); //$NON-NLS-1$
32
updateState();
33         window.getWorkbench().getHelpSystem().setHelp(this,
34                 IWorkbenchHelpContextIds.CLOSE_ALL_ACTION);
35         setActionDefinitionId("org.eclipse.ui.file.closeAll"); //$NON-NLS-1$
36
}
37
38     /* (non-Javadoc)
39      * Method declared on PageEventAction.
40      */

41     public void pageActivated(IWorkbenchPage page) {
42         super.pageActivated(page);
43         updateState();
44     }
45
46     /* (non-Javadoc)
47      * Method declared on PageEventAction.
48      */

49     public void pageClosed(IWorkbenchPage page) {
50         super.pageClosed(page);
51         updateState();
52     }
53
54     /* (non-Javadoc)
55      * Method declared on PartEventAction.
56      */

57     public void partClosed(IWorkbenchPart part) {
58         super.partClosed(part);
59         updateState();
60     }
61
62     /* (non-Javadoc)
63      * Method declared on PartEventAction.
64      */

65     public void partOpened(IWorkbenchPart part) {
66         super.partOpened(part);
67         updateState();
68     }
69
70     /* (non-Javadoc)
71      * Method declared on Action.
72      */

73     public void run() {
74         if (getWorkbenchWindow() == null) {
75             // action has been disposed
76
return;
77         }
78         IWorkbenchPage page = getActivePage();
79         if (page != null) {
80             page.closeAllEditors(true);
81         }
82     }
83
84     /**
85      * Enable the action if there at least one editor open.
86      */

87     private void updateState() {
88         IWorkbenchPage page = getActivePage();
89         if (page != null) {
90             setEnabled(page.getEditorReferences().length >= 1);
91         } else {
92             setEnabled(false);
93         }
94     }
95 }
96
Popular Tags