Source Code Cross Referenced for UseSupertypeAction.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 java.io.CharConversionException;
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:        import org.eclipse.ui.PlatformUI;
021:
022:        import org.eclipse.jdt.core.ICompilationUnit;
023:        import org.eclipse.jdt.core.IType;
024:        import org.eclipse.jdt.core.JavaModelException;
025:
026:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringAvailabilityTester;
027:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringExecutionStarter;
028:        import org.eclipse.jdt.internal.corext.refactoring.util.JavaElementUtil;
029:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
030:
031:        import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
032:        import org.eclipse.jdt.internal.ui.JavaPlugin;
033:        import org.eclipse.jdt.internal.ui.actions.ActionUtil;
034:        import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
035:        import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
036:        import org.eclipse.jdt.internal.ui.javaeditor.JavaTextSelection;
037:        import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages;
038:        import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringActions;
039:        import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
040:
041:        /**
042:         * Tries to use a super type of a class where possible.
043:         *  
044:         * <p>
045:         * This class may be instantiated; it is not intended to be subclassed.
046:         * </p>
047:         * 
048:         * @since 2.1
049:         */
050:        // Note: The disclaimer about instantiating and subclassing got added in 3.1.
051:        // Don't make this class final or remove a constructor!
052:        public class UseSupertypeAction extends SelectionDispatchAction {
053:
054:            private JavaEditor fEditor;
055:
056:            /**
057:             * Note: This constructor is for internal use only. Clients should not call this constructor.
058:             * @param editor the java editor
059:             */
060:            public UseSupertypeAction(JavaEditor editor) {
061:                this (editor.getEditorSite());
062:                fEditor = editor;
063:                setEnabled(SelectionConverter.canOperateOn(fEditor));
064:            }
065:
066:            /**
067:             * Creates a new <code>UseSupertypeAction</code>. The action requires
068:             * that the selection provided by the site's selection provider is of type <code>
069:             * org.eclipse.jface.viewers.IStructuredSelection</code>.
070:             * 
071:             * @param site the site providing context information for this action
072:             */
073:            public UseSupertypeAction(IWorkbenchSite site) {
074:                super (site);
075:                setText(RefactoringMessages.UseSupertypeAction_use_Supertype);
076:                PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
077:                        IJavaHelpContextIds.USE_SUPERTYPE_ACTION);
078:            }
079:
080:            //---- structured selection ---------------------------------------------------
081:
082:            /*
083:             * @see SelectionDispatchAction#selectionChanged(IStructuredSelection)
084:             */
085:            public void selectionChanged(IStructuredSelection selection) {
086:                try {
087:                    setEnabled(RefactoringAvailabilityTester
088:                            .isUseSuperTypeAvailable(selection));
089:                } catch (JavaModelException e) {
090:                    // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
091:                    if (!(e.getException() instanceof  CharConversionException)
092:                            && JavaModelUtil.isExceptionToBeLogged(e))
093:                        JavaPlugin.log(e);
094:                    setEnabled(false);// no UI - happens on selection changes
095:                }
096:            }
097:
098:            /*
099:             * @see SelectionDispatchAction#run(IStructuredSelection)
100:             */
101:            public void run(IStructuredSelection selection) {
102:                try {
103:                    if (RefactoringAvailabilityTester
104:                            .isUseSuperTypeAvailable(selection)) {
105:                        IType singleSelectedType = getSingleSelectedType(selection);
106:                        if (!ActionUtil.isEditable(getShell(),
107:                                singleSelectedType))
108:                            return;
109:                        RefactoringExecutionStarter
110:                                .startUseSupertypeRefactoring(
111:                                        singleSelectedType, getShell());
112:                    }
113:                } catch (JavaModelException e) {
114:                    ExceptionHandler
115:                            .handle(
116:                                    e,
117:                                    RefactoringMessages.OpenRefactoringWizardAction_refactoring,
118:                                    RefactoringMessages.OpenRefactoringWizardAction_exception);
119:                }
120:            }
121:
122:            private static IType getSingleSelectedType(
123:                    IStructuredSelection selection) throws JavaModelException {
124:                if (selection.isEmpty() || selection.size() != 1)
125:                    return null;
126:
127:                Object first = selection.getFirstElement();
128:                if (first instanceof  IType)
129:                    return (IType) first;
130:                if (first instanceof  ICompilationUnit)
131:                    return JavaElementUtil
132:                            .getMainType((ICompilationUnit) first);
133:                return null;
134:            }
135:
136:            //---- text selection ------------------------------------------------------
137:
138:            /*
139:             * @see SelectionDispatchAction#selectionChanged(ITextSelection)
140:             */
141:            public void selectionChanged(ITextSelection selection) {
142:                setEnabled(true);
143:            }
144:
145:            /**
146:             * Note: This method is for internal use only. Clients should not call this method.
147:             */
148:            public void selectionChanged(JavaTextSelection selection) {
149:                try {
150:                    setEnabled(RefactoringAvailabilityTester
151:                            .isUseSuperTypeAvailable(selection));
152:                } catch (JavaModelException e) {
153:                    setEnabled(false);
154:                }
155:            }
156:
157:            /*
158:             * @see SelectionDispatchAction#run(ITextSelection)
159:             */
160:            public void run(ITextSelection selection) {
161:                try {
162:                    IType type = RefactoringActions
163:                            .getEnclosingOrPrimaryType(fEditor);
164:                    if (RefactoringAvailabilityTester
165:                            .isUseSuperTypeAvailable(type)) {
166:                        if (!ActionUtil.isEditable(fEditor, getShell(), type))
167:                            return;
168:                        RefactoringExecutionStarter
169:                                .startUseSupertypeRefactoring(type, getShell());
170:                    } else {
171:                        MessageDialog
172:                                .openInformation(
173:                                        getShell(),
174:                                        RefactoringMessages.OpenRefactoringWizardAction_unavailable,
175:                                        RefactoringMessages.UseSupertypeAction_to_activate);
176:                    }
177:                } catch (JavaModelException e) {
178:                    ExceptionHandler
179:                            .handle(
180:                                    e,
181:                                    RefactoringMessages.OpenRefactoringWizardAction_refactoring,
182:                                    RefactoringMessages.OpenRefactoringWizardAction_exception);
183:                }
184:            }
185:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.