blob: 536a046d213b6bd6633b447dcf84e22ac46febc8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package org.eclipse.vex.core.internal.undo;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.dom.DocumentValidationException;
import org.eclipse.vex.core.dom.IDocument;
import org.eclipse.vex.core.dom.IElement;
public class InsertElementEdit implements IUndoableEdit {
private final IDocument document;
private final int offset;
private final QualifiedName elementName;
private IElement element;
public InsertElementEdit(final IDocument document, final int offset, final QualifiedName elementName) {
this.document = document;
this.offset = offset;
this.elementName = elementName;
element = null;
}
public boolean combine(final IUndoableEdit edit) {
return false;
}
public void undo() throws CannotUndoException {
try {
document.delete(element.getRange());
element = null;
} catch (final DocumentValidationException ex) {
throw new CannotUndoException();
}
}
public void redo() throws CannotRedoException {
try {
element = document.insertElement(offset, elementName);
} catch (final DocumentValidationException ex) {
throw new CannotUndoException();
}
}
public IElement getElement() {
return element;
}
}
|