KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > corext > refactoring > changes > CopyCompilationUnitChange


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.internal.corext.refactoring.changes;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.core.runtime.IProgressMonitor;
15 import org.eclipse.core.runtime.OperationCanceledException;
16
17 import org.eclipse.ltk.core.refactoring.Change;
18 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
19
20 import org.eclipse.jdt.core.ICompilationUnit;
21 import org.eclipse.jdt.core.IPackageFragment;
22
23 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
24 import org.eclipse.jdt.internal.corext.refactoring.reorg.INewNameQuery;
25 import org.eclipse.jdt.internal.corext.util.Messages;
26
27 public class CopyCompilationUnitChange extends CompilationUnitReorgChange {
28     
29     public CopyCompilationUnitChange(ICompilationUnit cu, IPackageFragment dest, INewNameQuery newNameQuery){
30         super(cu, dest, newNameQuery);
31     }
32         
33     public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
34         // Copy compilation unit change isn't undoable and isn't used
35
// as a redo/undo change right now. Furthermore the current
36
// implementation allows copying dirty files. In this case only
37
// the content on disk is copied.
38
return super.isValid(pm, NONE);
39     }
40     
41     Change doPerformReorg(IProgressMonitor pm) throws CoreException, OperationCanceledException {
42         getCu().copy(getDestinationPackage(), null, getNewName(), true, pm);
43         return null;
44     }
45
46     public String JavaDoc getName() {
47         return Messages.format(RefactoringCoreMessages.CopyCompilationUnitChange_copy,
48             new String JavaDoc[]{getCu().getElementName(), getPackageName(getDestinationPackage())});
49     }
50 }
51
Popular Tags