blob: 1382c96e560581c15d7bed1f8314bc30cc78c14f [file] [log] [blame]
csaltere2ddc8f2005-02-23 14:53:42 +00001/*******************************************************************************
csalterce820002006-01-10 07:53:46 +00002 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
csaltere2ddc8f2005-02-23 14:53:42 +00005 * which accompanies this distribution, and is available at
csalterce820002006-01-10 07:53:46 +00006 * http://www.eclipse.org/legal/cpl-v10.html
csaltere2ddc8f2005-02-23 14:53:42 +00007 *
8 * Contributors:
csalterce820002006-01-10 07:53:46 +00009 * IBM Corporation - initial API and implementation
csaltere2ddc8f2005-02-23 14:53:42 +000010 *******************************************************************************/
11package org.eclipse.wst.xsd.ui.internal.refactor.structure;
12
13
14import java.util.ArrayList;
15import java.util.Arrays;
16import java.util.List;
csalterce820002006-01-10 07:53:46 +000017import org.eclipse.core.internal.utils.Assert;
csaltere2ddc8f2005-02-23 14:53:42 +000018import org.eclipse.core.runtime.CoreException;
19import org.eclipse.core.runtime.IProgressMonitor;
20import org.eclipse.core.runtime.OperationCanceledException;
csaltere2ddc8f2005-02-23 14:53:42 +000021import org.eclipse.ltk.core.refactoring.Change;
22import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
24import org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
25import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
26import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
27import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
28import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
csalterce820002006-01-10 07:53:46 +000029import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating;
csaltere2ddc8f2005-02-23 14:53:42 +000030import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages;
csaltere2ddc8f2005-02-23 14:53:42 +000031import org.eclipse.xsd.XSDTypeDefinition;
32
33public class MakeTypeGlobalProcessor extends RenameProcessor implements INameUpdating{
34
35 private XSDTypeDefinition fTypeComponent;
36 private String fNewElementName;
37
38 public static final String IDENTIFIER= "org.eclipse.wst.ui.xsd.makeTypeGlobalProcessor"; //$NON-NLS-1$
39
40 //private QualifiedNameSearchResult fNameSearchResult;
41
42 public MakeTypeGlobalProcessor(XSDTypeDefinition element, String newName) {
43 fTypeComponent= element;
44 fNewElementName = newName;
45
46 }
47
48 public XSDTypeDefinition getTypeComponent() {
49 return fTypeComponent;
50 }
51
52
53
54 /* (non-Javadoc)
55 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating()
56 */
57 public boolean canEnableTextUpdating() {
58 return true;
59 }
david_williams47a33d22005-05-28 01:26:57 +000060
csaltere2ddc8f2005-02-23 14:53:42 +000061 protected String[] getAffectedProjectNatures() throws CoreException {
62 //TODO: find project natures of the files that are going to be refactored
63 return new String[0];
64 }
65
csaltere2ddc8f2005-02-23 14:53:42 +000066 protected void loadDerivedParticipants(RefactoringStatus status,
67 List result, String[] natures, SharableParticipants shared)
68 throws CoreException {
69 // TODO: provide a way to load rename participants
70 }
71 /* (non-Javadoc)
72 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
73 */
74 public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
75 CheckConditionsContext context) throws CoreException,
76 OperationCanceledException {
77 // TODO add code to check final conditions for component rename
78 return new RefactoringStatus();
79 }
80 /* (non-Javadoc)
81 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
82 */
83 public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
84 throws CoreException, OperationCanceledException {
85// TODO add code to check initial conditions for component rename
86 return new RefactoringStatus();
87 }
88 /* (non-Javadoc)
89 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
90 */
91 public Change createChange(IProgressMonitor pm) throws CoreException,
92 OperationCanceledException {
93 // TODO P1 add change creation
94// Change[] changes = XSDComponentRenameChange.createChangesFor(this.fNamedComponent, getNewElementName());
95// CompositeChange multiChange = null;
96// if(changes.length > 0)
97// multiChange = new CompositeChange("XSD component rename participant changes", changes); //$NON-NLS-1$ TODO: externalize string
98// return multiChange;
99
100// computeNameMatches(pm);
101// Change[] changes = fNameSearchResult.getAllChanges();
102// return new CompositeChange("XSD file rename participant changes", changes); //TODO: externalize string
103 pm.beginTask("", 1); //$NON-NLS-1$
104 try{
105 return new MakeTypeGlobalChange(fTypeComponent, getNewElementName());
106 } finally{
107 pm.done();
108 }
109 }
110 /* (non-Javadoc)
111 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
112 */
113 public Object[] getElements() {
114
115 return new Object[] {fTypeComponent};
116 }
117 /* (non-Javadoc)
118 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
119 */
120 public String getIdentifier() {
121 return IDENTIFIER;
122 }
123 /* (non-Javadoc)
124 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
125 */
126 public String getProcessorName() {
127 return RefactoringMessages.getFormattedString(
128 "MakeLocalTypeGlobalRefactoring.name", //$NON-NLS-1$
129 new String[]{getNewElementName()});
130
131 }
132 /* (non-Javadoc)
133 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
134 */
135 public boolean isApplicable() throws CoreException {
136 if (fTypeComponent == null)
137 return false;
138 // TODO implement isApplicable logic for the named component,
139 // verify how it is different from other condition checks
140// if (fNamedComponent.isAnonymous())
141// return false;
142// if (! Checks.isAvailable(fType))
143// return false;
144// if (isSpecialCase(fType))
145// return false;
146 return true;
147 }
148 /* (non-Javadoc)
149 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#checkNewElementName(java.lang.String)
150 */
151 public RefactoringStatus checkNewElementName(String newName){
152 Assert.isNotNull(newName, "new name"); //$NON-NLS-1$
153 // TODO: implement new name checking
154// RefactoringStatus result = Checks.checkTypeName(newName);
155// if (Checks.isAlreadyNamed(fType, newName))
156// result.addFatalError(RefactoringCoreMessages.getString("RenameTypeRefactoring.choose_another_name")); //$NON-NLS-1$
157 return new RefactoringStatus();
158 }
159 /* (non-Javadoc)
160 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#getNewElement()
161 */
162 public Object getNewElement() throws CoreException {
163 // TODO implement this method, it's used for updating selection on new element
164 return null;
165 }
166
167// private void computeNameMatches(IProgressMonitor pm) throws CoreException {
168//
169// IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
170// try {
171// URL fileURL = Platform.resolve(new URL(fNamedComponent.getSchema().getSchemaLocation()));
172// IFile file = workspaceRoot.getFileForLocation(new Path(fileURL.getPath()));
173// if (fNameSearchResult == null)
174// fNameSearchResult= new QualifiedNameSearchResult();
175// QualifiedNameFinder.process(fNameSearchResult, getNamedComponent().getName(),
176// getNewElementName(),
177// "*.xsd", file.getProject(), pm);
178// } catch (IOException e) {
179// // TODO Auto-generated catch block
180// e.printStackTrace();
181// }
182// }
183
184 public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException {
185 RenameArguments arguments= new RenameArguments(getNewElementName(), true);
186 String[] natures= getAffectedProjectNatures();
187 List result= new ArrayList();
188 loadElementParticipants(status, result, arguments, natures, sharedParticipants);
189 loadDerivedParticipants(status, result, natures, sharedParticipants);
190 return (RefactoringParticipant[])result.toArray(new RefactoringParticipant[result.size()]);
191 }
192
193 protected void loadElementParticipants(RefactoringStatus status, List result, RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException {
194 Object[] elements= getElements();
195 for (int i= 0; i < elements.length; i++) {
196 result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status,
197 this, elements[i],
198 arguments, natures, shared)));
199 }
200 }
201
202
203 public void setNewElementName(String newName) {
204
205 fNewElementName= newName;
206 }
207
208 public String getNewElementName() {
209 return fNewElementName;
210 }
211
212 public String getCurrentElementName() {
213 // TODO Auto-generated method stub
214 return fNewElementName;
215 }
216
217
218}