KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jface.action.Action;
14 import org.eclipse.ui.IPageListener;
15 import org.eclipse.ui.IPartListener;
16 import org.eclipse.ui.IWorkbenchPage;
17 import org.eclipse.ui.IWorkbenchPart;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.actions.ActionFactory;
20
21 /**
22  * Implements an action to open a list of open editors in the
23  * currently or last active workbook
24  *
25  * @since 3.0
26  */

27 public class WorkbookEditorsAction extends Action implements
28         ActionFactory.IWorkbenchAction, IPageListener, IPartListener {
29
30     /**
31      * The workbench window; or <code>null</code> if this
32      * action has been <code>dispose</code>d.
33      */

34     private IWorkbenchWindow workbenchWindow;
35
36     /**
37      * Constructor for NavigateWorkbenchAction.
38      */

39     public WorkbookEditorsAction(IWorkbenchWindow window) {
40         super(WorkbenchMessages.WorkbookEditorsAction_label);
41         if (window == null) {
42             throw new IllegalArgumentException JavaDoc();
43         }
44         this.workbenchWindow = window;
45         // Do we need help here ?
46
//WorkbenchHelp.setHelp(this, IHelpContextIds.WORKBENCH_EDITORS_ACTION);
47
setActionDefinitionId("org.eclipse.ui.window.openEditorDropDown"); //$NON-NLS-1$
48
workbenchWindow.addPageListener(this);
49         workbenchWindow.getPartService().addPartListener(this);
50         updateState();
51     }
52
53     /* (non-Javadoc)
54      * Method declared on IAction.
55      */

56     public void run() {
57         if (workbenchWindow == null) {
58             // action has been disposed
59
return;
60         }
61         IWorkbenchPage page = workbenchWindow.getActivePage();
62         if (page != null) {
63             WorkbenchPage wbp = (WorkbenchPage) page;
64             EditorAreaHelper eah = wbp.getEditorPresentation();
65             if (eah != null) {
66                 eah.displayEditorList();
67             }
68         }
69     }
70
71     /* (non-Javadoc)
72      * Method declared on ActionFactory.IWorkbenchAction.
73      */

74     public void dispose() {
75         workbenchWindow.removePageListener(this);
76         workbenchWindow.getPartService().removePartListener(this);
77         workbenchWindow = null;
78     }
79
80     /**
81      * Updates the enabled state.
82      */

83     public void updateState() {
84         IWorkbenchPage page = null;
85         if (workbenchWindow != null) {
86             page = workbenchWindow.getActivePage();
87         }
88         if (page == null) {
89             setEnabled(false);
90             return;
91         }
92         // enable iff there is at least one other editor to switch to
93
setEnabled(page.getEditorReferences().length >= 1);
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.ui.IPageListener#pageActivated(org.eclipse.ui.IWorkbenchPage)
98      */

99     public void pageActivated(IWorkbenchPage page) {
100     }
101
102     /* (non-Javadoc)
103      * @see org.eclipse.ui.IPageListener#pageClosed(org.eclipse.ui.IWorkbenchPage)
104      */

105     public void pageClosed(IWorkbenchPage page) {
106         updateState();
107     }
108
109     public void pageOpened(IWorkbenchPage page) {
110         updateState();
111     }
112
113     /* (non-Javadoc)
114      * @see org.eclipse.ui.IPartListener#partActivated(org.eclipse.ui.IWorkbenchPart)
115      */

116     public void partActivated(IWorkbenchPart part) {
117         //no-op
118
}
119
120     /* (non-Javadoc)
121      * @see org.eclipse.ui.IPartListener#partBroughtToTop(org.eclipse.ui.IWorkbenchPart)
122      */

123     public void partBroughtToTop(IWorkbenchPart part) {
124         //no-op
125
}
126
127     /* (non-Javadoc)
128      * @see org.eclipse.ui.IPartListener#partClosed(org.eclipse.ui.IWorkbenchPart)
129      */

130     public void partClosed(IWorkbenchPart part) {
131         updateState();
132     }
133
134     /* (non-Javadoc)
135      * @see org.eclipse.ui.IPartListener#partDeactivated(org.eclipse.ui.IWorkbenchPart)
136      */

137     public void partDeactivated(IWorkbenchPart part) {
138         //no-op
139
}
140
141     /* (non-Javadoc)
142      * @see org.eclipse.ui.IPartListener#partOpened(org.eclipse.ui.IWorkbenchPart)
143      */

144     public void partOpened(IWorkbenchPart part) {
145         updateState();
146     }
147 }
148
Popular Tags