Source Code Cross Referenced for ActivePartSourceProvider.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » services » 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.services 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2005, 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.services;
011:
012:        import java.util.HashMap;
013:        import java.util.Map;
014:
015:        import org.eclipse.ui.AbstractSourceProvider;
016:        import org.eclipse.ui.IEditorPart;
017:        import org.eclipse.ui.IEditorSite;
018:        import org.eclipse.ui.IPartListener;
019:        import org.eclipse.ui.ISources;
020:        import org.eclipse.ui.IWindowListener;
021:        import org.eclipse.ui.IWorkbench;
022:        import org.eclipse.ui.IWorkbenchPage;
023:        import org.eclipse.ui.IWorkbenchPart;
024:        import org.eclipse.ui.IWorkbenchPartSite;
025:        import org.eclipse.ui.IWorkbenchWindow;
026:        import org.eclipse.ui.internal.util.Util;
027:
028:        /**
029:         * Provides notifications when the active part changes.
030:         * 
031:         * @since 3.1
032:         */
033:        public class ActivePartSourceProvider extends AbstractSourceProvider {
034:
035:            /**
036:             * The names of the sources supported by this source provider.
037:             */
038:            private static final String[] PROVIDED_SOURCE_NAMES = new String[] {
039:                    ISources.ACTIVE_EDITOR_ID_NAME,
040:                    ISources.ACTIVE_EDITOR_NAME, ISources.ACTIVE_PART_ID_NAME,
041:                    ISources.ACTIVE_PART_NAME, ISources.ACTIVE_SITE_NAME };
042:
043:            /**
044:             * The last active editor part seen as active by this provider. This value
045:             * may be <code>null</code> if there is no currently active editor.
046:             */
047:            private IEditorPart lastActiveEditor = null;
048:
049:            /**
050:             * The last active editor id seen as active by this provider. This value may
051:             * be <code>null</code> if there is no currently active editor.
052:             */
053:            private String lastActiveEditorId = null;
054:
055:            /**
056:             * The last active part seen as active by this provider. This value may be
057:             * <code>null</code> if there is no currently active part.
058:             */
059:            private IWorkbenchPart lastActivePart = null;
060:
061:            /**
062:             * The last active part id seen as active by this provider. This value may
063:             * be <code>null</code> if there is no currently active part.
064:             */
065:            private String lastActivePartId = null;
066:
067:            /**
068:             * The last active part site seen by this provider. This value may be
069:             * <code>null</code> if there is no currently active site.
070:             */
071:            private IWorkbenchPartSite lastActivePartSite = null;
072:
073:            private final IPartListener partListener = new IPartListener() {
074:
075:                public final void partActivated(final IWorkbenchPart part) {
076:                    checkActivePart();
077:                }
078:
079:                public final void partBroughtToTop(final IWorkbenchPart part) {
080:                    checkActivePart();
081:                }
082:
083:                public final void partClosed(final IWorkbenchPart part) {
084:                    checkActivePart();
085:                }
086:
087:                public final void partDeactivated(final IWorkbenchPart part) {
088:                    checkActivePart();
089:                }
090:
091:                public final void partOpened(final IWorkbenchPart part) {
092:                    checkActivePart();
093:                }
094:
095:            };
096:
097:            private final IWindowListener windowListener = new IWindowListener() {
098:
099:                public final void windowActivated(final IWorkbenchWindow window) {
100:                    checkActivePart();
101:                }
102:
103:                public final void windowClosed(final IWorkbenchWindow window) {
104:                    if (window != null) {
105:                        window.getPartService()
106:                                .removePartListener(partListener);
107:                    }
108:                    checkActivePart();
109:                }
110:
111:                public final void windowDeactivated(
112:                        final IWorkbenchWindow window) {
113:                    checkActivePart();
114:                }
115:
116:                public final void windowOpened(final IWorkbenchWindow window) {
117:                    if (window != null) {
118:                        window.getPartService().addPartListener(partListener);
119:                    }
120:                    checkActivePart();
121:                }
122:
123:            };
124:
125:            /**
126:             * The workbench on which this source provider will act.
127:             */
128:            private final IWorkbench workbench;
129:
130:            /**
131:             * Constructs a new instance of <code>ShellSourceProvider</code>.
132:             * 
133:             * @param workbench
134:             *            The workbench on which to monitor shell activations; must not
135:             *            be <code>null</code>.
136:             */
137:            public ActivePartSourceProvider(final IWorkbench workbench) {
138:                this .workbench = workbench;
139:                workbench.addWindowListener(windowListener);
140:            }
141:
142:            private final void checkActivePart() {
143:                final Map currentState = getCurrentState();
144:                int sources = 0;
145:
146:                // Figure out what was changed.
147:                final Object newActivePart = currentState
148:                        .get(ISources.ACTIVE_PART_NAME);
149:                if (!Util.equals(newActivePart, lastActivePart)) {
150:                    sources |= ISources.ACTIVE_PART;
151:                    lastActivePart = (IWorkbenchPart) newActivePart;
152:                }
153:                final Object newActivePartId = currentState
154:                        .get(ISources.ACTIVE_PART_ID_NAME);
155:                if (!Util.equals(newActivePartId, lastActivePartId)) {
156:                    sources |= ISources.ACTIVE_PART_ID;
157:                    lastActivePartId = (String) newActivePartId;
158:                }
159:                final Object newActivePartSite = currentState
160:                        .get(ISources.ACTIVE_SITE_NAME);
161:                if (!Util.equals(newActivePartSite, lastActivePartSite)) {
162:                    sources |= ISources.ACTIVE_SITE;
163:                    lastActivePartSite = (IWorkbenchPartSite) newActivePartSite;
164:                }
165:                final Object newActiveEditor = currentState
166:                        .get(ISources.ACTIVE_EDITOR_NAME);
167:                if (!Util.equals(newActiveEditor, lastActiveEditor)) {
168:                    sources |= ISources.ACTIVE_EDITOR;
169:                    lastActiveEditor = (IEditorPart) newActiveEditor;
170:                }
171:                final Object newActiveEditorId = currentState
172:                        .get(ISources.ACTIVE_EDITOR_ID_NAME);
173:                if (!Util.equals(newActiveEditorId, lastActiveEditorId)) {
174:                    sources |= ISources.ACTIVE_EDITOR_ID;
175:                    lastActiveEditorId = (String) newActiveEditorId;
176:                }
177:
178:                // Fire the event, if something has changed.
179:                if (sources != 0) {
180:                    if (DEBUG) {
181:                        if ((sources & ISources.ACTIVE_PART) != 0) {
182:                            logDebuggingInfo("Active part changed to " //$NON-NLS-1$
183:                                    + lastActivePart);
184:                        }
185:                        if ((sources & ISources.ACTIVE_PART_ID) != 0) {
186:                            logDebuggingInfo("Active part id changed to " //$NON-NLS-1$
187:                                    + lastActivePartId);
188:                        }
189:                        if ((sources & ISources.ACTIVE_SITE) != 0) {
190:                            logDebuggingInfo("Active site changed to " //$NON-NLS-1$
191:                                    + lastActivePartSite);
192:                        }
193:                        if ((sources & ISources.ACTIVE_EDITOR) != 0) {
194:                            logDebuggingInfo("Active editor changed to " //$NON-NLS-1$
195:                                    + lastActiveEditor);
196:                        }
197:                        if ((sources & ISources.ACTIVE_EDITOR_ID) != 0) {
198:                            logDebuggingInfo("Active editor id changed to " //$NON-NLS-1$
199:                                    + lastActiveEditorId);
200:                        }
201:                    }
202:                    fireSourceChanged(sources, currentState);
203:                }
204:            }
205:
206:            public final void dispose() {
207:                workbench.removeWindowListener(windowListener);
208:            }
209:
210:            public final Map getCurrentState() {
211:                final Map currentState = new HashMap(7);
212:                currentState.put(ISources.ACTIVE_SITE_NAME, null);
213:                currentState.put(ISources.ACTIVE_PART_NAME, null);
214:                currentState.put(ISources.ACTIVE_PART_ID_NAME, null);
215:                currentState.put(ISources.ACTIVE_EDITOR_NAME, null);
216:                currentState.put(ISources.ACTIVE_EDITOR_ID_NAME, null);
217:
218:                final IWorkbenchWindow activeWorkbenchWindow = workbench
219:                        .getActiveWorkbenchWindow();
220:                if (activeWorkbenchWindow != null) {
221:                    final IWorkbenchPage activeWorkbenchPage = activeWorkbenchWindow
222:                            .getActivePage();
223:                    if (activeWorkbenchPage != null) {
224:                        // Check the active workbench part.
225:                        final IWorkbenchPart newActivePart = activeWorkbenchPage
226:                                .getActivePart();
227:                        currentState.put(ISources.ACTIVE_PART_NAME,
228:                                newActivePart);
229:                        if (newActivePart != null) {
230:                            final IWorkbenchPartSite activeWorkbenchPartSite = newActivePart
231:                                    .getSite();
232:                            currentState.put(ISources.ACTIVE_SITE_NAME,
233:                                    activeWorkbenchPartSite);
234:                            if (activeWorkbenchPartSite != null) {
235:                                final String newActivePartId = activeWorkbenchPartSite
236:                                        .getId();
237:                                currentState.put(ISources.ACTIVE_PART_ID_NAME,
238:                                        newActivePartId);
239:                            }
240:                        }
241:
242:                        // Check the active editor part.
243:                        final IEditorPart newActiveEditor = activeWorkbenchPage
244:                                .getActiveEditor();
245:                        currentState.put(ISources.ACTIVE_EDITOR_NAME,
246:                                newActiveEditor);
247:                        if (newActiveEditor != null) {
248:                            final IEditorSite activeEditorSite = newActiveEditor
249:                                    .getEditorSite();
250:                            if (activeEditorSite != null) {
251:                                final String newActiveEditorId = activeEditorSite
252:                                        .getId();
253:                                currentState.put(
254:                                        ISources.ACTIVE_EDITOR_ID_NAME,
255:                                        newActiveEditorId);
256:                            }
257:                        }
258:                    }
259:                }
260:
261:                return currentState;
262:            }
263:
264:            public final String[] getProvidedSourceNames() {
265:                return PROVIDED_SOURCE_NAMES;
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.