KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > core > refactoring > descriptors > RenameResourceDescriptor


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.core.refactoring.descriptors;
12
13 import org.eclipse.core.runtime.Assert;
14
15 import org.eclipse.core.resources.IProject;
16 import org.eclipse.core.resources.IResource;
17
18 import org.eclipse.ltk.core.refactoring.RefactoringContribution;
19 import org.eclipse.ltk.core.refactoring.RefactoringCore;
20 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
21
22 import org.eclipse.jdt.core.refactoring.IJavaRefactorings;
23
24 import org.eclipse.jdt.internal.core.refactoring.descriptors.DescriptorMessages;
25
26 /**
27  * Refactoring descriptor for the rename resource refactoring.
28  * <p>
29  * An instance of this refactoring descriptor may be obtained by calling
30  * {@link RefactoringContribution#createDescriptor()} on a refactoring
31  * contribution requested by invoking
32  * {@link RefactoringCore#getRefactoringContribution(String)} with the
33  * appropriate refactoring id.
34  * </p>
35  * <p>
36  * Note: this class is not intended to be instantiated by clients.
37  * </p>
38  *
39  * @since 3.3
40  */

41 public final class RenameResourceDescriptor extends JavaRefactoringDescriptor {
42
43     /** The name attribute */
44     private String JavaDoc fName= null;
45
46     /** The resource attribute */
47     private IResource fResource= null;
48
49     /**
50      * Creates a new refactoring descriptor.
51      */

52     public RenameResourceDescriptor() {
53         super(IJavaRefactorings.RENAME_RESOURCE);
54     }
55
56     /**
57      * {@inheritDoc}
58      */

59     protected void populateArgumentMap() {
60         super.populateArgumentMap();
61         fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_INPUT, resourceToHandle(getProject(), fResource));
62         fArguments.put(JavaRefactoringDescriptor.ATTRIBUTE_NAME, fName);
63     }
64
65     /**
66      * Sets the new name to rename the resource to.
67      *
68      * @param name
69      * the non-empty new name to set
70      */

71     public void setNewName(final String JavaDoc name) {
72         Assert.isNotNull(name);
73         Assert.isLegal(!"".equals(name), "Name must not be empty"); //$NON-NLS-1$//$NON-NLS-2$
74
fName= name;
75     }
76
77     /**
78      * Sets the project name of this refactoring.
79      * <p>
80      * Note: If the resource to be renamed is of type {@link IResource#PROJECT},
81      * clients are required to to set the project name to <code>null</code>.
82      * </p>
83      * <p>
84      * The default is to associate the refactoring with the workspace.
85      * </p>
86      *
87      * @param project
88      * the non-empty project name to set, or <code>null</code> for
89      * the workspace
90      *
91      * @see #getProject()
92      */

93     public void setProject(final String JavaDoc project) {
94         super.setProject(project);
95     }
96
97     /**
98      * Sets the resource to be renamed.
99      * <p>
100      * Note: If the resource to be renamed is of type {@link IResource#PROJECT},
101      * clients are required to to set the project name to <code>null</code>.
102      * </p>
103      *
104      * @param resource
105      * the resource to be renamed
106      */

107     public void setResource(final IResource resource) {
108         Assert.isNotNull(resource);
109         fResource= resource;
110     }
111
112     /**
113      * {@inheritDoc}
114      */

115     public RefactoringStatus validateDescriptor() {
116         RefactoringStatus status= super.validateDescriptor();
117         if (fResource == null)
118             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_no_resource));
119         if (fName == null || "".equals(fName)) //$NON-NLS-1$
120
status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_no_new_name));
121         if (fResource instanceof IProject && getProject() != null)
122             status.merge(RefactoringStatus.createFatalErrorStatus(DescriptorMessages.RenameResourceDescriptor_project_constraint));
123         return status;
124     }
125 }
Popular Tags