KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.eclipse.pde.internal.ui.refactoring;
2
3 import java.util.HashMap JavaDoc;
4
5 import org.eclipse.core.resources.IContainer;
6 import org.eclipse.core.resources.IFile;
7 import org.eclipse.core.resources.IProject;
8 import org.eclipse.core.resources.IResource;
9 import org.eclipse.core.runtime.CoreException;
10 import org.eclipse.core.runtime.IProgressMonitor;
11 import org.eclipse.ltk.core.refactoring.Change;
12 import org.eclipse.ltk.core.refactoring.CompositeChange;
13 /*******************************************************************************
14  * Copyright (c) 2006 IBM Corporation and others.
15  * All rights reserved. This program and the accompanying materials
16  * are made available under the terms of the Eclipse Public License v1.0
17  * which accompanies this distribution, and is available at
18  * http://www.eclipse.org/legal/epl-v10.html
19  *
20  * Contributors:
21  * IBM Corporation - initial API and implementation
22  *******************************************************************************/

23 import org.eclipse.pde.internal.core.WorkspaceModelManager;
24
25 public abstract class ResourceMoveParticipant extends PDEMoveParticipant {
26
27     protected boolean isInterestingForExtensions() {
28         return true;
29     }
30     
31     protected boolean initialize(Object JavaDoc element) {
32         if (element instanceof IResource) {
33             IProject project = ((IResource) element).getProject();
34             if (WorkspaceModelManager.isPluginProject(project)) {
35                 fProject = project;
36                 fElements = new HashMap JavaDoc();
37                 fElements.put(element, getNewName(getArguments().getDestination(), element));
38                 return true;
39             }
40         }
41         return false;
42     }
43
44     protected void addChange(CompositeChange result, String JavaDoc filename, IProgressMonitor pm)
45     throws CoreException {
46         IFile file = fProject.getFile(filename);
47         if (file.exists()) {
48             Change change = PluginManifestChange.createRenameChange(file,
49                     fElements.keySet().toArray(),
50                     getNewNames(),
51                     getTextChange(file),
52                     pm);
53             if (change != null)
54                 result.add(change);
55         }
56     }
57     
58     protected String JavaDoc getNewName(Object JavaDoc destination, Object JavaDoc element) {
59         if (destination instanceof IContainer && element instanceof IResource) {
60             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
61             buffer.append(((IContainer)destination).getProjectRelativePath().toString());
62             if (buffer.length() > 0)
63                 buffer.append('/');
64             return buffer.append(((IResource)element).getName()).toString();
65         }
66         return super.getNewName(destination, element);
67     }
68     
69     protected void addChange(CompositeChange result, IProgressMonitor pm)
70     throws CoreException {
71         IFile file = fProject.getFile("build.properties"); //$NON-NLS-1$
72
if (file.exists()) {
73             Change change = BuildPropertiesChange.createRenameChange(
74                     file,
75                     fElements.keySet().toArray(),
76                     getNewNames(),
77                     pm);
78             if (change != null)
79                 result.add(change);
80         }
81     }
82
83 }
84
Popular Tags