Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: 414564b9ce0d4ccde12b6daa0547c96333d30cb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*******************************************************************************
 * Copyright (c) 2000, 2004 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 *******************************************************************************/
package org.eclipse.wst.xsd.ui.internal.refactor.structure;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
import org.eclipse.ltk.core.refactoring.participants.ParticipantManager;
import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
import org.eclipse.ltk.core.refactoring.participants.RenameProcessor;
import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
import org.eclipse.wst.xsd.ui.internal.refactor.INameUpdating;
import org.eclipse.wst.xsd.ui.internal.refactor.RefactoringMessages;
import org.eclipse.xsd.XSDTypeDefinition;

public class MakeTypeGlobalProcessor extends RenameProcessor implements INameUpdating{
	
	private XSDTypeDefinition fTypeComponent;
	private String fNewElementName;

	public static final String IDENTIFIER= "org.eclipse.wst.ui.xsd.makeTypeGlobalProcessor"; //$NON-NLS-1$

	//private QualifiedNameSearchResult fNameSearchResult;
	
	public MakeTypeGlobalProcessor(XSDTypeDefinition element, String newName) {
		fTypeComponent= element;
		fNewElementName = newName;
		
	}
	
	public XSDTypeDefinition getTypeComponent() {
		return fTypeComponent;
	}

	
	
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.ITextUpdating#canEnableTextUpdating()
	 */
	public boolean canEnableTextUpdating() {
		return true;
	}

	protected String[] getAffectedProjectNatures() throws CoreException {
		//TODO: find project natures of the files that are going to be refactored
		return new String[0];
	}
	
	protected void loadDerivedParticipants(RefactoringStatus status,
			List result, String[] natures, SharableParticipants shared)
			throws CoreException {
		// TODO: provide a way to load rename participants
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkFinalConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
	 */
	public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
			CheckConditionsContext context) throws CoreException,
			OperationCanceledException {
		// TODO add code to check final conditions for component rename
		return new RefactoringStatus();
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#checkInitialConditions(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
			throws CoreException, OperationCanceledException {
//		 TODO add code to check initial conditions for component rename
		return new RefactoringStatus();
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#createChange(org.eclipse.core.runtime.IProgressMonitor)
	 */
	public Change createChange(IProgressMonitor pm) throws CoreException,
			OperationCanceledException {
		// TODO P1 add change creation
//		Change[] changes = XSDComponentRenameChange.createChangesFor(this.fNamedComponent, getNewElementName());
//		CompositeChange multiChange = null; 
//			if(changes.length > 0)
//				multiChange  = new CompositeChange("XSD component rename participant changes", changes); //$NON-NLS-1$ TODO: externalize string
//		return multiChange;
		
//		computeNameMatches(pm);	
//		Change[] changes = fNameSearchResult.getAllChanges();
//		return new CompositeChange("XSD file rename participant changes", changes); //TODO: externalize string
		pm.beginTask("", 1); //$NON-NLS-1$
		try{
			return new MakeTypeGlobalChange(fTypeComponent, getNewElementName());
		} finally{
			pm.done();
		}	 
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getElements()
	 */
	public Object[] getElements() {
		
		return new Object[] {fTypeComponent};
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getIdentifier()
	 */
	public String getIdentifier() {
		return IDENTIFIER;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#getProcessorName()
	 */
	public String getProcessorName() {
		return RefactoringMessages.getFormattedString(
				"MakeLocalTypeGlobalRefactoring.name",  //$NON-NLS-1$
				new String[]{getNewElementName()});

	}
	/* (non-Javadoc)
	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor#isApplicable()
	 */
	public boolean isApplicable() throws CoreException {
		if (fTypeComponent == null)
			return false;
		// TODO implement isApplicable logic for the named component, 
		// verify how it is different from other condition checks
//		if (fNamedComponent.isAnonymous())
//			return false;
//		if (! Checks.isAvailable(fType))
//			return false;
//		if (isSpecialCase(fType))
//			return false;
		return true;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#checkNewElementName(java.lang.String)
	 */
	public RefactoringStatus checkNewElementName(String newName){
		Assert.isNotNull(newName, "new name"); //$NON-NLS-1$
		// TODO: implement new name checking
//		RefactoringStatus result = Checks.checkTypeName(newName);
//		if (Checks.isAlreadyNamed(fType, newName))
//			result.addFatalError(RefactoringCoreMessages.getString("RenameTypeRefactoring.choose_another_name"));	 //$NON-NLS-1$
		return new RefactoringStatus();
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jdt.internal.corext.refactoring.tagging.INameUpdating#getNewElement()
	 */
	public Object getNewElement() throws CoreException {
		// TODO implement this method, it's used for updating selection on new element
		return null;
	}
	
//	private void computeNameMatches(IProgressMonitor pm) throws CoreException {
//	
//	    IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
//	    try {
//			URL fileURL = Platform.resolve(new URL(fNamedComponent.getSchema().getSchemaLocation()));
//			IFile file = workspaceRoot.getFileForLocation(new Path(fileURL.getPath()));
//			if (fNameSearchResult == null)
//				fNameSearchResult= new QualifiedNameSearchResult();
//			QualifiedNameFinder.process(fNameSearchResult, getNamedComponent().getName(),  
//				getNewElementName(), 
//				"*.xsd", file.getProject(), pm);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}
	
	public final RefactoringParticipant[] loadParticipants(RefactoringStatus status, SharableParticipants sharedParticipants) throws CoreException {
		RenameArguments arguments= new RenameArguments(getNewElementName(), true);
		String[] natures= getAffectedProjectNatures();
		List result= new ArrayList();
		loadElementParticipants(status, result, arguments, natures, sharedParticipants);
		loadDerivedParticipants(status, result, natures, sharedParticipants);
		return (RefactoringParticipant[])result.toArray(new RefactoringParticipant[result.size()]);
	}
	
	protected void loadElementParticipants(RefactoringStatus status, List result, RenameArguments arguments, String[] natures, SharableParticipants shared) throws CoreException {
		Object[] elements= getElements();
		for (int i= 0; i < elements.length; i++) {
			result.addAll(Arrays.asList(ParticipantManager.loadRenameParticipants(status, 
				this,  elements[i],
				arguments, natures, shared)));
		}
	}
	
	
	public void setNewElementName(String newName) {
		
		fNewElementName= newName;
	}

	public String getNewElementName() {
		return fNewElementName;
	}

	public String getCurrentElementName() {
		// TODO Auto-generated method stub
		return fNewElementName;
	}
	
	
}

Back to the top