01: /*******************************************************************************
02: * Copyright (c) 2005, 2007 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:
14: import org.eclipse.core.resources.IFile;
15: import org.eclipse.core.resources.IProject;
16: import org.eclipse.core.resources.IResource;
17: import org.eclipse.core.runtime.CoreException;
18: import org.eclipse.core.runtime.IAdaptable;
19: import org.eclipse.core.runtime.IProgressMonitor;
20: import org.eclipse.jdt.core.IJavaElement;
21: import org.eclipse.jdt.core.IJavaProject;
22: import org.eclipse.jdt.core.IPackageFragment;
23: import org.eclipse.ltk.core.refactoring.Change;
24: import org.eclipse.ltk.core.refactoring.CompositeChange;
25: import org.eclipse.pde.internal.core.ICoreConstants;
26: import org.eclipse.pde.internal.ui.PDEUIMessages;
27:
28: public class ManifestPackageMoveParticipant extends PDEMoveParticipant {
29:
30: protected boolean initialize(Object element) {
31: if (element instanceof IPackageFragment) {
32: IPackageFragment fragment = (IPackageFragment) element;
33: IJavaProject javaProject = (IJavaProject) fragment
34: .getAncestor(IJavaElement.JAVA_PROJECT);
35: IProject project = javaProject.getProject();
36: if (project.exists(ICoreConstants.MANIFEST_PATH)) {
37: fProject = javaProject.getProject();
38: fElements = new HashMap();
39: fElements.put(fragment, getNewName(getArguments()
40: .getDestination(), element));
41: return true;
42: }
43: }
44: return false;
45: }
46:
47: public String getName() {
48: return PDEUIMessages.ManifestPackageRenameParticipant_packageRename;
49: }
50:
51: protected void addChange(CompositeChange result, IProgressMonitor pm)
52: throws CoreException {
53: IFile file = fProject.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
54: if (file.exists()) {
55: IProject destProject = getDestinationProject();
56: if (destProject != null && !fProject.equals(destProject)) {
57: MoveFromChange change = BundleManifestChange
58: .createMovePackageChange(file, fElements
59: .keySet().toArray(), pm);
60: if (change != null) {
61: result.add(change);
62: IFile dest = destProject
63: .getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
64: if (dest.exists()) {
65: Change second = BundleManifestChange
66: .createMoveToPackageChange(dest,
67: change, pm);
68: if (second != null)
69: result.add(second);
70: }
71: }
72: }
73: }
74: }
75:
76: private IProject getDestinationProject() {
77: Object dest = getArguments().getDestination();
78: if (dest instanceof IAdaptable) {
79: IResource resource = (IResource) ((IAdaptable) dest)
80: .getAdapter(IResource.class);
81: if (resource != null)
82: return resource.getProject();
83: }
84: return null;
85: }
86:
87: protected boolean isInterestingForExtensions() {
88: return false;
89: }
90:
91: }
|