3m9 compatible;
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / RenameResourceElementsOperation.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
12
13 import net.sourceforge.phpdt.core.ICompilationUnit;
14 import net.sourceforge.phpdt.core.IJavaElement;
15 import net.sourceforge.phpdt.core.IJavaModelStatusConstants;
16 import net.sourceforge.phpdt.core.JavaModelException;
17 import net.sourceforge.phpdt.internal.core.util.Util;
18
19 /**
20  * This operation renames resources (Package fragments and compilation units).
21  *
22  * <p>Notes:<ul>
23  * <li>When a compilation unit is renamed, its main type and the constructors of the 
24  *              main type are renamed.
25  * </ul>
26  */
27 public class RenameResourceElementsOperation extends MoveResourceElementsOperation {
28 /**
29  * When executed, this operation will rename the specified elements with the given names in the
30  * corresponding destinations.
31  */
32 public RenameResourceElementsOperation(IJavaElement[] elements, IJavaElement[] destinations, String[] newNames, boolean force) {
33         //a rename is a move to the same parent with a new name specified
34         //these elements are from different parents
35         super(elements, destinations, force);
36         setRenamings(newNames);
37 }
38 /**
39  * @see MultiOperation
40  */
41 protected String getMainTaskName() {
42         return Util.bind("operation.renameResourceProgress"); //$NON-NLS-1$
43 }
44 /**
45  * @see CopyResourceElementsOperation#isRename()
46  */
47 protected boolean isRename() {
48         return true;
49 }
50 /**
51  * @see MultiOperation
52  */
53 protected void verify(IJavaElement element) throws JavaModelException {
54         super.verify(element);
55
56         int elementType = element.getElementType();
57         
58         if (!(elementType == IJavaElement.COMPILATION_UNIT || elementType == IJavaElement.PACKAGE_FRAGMENT)) {
59                 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
60         }
61         if (elementType == IJavaElement.COMPILATION_UNIT) {
62                 if (((ICompilationUnit) element).isWorkingCopy()) {
63                         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
64                 }
65         }
66         verifyRenaming(element);
67 }
68 }