01: /*******************************************************************************
02: * Copyright (c) 2005, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.pde.internal.ui.refactoring;
11:
12: import java.util.HashMap;
13: import java.util.Iterator;
14:
15: import org.eclipse.core.resources.IProject;
16: import org.eclipse.core.runtime.CoreException;
17: import org.eclipse.core.runtime.IProgressMonitor;
18: import org.eclipse.core.runtime.OperationCanceledException;
19: import org.eclipse.ltk.core.refactoring.Change;
20: import org.eclipse.ltk.core.refactoring.CompositeChange;
21: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
22: import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
23: import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant;
24: import org.eclipse.ltk.core.refactoring.participants.MoveArguments;
25: import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
26: import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments;
27:
28: public abstract class PDEMoveParticipant extends MoveParticipant
29: implements ISharableParticipant {
30:
31: protected IProject fProject;
32: protected HashMap fElements;
33:
34: public RefactoringStatus checkConditions(IProgressMonitor pm,
35: CheckConditionsContext context)
36: throws OperationCanceledException {
37: return new RefactoringStatus();
38: }
39:
40: public void addElement(Object element,
41: RefactoringArguments arguments) {
42: Object destination = ((MoveArguments) arguments)
43: .getDestination();
44: fElements.put(element, getNewName(destination, element));
45: }
46:
47: public Change createChange(IProgressMonitor pm)
48: throws CoreException, OperationCanceledException {
49: CompositeChange result = new CompositeChange(getName());
50: addChange(result, pm);
51: if (isInterestingForExtensions()) {
52: addChange(result, "plugin.xml", pm); //$NON-NLS-1$
53: addChange(result, "fragment.xml", pm); //$NON-NLS-1$
54: }
55: return (result.getChildren().length == 0) ? null : result;
56: }
57:
58: protected abstract boolean isInterestingForExtensions();
59:
60: protected void addChange(CompositeChange result, String filename,
61: IProgressMonitor pm) throws CoreException {
62: }
63:
64: // add main change (whether to Manifest or build.properties)
65: protected void addChange(CompositeChange result, IProgressMonitor pm)
66: throws CoreException {
67: }
68:
69: protected String getNewName(Object destination, Object element) {
70: return element.toString();
71: }
72:
73: protected String[] getNewNames() {
74: String[] result = new String[fElements.size()];
75: Iterator iter = fElements.values().iterator();
76: for (int i = 0; i < fElements.size(); i++)
77: result[i] = iter.next().toString();
78: return result;
79: }
80:
81: }
|