Source Code Cross Referenced for NewNameQueries.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » ui » refactoring » reorg » 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.refactoring.reorg 
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.internal.ui.refactoring.reorg;
011:
012:        import org.eclipse.core.runtime.Assert;
013:        import org.eclipse.core.runtime.CoreException;
014:        import org.eclipse.core.runtime.IStatus;
015:        import org.eclipse.core.runtime.OperationCanceledException;
016:
017:        import org.eclipse.core.resources.IResource;
018:
019:        import org.eclipse.swt.widgets.Composite;
020:        import org.eclipse.swt.widgets.Control;
021:        import org.eclipse.swt.widgets.Shell;
022:
023:        import org.eclipse.jface.dialogs.IInputValidator;
024:        import org.eclipse.jface.dialogs.InputDialog;
025:        import org.eclipse.jface.window.Window;
026:        import org.eclipse.jface.wizard.Wizard;
027:
028:        import org.eclipse.ltk.core.refactoring.RefactoringStatus;
029:
030:        import org.eclipse.jdt.core.ICompilationUnit;
031:        import org.eclipse.jdt.core.IJavaElement;
032:        import org.eclipse.jdt.core.IPackageFragment;
033:        import org.eclipse.jdt.core.IPackageFragmentRoot;
034:        import org.eclipse.jdt.core.JavaCore;
035:
036:        import org.eclipse.jdt.internal.corext.refactoring.Checks;
037:        import org.eclipse.jdt.internal.corext.refactoring.rename.RenamePackageProcessor;
038:        import org.eclipse.jdt.internal.corext.refactoring.reorg.INewNameQueries;
039:        import org.eclipse.jdt.internal.corext.refactoring.reorg.INewNameQuery;
040:        import org.eclipse.jdt.internal.corext.util.JavaConventionsUtil;
041:        import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
042:        import org.eclipse.jdt.internal.corext.util.Messages;
043:
044:        import org.eclipse.jdt.internal.ui.JavaPlugin;
045:        import org.eclipse.jdt.internal.ui.dialogs.TextFieldNavigationHandler;
046:
047:        public class NewNameQueries implements  INewNameQueries {
048:
049:            private static final String INVALID_NAME_NO_MESSAGE = "";//$NON-NLS-1$
050:            private final Wizard fWizard;
051:            private final Shell fShell;
052:
053:            public NewNameQueries() {
054:                fShell = null;
055:                fWizard = null;
056:            }
057:
058:            public NewNameQueries(Wizard wizard) {
059:                fWizard = wizard;
060:                fShell = null;
061:            }
062:
063:            public NewNameQueries(Shell shell) {
064:                fShell = shell;
065:                fWizard = null;
066:            }
067:
068:            private Shell getShell() {
069:                Assert.isTrue(fWizard == null || fShell == null);
070:                if (fWizard != null)
071:                    return fWizard.getContainer().getShell();
072:
073:                if (fShell != null)
074:                    return fShell;
075:                return JavaPlugin.getActiveWorkbenchShell();
076:            }
077:
078:            public INewNameQuery createNewCompilationUnitNameQuery(
079:                    ICompilationUnit cu, String initialSuggestedName) {
080:                String[] keys = { JavaCore.removeJavaLikeExtension(cu
081:                        .getElementName()) };
082:                String message = Messages.format(
083:                        ReorgMessages.ReorgQueries_enterNewNameQuestion, keys);
084:                return createStaticQuery(
085:                        createCompilationUnitNameValidator(cu), message,
086:                        initialSuggestedName, getShell());
087:            }
088:
089:            public INewNameQuery createNewResourceNameQuery(IResource res,
090:                    String initialSuggestedName) {
091:                String[] keys = { res.getName() };
092:                String message = Messages.format(
093:                        ReorgMessages.ReorgQueries_enterNewNameQuestion, keys);
094:                return createStaticQuery(createResourceNameValidator(res),
095:                        message, initialSuggestedName, getShell());
096:            }
097:
098:            public INewNameQuery createNewPackageNameQuery(
099:                    IPackageFragment pack, String initialSuggestedName) {
100:                String[] keys = { pack.getElementName() };
101:                String message = Messages.format(
102:                        ReorgMessages.ReorgQueries_enterNewNameQuestion, keys);
103:                return createStaticQuery(createPackageNameValidator(pack),
104:                        message, initialSuggestedName, getShell());
105:            }
106:
107:            public INewNameQuery createNewPackageFragmentRootNameQuery(
108:                    IPackageFragmentRoot root, String initialSuggestedName) {
109:                String[] keys = { root.getElementName() };
110:                String message = Messages.format(
111:                        ReorgMessages.ReorgQueries_enterNewNameQuestion, keys);
112:                return createStaticQuery(
113:                        createPackageFragmentRootNameValidator(root), message,
114:                        initialSuggestedName, getShell());
115:            }
116:
117:            public INewNameQuery createNullQuery() {
118:                return createStaticQuery(null);
119:            }
120:
121:            public INewNameQuery createStaticQuery(final String newName) {
122:                return new INewNameQuery() {
123:                    public String getNewName() {
124:                        return newName;
125:                    }
126:                };
127:            }
128:
129:            private static INewNameQuery createStaticQuery(
130:                    final IInputValidator validator, final String message,
131:                    final String initial, final Shell shell) {
132:                return new INewNameQuery() {
133:                    public String getNewName()
134:                            throws OperationCanceledException {
135:                        InputDialog dialog = new InputDialog(shell,
136:                                ReorgMessages.ReorgQueries_nameConflictMessage,
137:                                message, initial, validator) {
138:                            /* (non-Javadoc)
139:                             * @see org.eclipse.jface.dialogs.InputDialog#createDialogArea(org.eclipse.swt.widgets.Composite)
140:                             */
141:                            protected Control createDialogArea(Composite parent) {
142:                                Control area = super .createDialogArea(parent);
143:                                TextFieldNavigationHandler.install(getText());
144:                                return area;
145:                            }
146:                        };
147:                        if (dialog.open() == Window.CANCEL)
148:                            throw new OperationCanceledException();
149:                        return dialog.getValue();
150:                    }
151:                };
152:            }
153:
154:            private static IInputValidator createResourceNameValidator(
155:                    final IResource res) {
156:                IInputValidator validator = new IInputValidator() {
157:                    public String isValid(String newText) {
158:                        if (newText == null
159:                                || "".equals(newText) || res.getParent() == null) //$NON-NLS-1$
160:                            return INVALID_NAME_NO_MESSAGE;
161:                        if (res.getParent().findMember(newText) != null)
162:                            return ReorgMessages.ReorgQueries_resourceWithThisNameAlreadyExists;
163:                        if (!res.getParent().getFullPath().isValidSegment(
164:                                newText))
165:                            return ReorgMessages.ReorgQueries_invalidNameMessage;
166:                        IStatus status = res.getParent().getWorkspace()
167:                                .validateName(newText, res.getType());
168:                        if (status.getSeverity() == IStatus.ERROR)
169:                            return status.getMessage();
170:
171:                        if (res.getName().equalsIgnoreCase(newText))
172:                            return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;
173:
174:                        return null;
175:                    }
176:                };
177:                return validator;
178:            }
179:
180:            private static IInputValidator createCompilationUnitNameValidator(
181:                    final ICompilationUnit cu) {
182:                IInputValidator validator = new IInputValidator() {
183:                    public String isValid(String newText) {
184:                        if (newText == null || "".equals(newText)) //$NON-NLS-1$
185:                            return INVALID_NAME_NO_MESSAGE;
186:                        String newCuName = JavaModelUtil.getRenamedCUName(cu,
187:                                newText);
188:                        IStatus status = JavaConventionsUtil
189:                                .validateCompilationUnitName(newCuName, cu);
190:                        if (status.getSeverity() == IStatus.ERROR)
191:                            return status.getMessage();
192:                        RefactoringStatus refStatus;
193:                        refStatus = Checks.checkCompilationUnitNewName(cu,
194:                                newText);
195:                        if (refStatus.hasFatalError())
196:                            return refStatus
197:                                    .getMessageMatchingSeverity(RefactoringStatus.FATAL);
198:
199:                        if (cu.getElementName().equalsIgnoreCase(newCuName))
200:                            return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;
201:
202:                        return null;
203:                    }
204:                };
205:                return validator;
206:            }
207:
208:            private static IInputValidator createPackageFragmentRootNameValidator(
209:                    final IPackageFragmentRoot root) {
210:                return new IInputValidator() {
211:                    IInputValidator resourceNameValidator = createResourceNameValidator(root
212:                            .getResource());
213:
214:                    public String isValid(String newText) {
215:                        return resourceNameValidator.isValid(newText);
216:                    }
217:                };
218:            }
219:
220:            private static IInputValidator createPackageNameValidator(
221:                    final IPackageFragment pack) {
222:                IInputValidator validator = new IInputValidator() {
223:                    public String isValid(String newText) {
224:                        if (newText == null || "".equals(newText)) //$NON-NLS-1$
225:                            return INVALID_NAME_NO_MESSAGE;
226:                        IStatus status = JavaConventionsUtil
227:                                .validatePackageName(newText, pack);
228:                        if (status.getSeverity() == IStatus.ERROR)
229:                            return status.getMessage();
230:
231:                        IJavaElement parent = pack.getParent();
232:                        try {
233:                            if (parent instanceof  IPackageFragmentRoot) {
234:                                if (!RenamePackageProcessor
235:                                        .isPackageNameOkInRoot(newText,
236:                                                (IPackageFragmentRoot) parent))
237:                                    return ReorgMessages.ReorgQueries_packagewithThatNameexistsMassage;
238:                            }
239:                        } catch (CoreException e) {
240:                            return INVALID_NAME_NO_MESSAGE;
241:                        }
242:                        if (pack.getElementName().equalsIgnoreCase(newText))
243:                            return ReorgMessages.ReorgQueries_resourceExistsWithDifferentCaseMassage;
244:
245:                        return null;
246:                    }
247:                };
248:                return validator;
249:            }
250:        }
w_ww_._j___a___va2___s___.co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.