KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > text > edits > UndoEdit


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.text.edits;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18
19 /**
20  * This class encapsulates the reverse changes of an executed text
21  * edit tree. To apply an undo memento to a document use method
22  * <code>apply(IDocument)</code>.
23  * <p>
24  * Clients can't add additional children to an undo edit nor can they
25  * add an undo edit as a child to another edit. Doing so results in
26  * both cases in a <code>MalformedTreeException<code>.
27  *
28  * @since 3.0
29  */

30 public final class UndoEdit extends TextEdit {
31
32     UndoEdit() {
33         super(0, Integer.MAX_VALUE);
34     }
35
36     private UndoEdit(UndoEdit other) {
37         super(other);
38     }
39
40     /*
41      * @see org.eclipse.text.edits.TextEdit#internalAdd(org.eclipse.text.edits.TextEdit)
42      */

43     void internalAdd(TextEdit child) throws MalformedTreeException {
44         throw new MalformedTreeException(null, this, TextEditMessages.getString("UndoEdit.no_children")); //$NON-NLS-1$
45
}
46
47     /*
48      * @see org.eclipse.text.edits.MultiTextEdit#aboutToBeAdded(org.eclipse.text.edits.TextEdit)
49      */

50     void aboutToBeAdded(TextEdit parent) {
51         throw new MalformedTreeException(parent, this, TextEditMessages.getString("UndoEdit.can_not_be_added")); //$NON-NLS-1$
52
}
53
54     UndoEdit dispatchPerformEdits(TextEditProcessor processor) throws BadLocationException {
55         return processor.executeUndo();
56     }
57
58     void dispatchCheckIntegrity(TextEditProcessor processor) throws MalformedTreeException {
59         processor.checkIntegrityUndo();
60     }
61
62     /*
63      * @see org.eclipse.text.edits.TextEdit#doCopy()
64      */

65     protected TextEdit doCopy() {
66         return new UndoEdit(this);
67     }
68
69     /*
70      * @see TextEdit#accept0
71      */

72     protected void accept0(TextEditVisitor visitor) {
73         boolean visitChildren= visitor.visit(this);
74         if (visitChildren) {
75             acceptChildren(visitor);
76         }
77     }
78
79     /*
80      * @see TextEdit#performDocumentUpdating
81      */

82     int performDocumentUpdating(IDocument document) throws BadLocationException {
83         fDelta= 0;
84         return fDelta;
85     }
86
87     void add(ReplaceEdit edit) {
88         List JavaDoc children= internalGetChildren();
89         if (children == null) {
90             children= new ArrayList JavaDoc(2);
91             internalSetChildren(children);
92         }
93         children.add(edit);
94     }
95
96     void defineRegion(int offset, int length) {
97         internalSetOffset(offset);
98         internalSetLength(length);
99     }
100
101     boolean deleteChildren() {
102         return false;
103     }
104 }
105
106
Popular Tags