KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > refactoring > PDEMoveParticipant


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.refactoring;
12
13 import java.util.HashMap JavaDoc;
14 import java.util.Iterator JavaDoc;
15
16 import org.eclipse.core.resources.IProject;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IProgressMonitor;
19 import org.eclipse.core.runtime.OperationCanceledException;
20 import org.eclipse.ltk.core.refactoring.Change;
21 import org.eclipse.ltk.core.refactoring.CompositeChange;
22 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
23 import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
24 import org.eclipse.ltk.core.refactoring.participants.ISharableParticipant;
25 import org.eclipse.ltk.core.refactoring.participants.MoveArguments;
26 import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
27 import org.eclipse.ltk.core.refactoring.participants.RefactoringArguments;
28
29 public abstract class PDEMoveParticipant extends MoveParticipant implements ISharableParticipant {
30
31     protected IProject fProject;
32     protected HashMap JavaDoc fElements;
33
34     public RefactoringStatus checkConditions(IProgressMonitor pm,
35             CheckConditionsContext context) throws OperationCanceledException {
36         return new RefactoringStatus();
37     }
38     
39     public void addElement(Object JavaDoc element, RefactoringArguments arguments) {
40         Object JavaDoc destination = ((MoveArguments)arguments).getDestination();
41         fElements.put(element, getNewName(destination, element));
42     }
43
44     public Change createChange(IProgressMonitor pm) throws CoreException,
45             OperationCanceledException {
46         CompositeChange result = new CompositeChange(getName());
47         addChange(result, pm);
48         if (isInterestingForExtensions()) {
49             addChange(result, "plugin.xml", pm); //$NON-NLS-1$
50
addChange(result, "fragment.xml", pm); //$NON-NLS-1$
51
}
52         return (result.getChildren().length == 0) ? null : result;
53     }
54     
55     protected abstract boolean isInterestingForExtensions();
56     
57     protected void addChange(CompositeChange result, String JavaDoc filename, IProgressMonitor pm)
58         throws CoreException {
59     }
60     
61     // add main change (whether to Manifest or build.properties)
62
protected void addChange(CompositeChange result, IProgressMonitor pm)
63         throws CoreException {
64     }
65     
66     protected String JavaDoc getNewName(Object JavaDoc destination, Object JavaDoc element) {
67         return element.toString();
68     }
69     
70     protected String JavaDoc[] getNewNames() {
71         String JavaDoc[] result = new String JavaDoc[fElements.size()];
72         Iterator JavaDoc iter = fElements.values().iterator();
73         for (int i = 0; i < fElements.size(); i++)
74             result[i] = iter.next().toString();
75         return result;
76     }
77
78 }
79
Popular Tags