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


001:        /*******************************************************************************
002:         * Copyright (c) 2007 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.internal.ui.actions;
011:
012:        import org.eclipse.core.runtime.CoreException;
013:
014:        import org.eclipse.jface.dialogs.MessageDialog;
015:        import org.eclipse.jface.viewers.IStructuredSelection;
016:
017:        import org.eclipse.jface.text.ITextSelection;
018:
019:        import org.eclipse.ui.IWorkbenchSite;
020:
021:        import org.eclipse.jdt.core.IJavaElement;
022:        import org.eclipse.jdt.core.IMethod;
023:        import org.eclipse.jdt.core.JavaModelException;
024:
025:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
026:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
027:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
028:
029:        import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
030:
031:        import org.eclipse.jdt.internal.ui.JavaPlugin;
032:        import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
033:        import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
034:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
035:
036:        public class IntroduceParameterObjectAction extends
037:                SelectionDispatchAction {
038:
039:            private JavaEditor fEditor;
040:
041:            /**
042:             * Note: This constructor is for internal use only. Clients should not call this constructor.
043:             * @param editor the compilation unit editor
044:             */
045:            public IntroduceParameterObjectAction(JavaEditor editor) {
046:                this (editor.getEditorSite());
047:                fEditor = editor;
048:                setEnabled(true);
049:            }
050:
051:            /**
052:             * Creates a new <code>IntroduceIndirectionAction</code>. 
053:             * 
054:             * @param site the site providing context information for this action
055:             */
056:            public IntroduceParameterObjectAction(IWorkbenchSite site) {
057:                super (site);
058:                setText(ActionMessages.IntroduceParameterObjectAction_action_text);
059:                setToolTipText(ActionMessages.IntroduceParameterObjectAction_action_tooltip);
060:                setDescription(ActionMessages.IntroduceParameterObjectAction_action_description);
061:            }
062:
063:            //---- structured selection --------------------------------------------------
064:
065:            /*
066:             * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
067:             */
068:            public void selectionChanged(IStructuredSelection selection) {
069:                try {
070:                    setEnabled(RefactoringAvailabilityTester
071:                            .isIntroduceParameterObjectAvailable(selection));
072:                } catch (JavaModelException e) {
073:                    if (JavaModelUtil.isExceptionToBeLogged(e))
074:                        JavaPlugin.log(e);
075:                }
076:            }
077:
078:            /*
079:             * @see SelectionDispatchAction#selectionChanged(ITextSelection)
080:             */
081:            public void selectionChanged(ITextSelection selection) {
082:                setEnabled(true);
083:            }
084:
085:            /* (non-Javadoc)
086:             * @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection)
087:             */
088:            public void selectionChanged(JavaTextSelection selection) {
089:                try {
090:                    setEnabled(RefactoringAvailabilityTester
091:                            .isIntroduceParameterObjectAvailable(selection));
092:                } catch (JavaModelException e) {
093:                    if (JavaModelUtil.isExceptionToBeLogged(e))
094:                        JavaPlugin.log(e);
095:                    setEnabled(false);
096:                }
097:            }
098:
099:            /*
100:             * @see SelectionDispatchAction#run(IStructuredSelection)
101:             */
102:            public void run(IStructuredSelection selection) {
103:                try {
104:                    run(getSingleSelectedMethod(selection));
105:                } catch (CoreException e) {
106:                    ExceptionHandler
107:                            .handle(
108:                                    e,
109:                                    getShell(),
110:                                    ActionMessages.IntroduceParameterObjectAction_exceptiondialog_title,
111:                                    ActionMessages.IntroduceParameterObjectAction_unexpected_exception);
112:                }
113:            }
114:
115:            /*
116:             * (non-Javadoc) Method declared on SelectionDispatchAction
117:             */
118:            public void run(ITextSelection selection) {
119:                try {
120:                    run(getSingleSelectedMethod(selection));
121:                } catch (CoreException e) {
122:                    ExceptionHandler
123:                            .handle(
124:                                    e,
125:                                    getShell(),
126:                                    ActionMessages.IntroduceParameterObjectAction_exceptiondialog_title,
127:                                    ActionMessages.IntroduceParameterObjectAction_unexpected_exception);
128:                }
129:            }
130:
131:            public void run(JavaTextSelection selection) {
132:                try {
133:                    IJavaElement[] elements = selection
134:                            .resolveElementAtOffset();
135:                    if (elements.length != 1)
136:                        return;
137:
138:                    if (!(elements[0] instanceof  IMethod))
139:                        return;
140:
141:                    run((IMethod) elements[0]);
142:                } catch (CoreException e) {
143:                    ExceptionHandler
144:                            .handle(
145:                                    e,
146:                                    getShell(),
147:                                    ActionMessages.IntroduceParameterObjectAction_exceptiondialog_title,
148:                                    ActionMessages.IntroduceParameterObjectAction_unexpected_exception);
149:                }
150:            }
151:
152:            private void run(IMethod method) throws CoreException {
153:                if (method == null) {
154:                    MessageDialog
155:                            .openError(
156:                                    getShell(),
157:                                    ActionMessages.IntroduceParameterObjectAction_exceptiondialog_title,
158:                                    ActionMessages.IntroduceParameterObjectAction_can_not_run_refactoring_message);
159:                } else if (fEditor == null || ActionUtil.isEditable(fEditor)) {
160:                    RefactoringExecutionStarter.startIntroduceParameterObject(
161:                            method, getShell());
162:                }
163:            }
164:
165:            private static IMethod getSingleSelectedMethod(
166:                    IStructuredSelection selection) {
167:                if (selection.size() != 1)
168:                    return null;
169:
170:                Object element = selection.getFirstElement();
171:                if (!(element instanceof  IMethod))
172:                    return null;
173:
174:                return (IMethod) element;
175:            }
176:
177:            private IMethod getSingleSelectedMethod(ITextSelection selection)
178:                    throws JavaModelException {
179:                // - when caret/selection on method name (call or declaration) -> that method
180:                // - otherwise: caret position's enclosing method declaration
181:                // - when caret inside argument list of method declaration -> enclosing method declaration
182:                // - when caret inside argument list of method call -> enclosing method declaration (and NOT method call)
183:                IJavaElement[] elements = SelectionConverter
184:                        .codeResolve(fEditor);
185:                if (elements.length > 1)
186:                    return null;
187:
188:                if (elements.length == 1 && elements[0] instanceof  IMethod) {
189:                    return (IMethod) elements[0];
190:                } else {
191:                    IJavaElement elementAt = SelectionConverter
192:                            .getInputAsCompilationUnit(fEditor).getElementAt(
193:                                    selection.getOffset());
194:                    if (!(elementAt instanceof  IMethod))
195:                        return null;
196:
197:                    return (IMethod) elementAt;
198:                }
199:            }
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.