Source Code Cross Referenced for ExtractSuperClassAction.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) 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.internal.ui.actions;
011:
012:        import java.io.CharConversionException;
013:        import java.util.Arrays;
014:        import java.util.HashSet;
015:        import java.util.Iterator;
016:        import java.util.Set;
017:
018:        import org.eclipse.jface.dialogs.MessageDialog;
019:        import org.eclipse.jface.viewers.IStructuredSelection;
020:
021:        import org.eclipse.jface.text.ITextSelection;
022:
023:        import org.eclipse.ui.IWorkbenchSite;
024:        import org.eclipse.ui.PlatformUI;
025:
026:        import org.eclipse.jdt.core.IJavaElement;
027:        import org.eclipse.jdt.core.IMember;
028:        import org.eclipse.jdt.core.IType;
029:        import org.eclipse.jdt.core.JavaModelException;
030:
031:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
032:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
033:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
034:
035:        import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
036:
037:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
038:        import org.eclipse.jdt.internal.ui.JavaPlugin;
039:        import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
040:        import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
041:        import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
042:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
043:
044:        /**
045:         * Action to extract a supertype from a class.
046:         * <p>
047:         * Action is applicable to selections containing elements of type
048:         * <code>IType</code> (top-level types only), <code>IField</code> and
049:         * <code>IMethod</code>.
050:         * </p>
051:         * <p>
052:         * This class may be instantiated; it is not intended to be subclassed.
053:         * </p>
054:         * 
055:         * @since 3.2
056:         */
057:        public class ExtractSuperClassAction extends SelectionDispatchAction {
058:
059:            /**
060:             * Action definition ID of the refactor -> extract supertype action (value
061:             * <code>"org.eclipse.jdt.ui.edit.text.java.extract.superclass"</code>).
062:             * 
063:             * @since 3.2
064:             */
065:            public static final String EXTRACT_SUPERTYPE = "org.eclipse.jdt.ui.edit.text.java.extract.superclass"; //$NON-NLS-1$
066:
067:            /**
068:             * Refactor menu: name of standard Extract Supertype global action (value
069:             * <code>"org.eclipse.jdt.ui.actions.ExtractSuperclass"</code>).
070:             * 
071:             * @since 3.2
072:             */
073:            public static final String EXTRACT_SUPERTYPES = "org.eclipse.jdt.ui.actions.ExtractSuperclass"; //$NON-NLS-1$
074:
075:            private static IMember[] getSelectedMembers(
076:                    final IStructuredSelection selection) {
077:                if (selection.isEmpty())
078:                    return null;
079:                if (selection.size() == 1) {
080:                    try {
081:                        final IType type = RefactoringAvailabilityTester
082:                                .getSingleSelectedType(selection);
083:                        if (type != null)
084:                            return new IType[] { type };
085:                    } catch (JavaModelException exception) {
086:                        JavaPlugin.log(exception);
087:                    }
088:                }
089:                for (final Iterator iterator = selection.iterator(); iterator
090:                        .hasNext();) {
091:                    if (!(iterator.next() instanceof  IMember))
092:                        return null;
093:                }
094:                final Set set = new HashSet();
095:                set.addAll(Arrays.asList(selection.toArray()));
096:                return (IMember[]) set.toArray(new IMember[set.size()]);
097:            }
098:
099:            /** The java editor */
100:            private JavaEditor fEditor;
101:
102:            /**
103:             * Note: This constructor is for internal use only. Clients should not call
104:             * this constructor.
105:             * 
106:             * @param editor
107:             *            the java editor
108:             */
109:            public ExtractSuperClassAction(final JavaEditor editor) {
110:                this (editor.getEditorSite());
111:                fEditor = editor;
112:                setEnabled(SelectionConverter.canOperateOn(fEditor));
113:            }
114:
115:            /**
116:             * Creates a new extract super type action. The action requires that the
117:             * selection provided by the site's selection provider is of type
118:             * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
119:             * 
120:             * @param site
121:             *            the workbench site
122:             */
123:            public ExtractSuperClassAction(final IWorkbenchSite site) {
124:                super (site);
125:                setText(RefactoringMessages.ExtractSuperTypeAction_label);
126:                PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
127:                        IJavaHelpContextIds.EXTRACT_SUPERTYPE_ACTION);
128:            }
129:
130:            private IMember getSelectedMemberFromEditor()
131:                    throws JavaModelException {
132:                final IJavaElement element = SelectionConverter
133:                        .resolveEnclosingElement(fEditor,
134:                                (ITextSelection) fEditor.getSelectionProvider()
135:                                        .getSelection());
136:                if (element == null || !(element instanceof  IMember))
137:                    return null;
138:                return (IMember) element;
139:            }
140:
141:            /**
142:             * {@inheritDoc}
143:             */
144:            public void run(final IStructuredSelection selection) {
145:                try {
146:                    final IMember[] members = getSelectedMembers(selection);
147:                    if (RefactoringAvailabilityTester
148:                            .isExtractSupertypeAvailable(members)
149:                            && ActionUtil.isEditable(getShell(), members[0]))
150:                        RefactoringExecutionStarter
151:                                .startExtractSupertypeRefactoring(members,
152:                                        getShell());
153:                } catch (final JavaModelException exception) {
154:                    ExceptionHandler
155:                            .handle(
156:                                    exception,
157:                                    RefactoringMessages.OpenRefactoringWizardAction_refactoring,
158:                                    RefactoringMessages.OpenRefactoringWizardAction_exception);
159:                }
160:            }
161:
162:            /**
163:             * {@inheritDoc}
164:             */
165:            public void run(final ITextSelection selection) {
166:                try {
167:                    if (!ActionUtil.isEditable(fEditor))
168:                        return;
169:                    final IMember member = getSelectedMemberFromEditor();
170:                    final IMember[] array = new IMember[] { member };
171:                    if (member != null
172:                            && RefactoringAvailabilityTester
173:                                    .isExtractSupertypeAvailable(array)) {
174:                        RefactoringExecutionStarter
175:                                .startExtractSupertypeRefactoring(array,
176:                                        getShell());
177:                    } else {
178:                        MessageDialog
179:                                .openInformation(
180:                                        getShell(),
181:                                        RefactoringMessages.OpenRefactoringWizardAction_unavailable,
182:                                        RefactoringMessages.ExtractSuperTypeAction_unavailable);
183:                    }
184:                } catch (JavaModelException exception) {
185:                    ExceptionHandler
186:                            .handle(
187:                                    exception,
188:                                    RefactoringMessages.OpenRefactoringWizardAction_refactoring,
189:                                    RefactoringMessages.OpenRefactoringWizardAction_exception);
190:                }
191:            }
192:
193:            /**
194:             * {@inheritDoc}
195:             */
196:            public void selectionChanged(final IStructuredSelection selection) {
197:                try {
198:                    setEnabled(RefactoringAvailabilityTester
199:                            .isExtractSupertypeAvailable(selection));
200:                } catch (JavaModelException exception) {
201:                    // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
202:                    if (!(exception.getException() instanceof  CharConversionException)
203:                            && JavaModelUtil.isExceptionToBeLogged(exception))
204:                        JavaPlugin.log(exception);
205:                    setEnabled(false);//no UI - happens on selection changes
206:                }
207:            }
208:
209:            /**
210:             * {@inheritDoc}
211:             */
212:            public void selectionChanged(final ITextSelection selection) {
213:                setEnabled(true);
214:            }
215:
216:            /**
217:             * {@inheritDoc}
218:             */
219:            public void selectionChanged(final JavaTextSelection selection) {
220:                try {
221:                    setEnabled(RefactoringAvailabilityTester
222:                            .isExtractSupertypeAvailable(selection));
223:                } catch (JavaModelException event) {
224:                    setEnabled(false);
225:                }
226:            }
227:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.