A massive organize imports and formatting of the sources using default Eclipse code...
[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>
23  * Notes:
24  * <ul>
25  * <li>When a compilation unit is renamed, its main type and the constructors
26  * of the main type are renamed.
27  * </ul>
28  */
29 public class RenameResourceElementsOperation extends
30                 MoveResourceElementsOperation {
31         /**
32          * When executed, this operation will rename the specified elements with the
33          * given names in the corresponding destinations.
34          */
35         public RenameResourceElementsOperation(IJavaElement[] elements,
36                         IJavaElement[] destinations, String[] newNames, boolean force) {
37                 // a rename is a move to the same parent with a new name specified
38                 // these elements are from different parents
39                 super(elements, destinations, force);
40                 setRenamings(newNames);
41         }
42
43         /**
44          * @see MultiOperation
45          */
46         protected String getMainTaskName() {
47                 return Util.bind("operation.renameResourceProgress"); //$NON-NLS-1$
48         }
49
50         /**
51          * @see CopyResourceElementsOperation#isRename()
52          */
53         protected boolean isRename() {
54                 return true;
55         }
56
57         /**
58          * @see MultiOperation
59          */
60         protected void verify(IJavaElement element) throws JavaModelException {
61                 super.verify(element);
62
63                 int elementType = element.getElementType();
64
65                 if (!(elementType == IJavaElement.COMPILATION_UNIT || elementType == IJavaElement.PACKAGE_FRAGMENT)) {
66                         error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
67                 }
68                 if (elementType == IJavaElement.COMPILATION_UNIT) {
69                         if (((ICompilationUnit) element).isWorkingCopy()) {
70                                 error(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, element);
71                         }
72                 }
73                 verifyRenaming(element);
74         }
75 }