01: package org.eclipse.pde.internal.ui.refactoring;
02:
03: import java.util.HashMap;
04:
05: import org.eclipse.core.resources.IContainer;
06: import org.eclipse.core.resources.IFile;
07: import org.eclipse.core.resources.IProject;
08: import org.eclipse.core.resources.IResource;
09: import org.eclipse.core.runtime.CoreException;
10: import org.eclipse.core.runtime.IProgressMonitor;
11: import org.eclipse.ltk.core.refactoring.Change;
12: import org.eclipse.ltk.core.refactoring.CompositeChange;
13: /*******************************************************************************
14: * Copyright (c) 2006 IBM Corporation and others.
15: * All rights reserved. This program and the accompanying materials
16: * are made available under the terms of the Eclipse Public License v1.0
17: * which accompanies this distribution, and is available at
18: * http://www.eclipse.org/legal/epl-v10.html
19: *
20: * Contributors:
21: * IBM Corporation - initial API and implementation
22: *******************************************************************************/
23: import org.eclipse.pde.internal.core.WorkspaceModelManager;
24:
25: public abstract class ResourceMoveParticipant extends
26: PDEMoveParticipant {
27:
28: protected boolean isInterestingForExtensions() {
29: return true;
30: }
31:
32: protected boolean initialize(Object element) {
33: if (element instanceof IResource) {
34: IProject project = ((IResource) element).getProject();
35: if (WorkspaceModelManager.isPluginProject(project)) {
36: fProject = project;
37: fElements = new HashMap();
38: fElements.put(element, getNewName(getArguments()
39: .getDestination(), element));
40: return true;
41: }
42: }
43: return false;
44: }
45:
46: protected void addChange(CompositeChange result, String filename,
47: IProgressMonitor pm) throws CoreException {
48: IFile file = fProject.getFile(filename);
49: if (file.exists()) {
50: Change change = PluginManifestChange.createRenameChange(
51: file, fElements.keySet().toArray(), getNewNames(),
52: getTextChange(file), pm);
53: if (change != null)
54: result.add(change);
55: }
56: }
57:
58: protected String getNewName(Object destination, Object element) {
59: if (destination instanceof IContainer
60: && element instanceof IResource) {
61: StringBuffer buffer = new StringBuffer();
62: buffer.append(((IContainer) destination)
63: .getProjectRelativePath().toString());
64: if (buffer.length() > 0)
65: buffer.append('/');
66: return buffer.append(((IResource) element).getName())
67: .toString();
68: }
69: return super .getNewName(destination, element);
70: }
71:
72: protected void addChange(CompositeChange result, IProgressMonitor pm)
73: throws CoreException {
74: IFile file = fProject.getFile("build.properties"); //$NON-NLS-1$
75: if (file.exists()) {
76: Change change = BuildPropertiesChange.createRenameChange(
77: file, fElements.keySet().toArray(), getNewNames(),
78: pm);
79: if (change != null)
80: result.add(change);
81: }
82: }
83:
84: }
|