KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ltk > internal > core > refactoring > UndoDocumentChange


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.ltk.internal.core.refactoring;
12
13 import org.eclipse.text.edits.TextEdit;
14 import org.eclipse.text.edits.UndoEdit;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IProgressMonitor;
18 import org.eclipse.core.runtime.NullProgressMonitor;
19
20 import org.eclipse.jface.text.BadLocationException;
21 import org.eclipse.jface.text.IDocument;
22
23 import org.eclipse.ltk.core.refactoring.Change;
24 import org.eclipse.ltk.core.refactoring.RefactoringStatus;
25
26 public class UndoDocumentChange extends Change {
27     
28     private String JavaDoc fName;
29     private UndoEdit fUndo;
30     private IDocument fDocument;
31     private int fLength;
32     
33     public UndoDocumentChange(String JavaDoc name, IDocument document, UndoEdit undo) {
34         fName= name;
35         fUndo= undo;
36         fDocument= document;
37     }
38     
39     /**
40      * {@inheritDoc}
41      */

42     public String JavaDoc getName() {
43         return fName;
44     }
45     
46     /**
47      * {@inheritDoc}
48      */

49     public Object JavaDoc getModifiedElement() {
50         return null;
51     }
52     
53     /**
54      * {@inheritDoc}
55      */

56     public void initializeValidationData(IProgressMonitor pm) {
57         fLength= fDocument.getLength();
58     }
59     
60     /**
61      * {@inheritDoc}
62      */

63     public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
64         if (pm == null)
65             pm= new NullProgressMonitor();
66         pm.beginTask("", 1); //$NON-NLS-1$
67
RefactoringStatus result= TextChanges.isValid(fDocument, fLength);
68         pm.worked(1);
69         return result;
70     }
71     
72     /**
73      * {@inheritDoc}
74      */

75     public Change perform(IProgressMonitor pm) throws CoreException {
76         try {
77             UndoEdit redo= fUndo.apply(fDocument, TextEdit.CREATE_UNDO);
78             Change result= new UndoDocumentChange(getName(), fDocument, redo);
79             return result;
80         } catch (BadLocationException e) {
81             throw Changes.asCoreException(e);
82         }
83     }
84 }
85
Popular Tags