KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2005 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.jdt.core.IJavaElement;
18 import org.eclipse.jdt.core.IJavaProject;
19 import org.eclipse.jdt.core.IType;
20 import org.eclipse.pde.internal.core.WorkspaceModelManager;
21 import org.eclipse.pde.internal.ui.PDEUIMessages;
22
23 public class ManifestTypeRenameParticipant extends PDERenameParticipant {
24
25     protected boolean initialize(Object JavaDoc element) {
26         if (element instanceof IType) {
27             IType type = (IType)element;
28             IJavaProject javaProject = (IJavaProject)type.getAncestor(IJavaElement.JAVA_PROJECT);
29             IProject project = javaProject.getProject();
30             if (WorkspaceModelManager.isPluginProject(project)) {
31                 fProject = javaProject.getProject();
32                 fElements = new HashMap JavaDoc();
33                 fElements.put(type, getArguments().getNewName());
34                 return true;
35             }
36         }
37         return false;
38     }
39     
40     protected String JavaDoc[] getOldNames() {
41         String JavaDoc[] result = new String JavaDoc[fElements.size()];
42         Iterator JavaDoc iter = fElements.keySet().iterator();
43         for (int i = 0; i < fElements.size(); i++)
44             result[i] = ((IType)iter.next()).getFullyQualifiedName('$');
45         return result;
46     }
47     
48     protected String JavaDoc[] getNewNames() {
49         String JavaDoc[] result = new String JavaDoc[fElements.size()];
50         Iterator JavaDoc iter = fElements.keySet().iterator();
51         for (int i = 0; i < fElements.size(); i++) {
52             IType type = (IType)iter.next();
53             String JavaDoc oldName = type.getFullyQualifiedName('$');
54             int index = oldName.lastIndexOf(type.getElementName());
55             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(oldName.substring(0, index));
56             buffer.append(fElements.get(type));
57             result[i] = buffer.toString();
58         }
59         return result;
60     }
61
62     public String JavaDoc getName() {
63         return PDEUIMessages.ManifestTypeRenameParticipant_composite;
64     }
65
66 }
67
Popular Tags