Source Code Cross Referenced for CurrentSelectionSourceProvider.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.Map;
013:        import java.util.TreeMap;
014:
015:        import org.eclipse.jface.viewers.ISelection;
016:        import org.eclipse.ui.AbstractSourceProvider;
017:        import org.eclipse.ui.INullSelectionListener;
018:        import org.eclipse.ui.ISelectionService;
019:        import org.eclipse.ui.ISources;
020:        import org.eclipse.ui.IWindowListener;
021:        import org.eclipse.ui.IWorkbench;
022:        import org.eclipse.ui.IWorkbenchPart;
023:        import org.eclipse.ui.IWorkbenchWindow;
024:
025:        /**
026:         * <p>
027:         * This listens to changes to the current selection, and propagates them through
028:         * the <code>ISourceProvider</code> framework (a common language in which
029:         * events are communicated to expression-based services).
030:         * </p>
031:         * <p>
032:         * This class is not intended for use outside of the
033:         * <code>org.eclipse.ui.workbench</code> plug-in.
034:         * </p>
035:         * 
036:         * @since 3.2
037:         */
038:        public final class CurrentSelectionSourceProvider extends
039:                AbstractSourceProvider implements  INullSelectionListener {
040:
041:            /**
042:             * The names of the sources supported by this source provider.
043:             */
044:            private static final String[] PROVIDED_SOURCE_NAMES = new String[] { ISources.ACTIVE_CURRENT_SELECTION_NAME };
045:
046:            /**
047:             * Monitors changes to the active workbench window, and swaps the selection
048:             * listener to the active workbench window.
049:             */
050:            private final IWindowListener windowListener = new IWindowListener() {
051:                public final void windowActivated(final IWorkbenchWindow window) {
052:                    swapListeners(window, false);
053:                }
054:
055:                public final void windowClosed(final IWorkbenchWindow window) {
056:                    swapListeners(window, true);
057:                }
058:
059:                public final void windowDeactivated(
060:                        final IWorkbenchWindow window) {
061:                    swapListeners(window, true);
062:                }
063:
064:                public final void windowOpened(final IWorkbenchWindow window) {
065:                    swapListeners(window, false);
066:                }
067:            };
068:
069:            /**
070:             * The workbench on which this source provider is acting. This value is
071:             * never <code>null</code>.
072:             */
073:            private final IWorkbench workbench;
074:
075:            /**
076:             * Constructs a new instance of <code>CurrentSelectionSourceProvider</code>.
077:             * 
078:             * @param workbench
079:             *            The workbench on which this source provider should act; this
080:             *            value must not be <code>null</code>.
081:             */
082:            public CurrentSelectionSourceProvider(final IWorkbench workbench) {
083:                this .workbench = workbench;
084:                workbench.addWindowListener(windowListener);
085:            }
086:
087:            public final void dispose() {
088:                workbench.removeWindowListener(windowListener);
089:            }
090:
091:            public final Map getCurrentState() {
092:                final Map currentState = new TreeMap();
093:                final IWorkbenchWindow window = workbench
094:                        .getActiveWorkbenchWindow();
095:                if (window != null) {
096:                    final ISelectionService service = window
097:                            .getSelectionService();
098:                    final ISelection selection = service.getSelection();
099:                    currentState.put(ISources.ACTIVE_CURRENT_SELECTION_NAME,
100:                            selection);
101:                } else {
102:                    currentState.put(ISources.ACTIVE_CURRENT_SELECTION_NAME,
103:                            null);
104:                }
105:                return currentState;
106:            }
107:
108:            public final String[] getProvidedSourceNames() {
109:                return PROVIDED_SOURCE_NAMES;
110:            }
111:
112:            public final void selectionChanged(final IWorkbenchPart part,
113:                    final ISelection selection) {
114:                if (DEBUG) {
115:                    logDebuggingInfo("Selection changed to " + selection); //$NON-NLS-1$
116:                }
117:
118:                fireSourceChanged(ISources.ACTIVE_CURRENT_SELECTION,
119:                        ISources.ACTIVE_CURRENT_SELECTION_NAME, selection);
120:            }
121:
122:            /**
123:             * Swaps the selection listener. This either adds or removes a selection
124:             * listener from the given window's selection service.
125:             * 
126:             * @param window
127:             *            The workbench window to which the listener should be added or
128:             *            from which the listener should be removed; must not be
129:             *            <code>null</code>.
130:             * @param remove
131:             *            Whether the selection listener should be removed; otherwise,
132:             *            it should be added.
133:             */
134:            private final void swapListeners(final IWorkbenchWindow window,
135:                    final boolean remove) {
136:                final ISelectionService selectionService = window
137:                        .getSelectionService();
138:                if (remove) {
139:                    window.getSelectionService().removeSelectionListener(
140:                            CurrentSelectionSourceProvider.this);
141:                    selectionChanged(null, null);
142:                } else {
143:                    window.getSelectionService().addSelectionListener(
144:                            CurrentSelectionSourceProvider.this);
145:                    selectionChanged(null, selectionService.getSelection());
146:                }
147:            }
148:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.