Source Code Cross Referenced for ActiveEditorAction.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Eclipse » ui workbench » org.eclipse.ui.internal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal;
011:
012:        import org.eclipse.ui.IEditorPart;
013:        import org.eclipse.ui.IWorkbenchPage;
014:        import org.eclipse.ui.IWorkbenchPart;
015:        import org.eclipse.ui.IWorkbenchWindow;
016:        import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
017:
018:        /**
019:         * The abstract superclass for actions that depend on the active editor.
020:         * This implementation tracks the active editor (see <code>getActiveEditor</code>)
021:         * and updates the availability of the action when an editor becomes
022:         * active.
023:         * <p>
024:         * Subclasses must implement the following <code>IAction</code> method:
025:         * <ul>
026:         *   <li><code>run</code> - to do the action's work</li>
027:         * </ul>
028:         * </p>
029:         * <p>
030:         * Subclasses may extend any of the <code>IPartListener</code> methods if the
031:         * action availablity needs to be recalculated:
032:         * <ul>
033:         *   <li><code>partActivated</code></li> 
034:         *   <li><code>partDeactivated</code></li>
035:         *   <li><code>partOpened</code></li>
036:         *   <li><code>partClosed</code></li>
037:         *   <li><code>partBroughtToTop</code></li>
038:         * </ul>
039:         * </p>
040:         * <p>
041:         * Subclasses may extend any of the <code>IPageListener</code> methods if the
042:         * action availablity needs to be recalculated:
043:         * <ul>
044:         *   <li><code>pageActivated</code></li> 
045:         *   <li><code>pageClosed</code></li>
046:         *   <li><code>pageOpened</code></li>
047:         * </ul>
048:         * </p>
049:         * <p>
050:         * This method implements the <code>IPartListener</code> and
051:         * <code>IPageListener</code>interfaces, and automatically registers listeners
052:         * so that it can keep its enablement state up to date. Ordinarily, the
053:         * window's references to these listeners will be dropped automatically when
054:         * the window closes. However, if the client needs to get rid of an action
055:         * while the window is still open, the client must call 
056:         * {@link IWorkbenchAction#dispose dispose} to give the action an
057:         * opportunity to deregister its listeners and to perform any other cleanup.
058:         * </p>
059:         */
060:        public abstract class ActiveEditorAction extends PageEventAction {
061:
062:            private IEditorPart activeEditor;
063:
064:            /**
065:             * Creates a new action with the given text.
066:             *
067:             * @param text the string used as the text for the action, 
068:             *   or <code>null</code> if there is no text
069:             * @param window the workbench window this action is
070:             *   registered with.
071:             */
072:            protected ActiveEditorAction(String text, IWorkbenchWindow window) {
073:                super (text, window);
074:                updateState();
075:            }
076:
077:            /**
078:             * Notification that the active editor tracked
079:             * by the action is being activated.
080:             *
081:             * Subclasses may override.
082:             */
083:            protected void editorActivated(IEditorPart part) {
084:            }
085:
086:            /**
087:             * Notification that the active editor tracked
088:             * by the action is being deactivated.
089:             *
090:             * Subclasses may override.
091:             */
092:            protected void editorDeactivated(IEditorPart part) {
093:            }
094:
095:            /**
096:             * Return the active editor
097:             *
098:             * @return the page's active editor, and <code>null</code>
099:             *		if no active editor or no active page.
100:             */
101:            public final IEditorPart getActiveEditor() {
102:                return activeEditor;
103:            }
104:
105:            /* (non-Javadoc)
106:             * Method declared on PageEventAction.
107:             */
108:            public void pageActivated(IWorkbenchPage page) {
109:                super .pageActivated(page);
110:                updateActiveEditor();
111:                updateState();
112:            }
113:
114:            /* (non-Javadoc)
115:             * Method declared on PageEventAction.
116:             */
117:            public void pageClosed(IWorkbenchPage page) {
118:                super .pageClosed(page);
119:                updateActiveEditor();
120:                updateState();
121:            }
122:
123:            /* (non-Javadoc)
124:             * Method declared on PartEventAction.
125:             */
126:            public void partActivated(IWorkbenchPart part) {
127:                super .partActivated(part);
128:                if (part instanceof  IEditorPart) {
129:                    updateActiveEditor();
130:                    updateState();
131:                }
132:            }
133:
134:            /* (non-Javadoc)
135:             * Method declared on PartEventAction.
136:             */
137:            public void partBroughtToTop(IWorkbenchPart part) {
138:                super .partBroughtToTop(part);
139:                if (part instanceof  IEditorPart) {
140:                    updateActiveEditor();
141:                    updateState();
142:                }
143:            }
144:
145:            /* (non-Javadoc)
146:             * Method declared on PartEventAction.
147:             */
148:            public void partClosed(IWorkbenchPart part) {
149:                super .partClosed(part);
150:                if (part instanceof  IEditorPart) {
151:                    updateActiveEditor();
152:                    updateState();
153:                }
154:            }
155:
156:            /* (non-Javadoc)
157:             * Method declared on PartEventAction.
158:             */
159:            public void partDeactivated(IWorkbenchPart part) {
160:                super .partDeactivated(part);
161:                if (part instanceof  IEditorPart) {
162:                    updateActiveEditor();
163:                    updateState();
164:                }
165:            }
166:
167:            /**
168:             * Set the active editor
169:             */
170:            private void setActiveEditor(IEditorPart part) {
171:                if (activeEditor == part) {
172:                    return;
173:                }
174:                if (activeEditor != null) {
175:                    editorDeactivated(activeEditor);
176:                }
177:                activeEditor = part;
178:                if (activeEditor != null) {
179:                    editorActivated(activeEditor);
180:                }
181:            }
182:
183:            /**
184:             * Update the active editor based on the current
185:             * active page.
186:             */
187:            private void updateActiveEditor() {
188:                if (getActivePage() == null) {
189:                    setActiveEditor(null);
190:                } else {
191:                    setActiveEditor(getActivePage().getActiveEditor());
192:                }
193:            }
194:
195:            /**
196:             * Update the state of the action. By default, the action
197:             * is enabled if there is an active editor.
198:             *
199:             * Subclasses may override or extend this method.
200:             */
201:            protected void updateState() {
202:                setEnabled(getActiveEditor() != null);
203:            }
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.