Source Code Cross Referenced for SelectionDispatchAction.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » ui » actions » 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 » jdt » org.eclipse.jdt.ui.actions 
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.jdt.ui.actions;
011:
012:        import org.eclipse.core.runtime.Assert;
013:
014:        import org.eclipse.swt.widgets.Shell;
015:
016:        import org.eclipse.jface.action.Action;
017:        import org.eclipse.jface.viewers.ISelection;
018:        import org.eclipse.jface.viewers.ISelectionChangedListener;
019:        import org.eclipse.jface.viewers.ISelectionProvider;
020:        import org.eclipse.jface.viewers.IStructuredSelection;
021:        import org.eclipse.jface.viewers.SelectionChangedEvent;
022:
023:        import org.eclipse.jface.text.ITextSelection;
024:
025:        import org.eclipse.ui.IWorkbenchSite;
026:
027:        import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
028:
029:        /**
030:         * Action that dispatches the <code>IAction#run()</code> and the 
031:         * <code>ISelectionChangedListener#selectionChanged</code> 
032:         * according to the type of the selection. 
033:         * 
034:         * <ul>
035:         * 	<li>if selection is of type <code>ITextSelection</code> then
036:         * 	<code>run(ITextSelection)</code> and <code>selectionChanged(ITextSelection)</code>
037:         * 	is called.</li> 
038:         * 	<li>if selection is of type <code>IStructuredSelection</code> then
039:         * 	<code>run(IStructuredSelection)</code> and <code>
040:         * 	selectionChanged(IStructuredSelection)</code> is called.</li>
041:         * 	<li>default is to call <code>run(ISelection)</code> and <code>
042:         * 	selectionChanged(ISelection)</code>.</li>
043:         * </ul>
044:         * 
045:         * <p>
046:         * Note: This class is not intended to be subclassed outside the JDT UI plug-in.
047:         * </p>
048:         * 
049:         * @since 2.0
050:         */
051:        public abstract class SelectionDispatchAction extends Action implements 
052:                ISelectionChangedListener {
053:
054:            private IWorkbenchSite fSite;
055:            private ISelectionProvider fSpecialSelectionProvider;
056:
057:            /**
058:             * Creates a new action with no text and no image.
059:             * <p>
060:             * Configure the action later using the set methods.
061:             * </p>
062:             * 
063:             * @param site the site this action is working on
064:             */
065:            protected SelectionDispatchAction(IWorkbenchSite site) {
066:                Assert.isNotNull(site);
067:                fSite = site;
068:            }
069:
070:            /**
071:             * Creates a new action with no text and no image
072:             * 
073:             * <p>
074:             * Configure the action later using the set methods.
075:             * </p>
076:             * 
077:             * @param site the site this action is working on
078:             * @param provider a special selection provider which is used
079:             * instead of the site's selection provider or <code>null</code> to use the site's
080:             * selection provider. Clients can for example use a {@link ConvertingSelectionProvider}
081:             * to first convert a selection before passing it to the action.
082:             *  
083:             * @since 3.2
084:             * @deprecated Use {@link #setSpecialSelectionProvider(ISelectionProvider)} instead. This constructor will be
085:             * removed after 3.2 M5.
086:             */
087:            protected SelectionDispatchAction(IWorkbenchSite site,
088:                    ISelectionProvider provider) {
089:                this (site);
090:                setSpecialSelectionProvider(provider);
091:            }
092:
093:            /**
094:             * Returns the site owning this action.
095:             * 
096:             * @return the site owning this action
097:             */
098:            public IWorkbenchSite getSite() {
099:                return fSite;
100:            }
101:
102:            /**
103:             * Returns the selection provided by the site owning this action.
104:             * 
105:             * @return the site's selection
106:             */
107:            public ISelection getSelection() {
108:                ISelectionProvider selectionProvider = getSelectionProvider();
109:                if (selectionProvider != null)
110:                    return selectionProvider.getSelection();
111:                else
112:                    return null;
113:            }
114:
115:            /**
116:             * Returns the shell provided by the site owning this action.
117:             * 
118:             * @return the site's shell	
119:             */
120:            public Shell getShell() {
121:                return fSite.getShell();
122:            }
123:
124:            /**
125:             * Returns the selection provider managed by the site owning this action or the selection
126:             * provider explicitly set in {@link #setSpecialSelectionProvider(ISelectionProvider)}.
127:             * 
128:             * @return the site's selection provider	
129:             */
130:            public ISelectionProvider getSelectionProvider() {
131:                if (fSpecialSelectionProvider != null) {
132:                    return fSpecialSelectionProvider;
133:                }
134:                return fSite.getSelectionProvider();
135:            }
136:
137:            /**
138:             * Sets a special selection provider which will be used instead of the site's selection provider.
139:             * This method should be used directly after constructing the action and before the action is
140:             * registered as a selection listener. The invocation will not a perform a selection change notification. 
141:             * 
142:             * @param provider a special selection provider which is used
143:             * instead of the site's selection provider or <code>null</code> to use the site's
144:             * selection provider. Clients can for example use a {@link ConvertingSelectionProvider}
145:             * to first convert a selection before passing it to the action.
146:             * 
147:             * @since 3.2
148:             */
149:            public void setSpecialSelectionProvider(ISelectionProvider provider) {
150:                fSpecialSelectionProvider = provider;
151:            }
152:
153:            /**
154:             * Updates the action's enablement state according to the given selection. This
155:             * default implementation calls one of the <code>selectionChanged</code>
156:             * methods depending on the type of the passed selection.
157:             * 
158:             * @param selection the selection this action is working on
159:             */
160:            public void update(ISelection selection) {
161:                dispatchSelectionChanged(selection);
162:            }
163:
164:            /**
165:             * Notifies this action that the given structured selection has changed. This default
166:             * implementation calls <code>selectionChanged(ISelection selection)</code>.
167:             * 
168:             * @param selection the new selection
169:             */
170:            public void selectionChanged(IStructuredSelection selection) {
171:                selectionChanged((ISelection) selection);
172:            }
173:
174:            /**
175:             * Executes this actions with the given structured selection. This default implementation
176:             * calls <code>run(ISelection selection)</code>.
177:             * 
178:             * @param selection the selection
179:             */
180:            public void run(IStructuredSelection selection) {
181:                run((ISelection) selection);
182:            }
183:
184:            /**
185:             * Note: This method is for internal use only. Clients should not call this method.
186:             * 
187:             * @param selection the selection
188:             */
189:            public void selectionChanged(JavaTextSelection selection) {
190:                selectionChanged((ITextSelection) selection);
191:            }
192:
193:            /**
194:             * Note: This method is for internal use only. Clients should not call this method.
195:             * 
196:             * @param selection the selection
197:             */
198:            public void run(JavaTextSelection selection) {
199:                run((ITextSelection) selection);
200:            }
201:
202:            /**
203:             * Notifies this action that the given text selection has changed.  This default
204:             * implementation calls <code>selectionChanged(ISelection selection)</code>.
205:             * 
206:             * @param selection the new selection
207:             */
208:            public void selectionChanged(ITextSelection selection) {
209:                selectionChanged((ISelection) selection);
210:            }
211:
212:            /**
213:             * Executes this actions with the given text selection. This default implementation
214:             * calls <code>run(ISelection selection)</code>.
215:             * 
216:             * @param selection the selection
217:             */
218:            public void run(ITextSelection selection) {
219:                run((ISelection) selection);
220:            }
221:
222:            /**
223:             * Notifies this action that the given selection has changed.  This default
224:             * implementation sets the action's enablement state to <code>false</code>.
225:             * 
226:             * @param selection the new selection
227:             */
228:            public void selectionChanged(ISelection selection) {
229:                setEnabled(false);
230:            }
231:
232:            /**
233:             * Executes this actions with the given selection. This default implementation
234:             * does nothing.
235:             * 
236:             * @param selection the selection
237:             */
238:            public void run(ISelection selection) {
239:            }
240:
241:            /* (non-Javadoc)
242:             * Method declared on IAction.
243:             */
244:            public void run() {
245:                dispatchRun(getSelection());
246:            }
247:
248:            /* (non-Javadoc)
249:             * Method declared on ISelectionChangedListener.
250:             */
251:            public void selectionChanged(SelectionChangedEvent event) {
252:                dispatchSelectionChanged(event.getSelection());
253:            }
254:
255:            private void dispatchSelectionChanged(ISelection selection) {
256:                if (selection instanceof  IStructuredSelection) {
257:                    selectionChanged((IStructuredSelection) selection);
258:                } else if (selection instanceof  JavaTextSelection) {
259:                    selectionChanged((JavaTextSelection) selection);
260:                } else if (selection instanceof  ITextSelection) {
261:                    selectionChanged((ITextSelection) selection);
262:                } else {
263:                    selectionChanged(selection);
264:                }
265:            }
266:
267:            private void dispatchRun(ISelection selection) {
268:                if (selection instanceof  IStructuredSelection) {
269:                    run((IStructuredSelection) selection);
270:                } else if (selection instanceof  JavaTextSelection) {
271:                    run((JavaTextSelection) selection);
272:                } else if (selection instanceof  ITextSelection) {
273:                    run((ITextSelection) selection);
274:                } else {
275:                    run(selection);
276:                }
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.