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