KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.SubProgressMonitor;
16
17 import org.eclipse.core.resources.IFile;
18 import org.eclipse.core.resources.IResource;
19
20 import org.eclipse.core.filebuffers.FileBuffers;
21 import org.eclipse.core.filebuffers.ITextFileBuffer;
22 import org.eclipse.core.filebuffers.LocationKind;
23
24 import org.eclipse.jdt.internal.corext.refactoring.RefactoringCoreMessages;
25 import org.eclipse.jdt.internal.corext.refactoring.base.JDTChange;
26 import org.eclipse.ltk.core.refactoring.Change;
27
28 abstract class AbstractDeleteChange extends JDTChange {
29     
30     protected abstract Change doDelete(IProgressMonitor pm) throws CoreException;
31     
32     /* non java-doc
33      * @see IChange#perform(ChangeContext, IProgressMonitor)
34      */

35     public final Change perform(IProgressMonitor pm) throws CoreException {
36         try {
37             pm.beginTask(RefactoringCoreMessages.AbstractDeleteChange_deleting, 1);
38             Change undo= doDelete(pm);
39             return undo;
40         } finally {
41             pm.done();
42         }
43     }
44     
45     protected static void saveFileIfNeeded(IFile file, IProgressMonitor pm) throws CoreException {
46         ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
47         if (buffer != null && buffer.isDirty() && buffer.isStateValidated() && buffer.isSynchronized()) {
48             pm.beginTask("", 2); //$NON-NLS-1$
49
buffer.commit(new SubProgressMonitor(pm, 1), false);
50             file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
51             pm.done();
52         } else {
53             pm.beginTask("", 1); //$NON-NLS-1$
54
pm.worked(1);
55             pm.done();
56         }
57     }
58 }
59
60
Popular Tags