01: /*******************************************************************************
02: * Copyright (c) 2006, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.corext.refactoring.changes;
11:
12: import org.eclipse.core.runtime.CoreException;
13: import org.eclipse.core.runtime.IProgressMonitor;
14: import org.eclipse.core.runtime.OperationCanceledException;
15: import org.eclipse.core.runtime.SubProgressMonitor;
16:
17: import org.eclipse.core.resources.IFile;
18: import org.eclipse.core.resources.IFolder;
19: import org.eclipse.core.resources.IResource;
20:
21: import org.eclipse.ui.ide.undo.ResourceDescription;
22:
23: import org.eclipse.ltk.core.refactoring.Change;
24: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
25:
26: import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
27: import org.eclipse.jdt.internal.corext.util.Messages;
28:
29: public class UndoDeleteResourceChange extends Change {
30:
31: private final ResourceDescription fResourceDescription;
32:
33: public UndoDeleteResourceChange(
34: ResourceDescription resourceDescription) {
35: fResourceDescription = resourceDescription;
36: }
37:
38: public void initializeValidationData(IProgressMonitor pm) {
39:
40: }
41:
42: public Object getModifiedElement() {
43: return null;
44: }
45:
46: public String getName() {
47: return Messages
48: .format(
49: RefactoringCoreMessages.UndoDeleteResourceChange_change_name,
50: fResourceDescription.getName());
51: }
52:
53: public RefactoringStatus isValid(IProgressMonitor pm)
54: throws CoreException, OperationCanceledException {
55: if (!fResourceDescription.isValid()) {
56: return RefactoringStatus
57: .createFatalErrorStatus(Messages
58: .format(
59: RefactoringCoreMessages.UndoDeleteResourceChange_cannot_restore,
60: fResourceDescription.getName()));
61: }
62:
63: if (fResourceDescription.verifyExistence(true)) {
64: return RefactoringStatus
65: .createFatalErrorStatus(Messages
66: .format(
67: RefactoringCoreMessages.UndoDeleteResourceChange_already_exists,
68: fResourceDescription.getName()));
69: }
70:
71: return new RefactoringStatus();
72: }
73:
74: public Change perform(IProgressMonitor pm) throws CoreException {
75: IResource created = fResourceDescription.createResource(pm);
76: created.refreshLocal(IResource.DEPTH_INFINITE,
77: new SubProgressMonitor(pm, 1));
78: if (created instanceof IFile) {
79: return new DeleteFileChange((IFile) created, false);
80: } else if (created instanceof IFolder) {
81: return new DeleteFolderChange((IFolder) created, false);
82: } else {
83: return null; // should not happen
84: }
85: }
86:
87: public String toString() {
88: return "Remove " + fResourceDescription.getName(); //$NON-NLS-1$
89: }
90: }
|