Source Code Cross Referenced for JavaCopyProcessor.java in  » IDE-Eclipse » jdt » org » eclipse » jdt » internal » corext » 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.corext.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.corext.refactoring.reorg;
011:
012:        import java.util.ArrayList;
013:        import java.util.Arrays;
014:        import java.util.HashSet;
015:        import java.util.List;
016:        import java.util.Set;
017:
018:        import org.eclipse.core.runtime.Assert;
019:        import org.eclipse.core.runtime.CoreException;
020:        import org.eclipse.core.runtime.IProgressMonitor;
021:        import org.eclipse.core.runtime.OperationCanceledException;
022:        import org.eclipse.core.runtime.SubProgressMonitor;
023:
024:        import org.eclipse.core.resources.IResource;
025:
026:        import org.eclipse.ltk.core.refactoring.Change;
027:        import org.eclipse.ltk.core.refactoring.ChangeDescriptor;
028:        import org.eclipse.ltk.core.refactoring.CompositeChange;
029:        import org.eclipse.ltk.core.refactoring.RefactoringStatus;
030:        import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
031:        import org.eclipse.ltk.core.refactoring.participants.CopyProcessor;
032:        import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments;
033:        import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
034:        import org.eclipse.ltk.core.refactoring.participants.ReorgExecutionLog;
035:        import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
036:
037:        import org.eclipse.jdt.core.IJavaElement;
038:        import org.eclipse.jdt.core.JavaModelException;
039:
040:        import org.eclipse.jdt.internal.corext.refactoring.JavaRefactoringArguments;
041:        import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
042:        import org.eclipse.jdt.internal.corext.refactoring.changes.DynamicValidationStateChange;
043:        import org.eclipse.jdt.internal.corext.refactoring.participants.JavaProcessors;
044:        import org.eclipse.jdt.internal.corext.refactoring.participants.ResourceProcessors;
045:        import org.eclipse.jdt.internal.corext.refactoring.reorg.IReorgPolicy.ICopyPolicy;
046:        import org.eclipse.jdt.internal.corext.refactoring.tagging.ICommentProvider;
047:        import org.eclipse.jdt.internal.corext.refactoring.tagging.IScriptableRefactoring;
048:        import org.eclipse.jdt.internal.corext.util.Resources;
049:
050:        import org.eclipse.jdt.ui.refactoring.IRefactoringProcessorIds;
051:
052:        public final class JavaCopyProcessor extends CopyProcessor implements 
053:                IReorgDestinationValidator, IScriptableRefactoring,
054:                ICommentProvider {
055:
056:            private String fComment;
057:
058:            private ICopyPolicy fCopyPolicy;
059:
060:            private ReorgExecutionLog fExecutionLog;
061:
062:            private INewNameQueries fNewNameQueries;
063:
064:            private IReorgQueries fReorgQueries;
065:
066:            public JavaCopyProcessor(ICopyPolicy copyPolicy) {
067:                fCopyPolicy = copyPolicy;
068:            }
069:
070:            public boolean canChildrenBeDestinations(
071:                    IReorgDestination destination) {
072:                return fCopyPolicy.canChildrenBeDestinations(destination);
073:            }
074:
075:            public boolean canElementBeDestination(IReorgDestination destination) {
076:                return fCopyPolicy.canElementBeDestination(destination);
077:            }
078:
079:            public boolean canEnableComment() {
080:                return true;
081:            }
082:
083:            public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
084:                    CheckConditionsContext context) throws CoreException {
085:                Assert.isNotNull(fNewNameQueries, "Missing new name queries"); //$NON-NLS-1$
086:                Assert.isNotNull(fReorgQueries, "Missing reorg queries"); //$NON-NLS-1$
087:                pm.beginTask("", 2); //$NON-NLS-1$
088:                RefactoringStatus result = fCopyPolicy.checkFinalConditions(
089:                        new SubProgressMonitor(pm, 1), context, fReorgQueries);
090:                result.merge(context.check(new SubProgressMonitor(pm, 1)));
091:                return result;
092:            }
093:
094:            public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
095:                    throws CoreException {
096:                RefactoringStatus result = new RefactoringStatus();
097:                result.merge(RefactoringStatus.create(Resources
098:                        .checkInSync(ReorgUtils.getNotNulls(fCopyPolicy
099:                                .getResources()))));
100:                IResource[] javaResources = ReorgUtils.getResources(fCopyPolicy
101:                        .getJavaElements());
102:                result.merge(RefactoringStatus.create(Resources
103:                        .checkInSync(ReorgUtils.getNotNulls(javaResources))));
104:                return result;
105:            }
106:
107:            public Change createChange(IProgressMonitor pm)
108:                    throws CoreException {
109:                Assert.isNotNull(fNewNameQueries);
110:                Assert.isTrue(fCopyPolicy.getJavaElementDestination() == null
111:                        || fCopyPolicy.getResourceDestination() == null);
112:                Assert.isTrue(fCopyPolicy.getJavaElementDestination() != null
113:                        || fCopyPolicy.getResourceDestination() != null);
114:                try {
115:                    final DynamicValidationStateChange result = new DynamicValidationStateChange(
116:                            getChangeName()) {
117:
118:                        public Object getAdapter(Class adapter) {
119:                            if (ReorgExecutionLog.class.equals(adapter))
120:                                return fExecutionLog;
121:                            return super .getAdapter(adapter);
122:                        }
123:
124:                        public ChangeDescriptor getDescriptor() {
125:                            return fCopyPolicy.getDescriptor();
126:                        }
127:
128:                        public Change perform(IProgressMonitor pm2)
129:                                throws CoreException {
130:                            try {
131:                                super .perform(pm2);
132:                            } catch (OperationCanceledException e) {
133:                                fExecutionLog.markAsCanceled();
134:                                throw e;
135:                            }
136:                            return null;
137:                        }
138:                    };
139:                    Change change = fCopyPolicy.createChange(pm,
140:                            new MonitoringNewNameQueries(fNewNameQueries,
141:                                    fExecutionLog));
142:                    if (change instanceof  CompositeChange) {
143:                        CompositeChange subComposite = (CompositeChange) change;
144:                        result.merge(subComposite);
145:                    } else {
146:                        result.add(change);
147:                    }
148:                    return result;
149:                } finally {
150:                    pm.done();
151:                }
152:            }
153:
154:            private String[] getAffectedProjectNatures() throws CoreException {
155:                String[] jNatures = JavaProcessors
156:                        .computeAffectedNaturs(fCopyPolicy.getJavaElements());
157:                String[] rNatures = ResourceProcessors
158:                        .computeAffectedNatures(fCopyPolicy.getResources());
159:                Set result = new HashSet();
160:                result.addAll(Arrays.asList(jNatures));
161:                result.addAll(Arrays.asList(rNatures));
162:                return (String[]) result.toArray(new String[result.size()]);
163:            }
164:
165:            private String getChangeName() {
166:                return RefactoringCoreMessages.JavaCopyProcessor_changeName;
167:            }
168:
169:            public String getComment() {
170:                return fComment;
171:            }
172:
173:            public Object getCommonParentForInputElements() {
174:                return new ParentChecker(fCopyPolicy.getResources(),
175:                        fCopyPolicy.getJavaElements()).getCommonParent();
176:            }
177:
178:            public Object[] getElements() {
179:                IJavaElement[] jElements = fCopyPolicy.getJavaElements();
180:                IResource[] resources = fCopyPolicy.getResources();
181:                List result = new ArrayList(jElements.length + resources.length);
182:                result.addAll(Arrays.asList(jElements));
183:                result.addAll(Arrays.asList(resources));
184:                return result.toArray();
185:            }
186:
187:            public String getIdentifier() {
188:                return IRefactoringProcessorIds.COPY_PROCESSOR;
189:            }
190:
191:            public IJavaElement[] getJavaElements() {
192:                return fCopyPolicy.getJavaElements();
193:            }
194:
195:            public String getProcessorName() {
196:                return RefactoringCoreMessages.JavaCopyProcessor_processorName;
197:            }
198:
199:            public IResource[] getResources() {
200:                return fCopyPolicy.getResources();
201:            }
202:
203:            public RefactoringStatus initialize(RefactoringArguments arguments) {
204:                setReorgQueries(new NullReorgQueries());
205:                final RefactoringStatus status = new RefactoringStatus();
206:                if (arguments instanceof  JavaRefactoringArguments) {
207:                    final JavaRefactoringArguments extended = (JavaRefactoringArguments) arguments;
208:                    fCopyPolicy = ReorgPolicyFactory.createCopyPolicy(status,
209:                            extended);
210:                    if (fCopyPolicy != null && !status.hasFatalError()) {
211:                        status.merge(fCopyPolicy.initialize(arguments));
212:                        if (!status.hasFatalError()) {
213:                            final ReorgExecutionLog log = ReorgPolicyFactory
214:                                    .loadReorgExecutionLog(extended);
215:                            if (log != null && !status.hasFatalError())
216:                                setNewNameQueries(new LoggedNewNameQueries(log));
217:                        }
218:                    }
219:                } else
220:                    return RefactoringStatus
221:                            .createFatalErrorStatus(RefactoringCoreMessages.InitializableRefactoring_inacceptable_arguments);
222:                return status;
223:            }
224:
225:            public boolean isApplicable() throws CoreException {
226:                return fCopyPolicy.canEnable();
227:            }
228:
229:            public RefactoringParticipant[] loadParticipants(
230:                    RefactoringStatus status,
231:                    SharableParticipants sharedParticipants)
232:                    throws CoreException {
233:                RefactoringParticipant[] result = fCopyPolicy.loadParticipants(
234:                        status, this , getAffectedProjectNatures(),
235:                        sharedParticipants);
236:                fExecutionLog = fCopyPolicy.getReorgExecutionLog();
237:                return result;
238:            }
239:
240:            public void setComment(String comment) {
241:                fComment = comment;
242:            }
243:
244:            public RefactoringStatus setDestination(
245:                    IReorgDestination destination) throws JavaModelException {
246:                fCopyPolicy.setDestination(destination);
247:                return fCopyPolicy.verifyDestination(destination);
248:            }
249:
250:            public void setNewNameQueries(INewNameQueries newNameQueries) {
251:                Assert.isNotNull(newNameQueries);
252:                fNewNameQueries = newNameQueries;
253:            }
254:
255:            public void setReorgQueries(IReorgQueries queries) {
256:                Assert.isNotNull(queries);
257:                fReorgQueries = queries;
258:            }
259:
260:            public int getSaveMode() {
261:                return fCopyPolicy.getSaveMode();
262:            }
263:        }
www.jav___a___2___s___.___co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.