KickJava   Java API By Example, From Geeks To Geeks.

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


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
12 package org.eclipse.jdt.internal.corext.refactoring.changes;
13
14 import org.eclipse.core.runtime.CoreException;
15 import org.eclipse.core.runtime.IProgressMonitor;
16
17 import org.eclipse.core.resources.IFolder;
18
19 import org.eclipse.jdt.core.IPackageFragment;
20 import org.eclipse.jdt.core.IPackageFragmentRoot;
21
22 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
23 import org.eclipse.jdt.internal.corext.refactoring.base.JDTChange;
24 import org.eclipse.ltk.core.refactoring.Change;
25 import org.eclipse.ltk.core.refactoring.NullChange;
26 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
27
28 public class CreatePackageChange extends JDTChange {
29     
30     private IPackageFragment fPackageFragment;
31     
32     public CreatePackageChange(IPackageFragment pack) {
33         fPackageFragment= pack;
34     }
35
36     public RefactoringStatus isValid(IProgressMonitor pm) {
37         // Don't do any checking. Peform handles the case
38
// that the package already exists. Furthermore
39
// create package change isn't used as a undo
40
// redo change right now
41
return new RefactoringStatus();
42     }
43     
44     public Change perform(IProgressMonitor pm) throws CoreException {
45         try {
46             pm.beginTask(RefactoringCoreMessages.CreatePackageChange_Creating_package, 1);
47
48             if (fPackageFragment.exists()) {
49                 return new NullChange();
50             } else {
51                 IPackageFragmentRoot root= (IPackageFragmentRoot) fPackageFragment.getParent();
52                 root.createPackageFragment(fPackageFragment.getElementName(), false, pm);
53                 
54                 return new DeleteFolderChange((IFolder) fPackageFragment.getResource(), true);
55             }
56         } finally {
57             pm.done();
58         }
59     }
60
61     public String JavaDoc getName() {
62         return RefactoringCoreMessages.CreatePackageChange_Create_package;
63     }
64
65     public Object JavaDoc getModifiedElement() {
66         return fPackageFragment;
67     }
68 }
69
Popular Tags