KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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 import org.eclipse.core.runtime.SubProgressMonitor;
17
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.IFolder;
20 import org.eclipse.core.resources.IResource;
21
22 import org.eclipse.ui.ide.undo.ResourceDescription;
23
24 import org.eclipse.ltk.core.refactoring.Change;
25 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
26
27 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
28 import org.eclipse.jdt.internal.corext.util.Messages;
29
30
31 public class UndoDeleteResourceChange extends Change {
32
33     private final ResourceDescription fResourceDescription;
34
35     public UndoDeleteResourceChange(ResourceDescription resourceDescription) {
36         fResourceDescription= resourceDescription;
37     }
38     
39     public void initializeValidationData(IProgressMonitor pm) {
40         
41     }
42     
43     public Object JavaDoc getModifiedElement() {
44         return null;
45     }
46
47     public String JavaDoc getName() {
48         return Messages.format(RefactoringCoreMessages.UndoDeleteResourceChange_change_name, fResourceDescription.getName());
49     }
50
51     public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException, OperationCanceledException {
52         if (! fResourceDescription.isValid()) {
53             return RefactoringStatus.createFatalErrorStatus(
54                     Messages.format(
55                             RefactoringCoreMessages.UndoDeleteResourceChange_cannot_restore,
56                             fResourceDescription.getName()));
57         }
58         
59         if (fResourceDescription.verifyExistence(true)) {
60             return RefactoringStatus.createFatalErrorStatus(
61                     Messages.format(
62                             RefactoringCoreMessages.UndoDeleteResourceChange_already_exists,
63                             fResourceDescription.getName()));
64         }
65         
66         return new RefactoringStatus();
67     }
68
69     public Change perform(IProgressMonitor pm) throws CoreException {
70         IResource created= fResourceDescription.createResource(pm);
71         created.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(pm, 1));
72         if (created instanceof IFile) {
73             return new DeleteFileChange((IFile) created, false);
74         } else if (created instanceof IFolder) {
75             return new DeleteFolderChange((IFolder) created, false);
76         } else {
77             return null; // should not happen
78
}
79     }
80     
81     public String JavaDoc toString() {
82         return "Remove " + fResourceDescription.getName(); //$NON-NLS-1$
83
}
84 }
85
Popular Tags