KickJava   Java API By Example, From Geeks To Geeks.

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


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
15 import org.eclipse.core.resources.IFile;
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.jdt.core.IJavaElement;
20 import org.eclipse.jdt.core.IJavaProject;
21 import org.eclipse.jdt.core.IPackageFragment;
22 import org.eclipse.jdt.core.IType;
23 import org.eclipse.ltk.core.refactoring.Change;
24 import org.eclipse.ltk.core.refactoring.CompositeChange;
25 import org.eclipse.pde.internal.core.WorkspaceModelManager;
26 import org.eclipse.pde.internal.ui.PDEUIMessages;
27
28 public class ManifestTypeMoveParticipant extends PDEMoveParticipant {
29
30     protected boolean initialize(Object JavaDoc element) {
31         if (element instanceof IType) {
32             IType type = (IType) element;
33             IJavaProject javaProject = (IJavaProject) type
34                     .getAncestor(IJavaElement.JAVA_PROJECT);
35             IProject project = javaProject.getProject();
36             if (WorkspaceModelManager.isPluginProject(project)) {
37                 fProject = javaProject.getProject();
38                 fElements = new HashMap JavaDoc();
39                 fElements.put(element, getNewName(getArguments().getDestination(), element));
40                 return true;
41             }
42         }
43         return false;
44     }
45
46     public String JavaDoc getName() {
47         return PDEUIMessages.ManifestTypeRenameParticipant_composite;
48     }
49     
50     protected boolean isInterestingForExtensions() {
51         Object JavaDoc dest = getArguments().getDestination();
52         if (dest instanceof IJavaElement) {
53             IJavaElement destination = (IJavaElement)dest;
54             IJavaProject jProject = (IJavaProject)destination.getAncestor(IJavaElement.JAVA_PROJECT);
55             return jProject.getProject().equals(fProject);
56         }
57         return false;
58     }
59
60     protected void addChange(CompositeChange result, String JavaDoc filename, IProgressMonitor pm)
61             throws CoreException {
62         IFile file = fProject.getFile(filename);
63         if (file.exists()) {
64             Change change = PluginManifestChange.createRenameChange(file,
65                     fElements.keySet().toArray(),
66                     getNewNames(),
67                     getTextChange(file),
68                     pm);
69             if (change != null)
70                 result.add(change);
71         }
72     }
73     
74     protected String JavaDoc getNewName(Object JavaDoc destination, Object JavaDoc element) {
75         if (destination instanceof IPackageFragment && element instanceof IJavaElement) {
76             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
77             buffer.append(((IPackageFragment)destination).getElementName());
78             if (buffer.length() > 0)
79                 buffer.append('.');
80             return buffer.append(((IJavaElement)element).getElementName()).toString();
81         }
82         return super.getNewName(destination, element);
83     }
84
85     protected void addChange(CompositeChange result, IProgressMonitor pm)
86             throws CoreException {
87         IFile file = fProject.getFile("META-INF/MANIFEST.MF"); //$NON-NLS-1$
88
if (file.exists()) {
89             Change change = BundleManifestChange.createRenameChange(
90                                         file,
91                                         fElements.keySet().toArray(),
92                                         getNewNames(),
93                                         pm);
94             if (change != null)
95                 result.add(change);
96         }
97     }
98
99 }
100
Popular Tags