summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Hiesserich2013-06-21 14:38:01 (EDT)
committer Florian Thienel2013-06-21 14:38:01 (EDT)
commit6831546c0812eb41082ef09334256e59724e2a45 (patch)
tree9bc1f9271132bde42eaf202fb35f8206ff92e3aa
parent70608eb91838ee2b1cdb48a16c3df0f863cd6955 (diff)
downloadorg.eclipse.mylyn.docs.vex-6831546c0812eb41082ef09334256e59724e2a45.zip
org.eclipse.mylyn.docs.vex-6831546c0812eb41082ef09334256e59724e2a45.tar.gz
org.eclipse.mylyn.docs.vex-6831546c0812eb41082ef09334256e59724e2a45.tar.bz2
refactoring: provide a base implementation for IUndoableEdit
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/AbstractUndoableEdit.java94
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeAttributeEdit.java26
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeNamespaceEdit.java26
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/CompoundEdit.java33
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/DeleteEdit.java26
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/IUndoableEdit.java17
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertCommentEdit.java26
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertElementEdit.java25
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertFragmentEdit.java26
-rw-r--r--org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertTextEdit.java25
10 files changed, 260 insertions, 64 deletions
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/AbstractUndoableEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/AbstractUndoableEdit.java
new file mode 100644
index 0000000..d89752b
--- /dev/null
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/AbstractUndoableEdit.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Carsten Hiesserich and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Carsten Hiesserich - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.vex.core.internal.undo;
+
+/**
+ * A default implementation of <code>IUndoableEdit</code> that can be used as a base for implementing editing
+ * operations.
+ *
+ */
+public abstract class AbstractUndoableEdit implements IUndoableEdit {
+
+ /**
+ * Indicates whether this editing action has been executed. A value of <code>true</code> means that the action was
+ * performed, or that a redo operation was successful.
+ */
+ private boolean hasBeenDone = false;
+
+ public boolean combine(final IUndoableEdit edit) {
+ if (hasBeenDone) {
+ return performCombine(edit);
+ }
+ return false;
+ }
+
+ /**
+ * To be implemented by subclasses to perform the actual Combine action. The default implementation always returns
+ * <code>false</code>.
+ *
+ * @param edit
+ * The edit to combine with this one
+ * @return <code>true</code> if the given edit has been combined with this one.
+ */
+ protected boolean performCombine(final IUndoableEdit edit) {
+ return false;
+ }
+
+ public void redo() throws CannotRedoException {
+ if (!canRedo()) {
+ throw new CannotRedoException();
+ }
+
+ try {
+ performRedo();
+ hasBeenDone = true;
+ } catch (final CannotRedoException ex) {
+ hasBeenDone = false;
+ throw ex;
+ }
+ }
+
+ /**
+ * To be implemented by subclasses to perform the actual Redo action.
+ *
+ * @throws CannotRedoException
+ */
+ protected abstract void performRedo() throws CannotRedoException;
+
+ public void undo() throws CannotUndoException {
+ if (!canUndo()) {
+ throw new CannotUndoException();
+ }
+
+ try {
+ performUndo();
+ hasBeenDone = false;
+ } catch (final CannotUndoException ex) {
+ throw ex;
+ }
+ }
+
+ /**
+ * To be implemented by subclasses to perform the actual Undo action.
+ *
+ * @throws CannotUndoException
+ */
+ protected abstract void performUndo() throws CannotUndoException;
+
+ public boolean canUndo() {
+ return hasBeenDone;
+ }
+
+ public boolean canRedo() {
+ return !hasBeenDone;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeAttributeEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeAttributeEdit.java
index 3ff420b..058cb7c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeAttributeEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeAttributeEdit.java
@@ -1,10 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IElement;
-public class ChangeAttributeEdit implements IUndoableEdit {
+public class ChangeAttributeEdit extends AbstractUndoableEdit {
private final IElement element;
private final QualifiedName attributeName;
@@ -12,17 +23,15 @@ public class ChangeAttributeEdit implements IUndoableEdit {
private final String newValue;
public ChangeAttributeEdit(final IElement element, final QualifiedName attributeName, final String oldValue, final String newValue) {
+ super();
this.element = element;
this.attributeName = attributeName;
this.oldValue = oldValue;
this.newValue = newValue;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
element.setAttribute(attributeName, oldValue);
} catch (final DocumentValidationException ex) {
@@ -30,11 +39,12 @@ public class ChangeAttributeEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
element.setAttribute(attributeName, newValue);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeNamespaceEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeNamespaceEdit.java
index 73f8eb1..2216261 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeNamespaceEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/ChangeNamespaceEdit.java
@@ -1,9 +1,20 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IElement;
-public class ChangeNamespaceEdit implements IUndoableEdit {
+public class ChangeNamespaceEdit extends AbstractUndoableEdit {
private final IElement element;
private final String prefix;
@@ -11,17 +22,15 @@ public class ChangeNamespaceEdit implements IUndoableEdit {
private final String newUri;
public ChangeNamespaceEdit(final IElement element, final String prefix, final String oldUri, final String newUri) {
+ super();
this.element = element;
this.prefix = prefix;
this.oldUri = oldUri;
this.newUri = newUri;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
if (oldUri == null) {
element.removeNamespace(prefix);
@@ -33,7 +42,8 @@ public class ChangeNamespaceEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
if (newUri == null) {
element.removeNamespace(prefix);
@@ -41,7 +51,7 @@ public class ChangeNamespaceEdit implements IUndoableEdit {
element.declareNamespace(prefix, newUri);
}
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/CompoundEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/CompoundEdit.java
index 6560845..67007ff 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/CompoundEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/CompoundEdit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2013 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* John Krasnay - initial API and implementation
* Igor Jacy Lino Campista - Java 5 warnings fixed (bug 311325)
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
*******************************************************************************/
package org.eclipse.vex.core.internal.undo;
@@ -17,7 +18,7 @@ import java.util.List;
/**
* An undoable edit that is a composite of others.
*/
-public class CompoundEdit implements IUndoableEdit {
+public class CompoundEdit extends AbstractUndoableEdit {
/**
* Class constructor.
@@ -35,30 +36,42 @@ public class CompoundEdit implements IUndoableEdit {
edits.add(edit);
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
/**
* Calls redo() on each contained edit, in the order that they were added.
*/
- public void redo() {
+ @Override
+ protected void performRedo() {
for (int i = 0; i < edits.size(); i++) {
final IUndoableEdit edit = edits.get(i);
- edit.redo();
+ if (edit.canRedo()) {
+ edit.redo();
+ }
}
}
/**
* Calls undo() on each contained edit, in reverse order from which they were added.
*/
- public void undo() {
+ @Override
+ protected void performUndo() {
for (int i = edits.size() - 1; i >= 0; i--) {
final IUndoableEdit edit = edits.get(i);
- edit.undo();
+ if (edit.canUndo()) {
+ edit.undo();
+ }
}
}
+ @Override
+ public boolean canUndo() {
+ return true;
+ }
+
+ @Override
+ public boolean canRedo() {
+ return true;
+ }
+
// ===================================================== PRIVATE
private final List<IUndoableEdit> edits = new ArrayList<IUndoableEdit>();
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/DeleteEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/DeleteEdit.java
index 1b4cdf6..9b7e890 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/DeleteEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/DeleteEdit.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.vex.core.provisional.dom.ContentRange;
@@ -5,22 +16,20 @@ import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IDocument;
import org.eclipse.vex.core.provisional.dom.IDocumentFragment;
-public class DeleteEdit implements IUndoableEdit {
+public class DeleteEdit extends AbstractUndoableEdit {
private final IDocument document;
private final ContentRange range;
private IDocumentFragment fragment = null;
public DeleteEdit(final IDocument document, final ContentRange range) {
+ super();
this.document = document;
this.range = range;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
document.insertFragment(range.getStartOffset(), fragment);
fragment = null;
@@ -29,12 +38,13 @@ public class DeleteEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
fragment = document.getFragment(range);
document.delete(range);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/IUndoableEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/IUndoableEdit.java
index 1c9cf2f..6b5e8dd 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/IUndoableEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/IUndoableEdit.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2008 John Krasnay and others.
+ * Copyright (c) 2004, 2013 John Krasnay and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,6 +7,7 @@
*
* Contributors:
* John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Added methods to support AbstractUndoableEdit
*******************************************************************************/
package org.eclipse.vex.core.internal.undo;
@@ -36,4 +37,18 @@ public interface IUndoableEdit {
* Undo the edit.
*/
public void undo() throws CannotUndoException;
+
+ /**
+ * Determines whether it would be possible to undo this editing action.
+ *
+ * @return <code>true</code> to indicate that this edit can be undone, <code>false</code> otherwise.
+ */
+ public boolean canUndo();
+
+ /**
+ * Determines whether it would be possible to redo this editing action.
+ *
+ * @return <code>true</code> to indicate that this edit can be redone, <code>false</code> otherwise.
+ */
+ public boolean canRedo();
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertCommentEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertCommentEdit.java
index b26df85..6aeb453 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertCommentEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertCommentEdit.java
@@ -1,26 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IComment;
import org.eclipse.vex.core.provisional.dom.IDocument;
-public class InsertCommentEdit implements IUndoableEdit {
+public class InsertCommentEdit extends AbstractUndoableEdit {
private final IDocument document;
private final int offset;
private IComment comment;
public InsertCommentEdit(final IDocument document, final int offset) {
+ super();
this.document = document;
this.offset = offset;
comment = null;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
document.delete(comment.getRange());
comment = null;
@@ -29,11 +38,12 @@ public class InsertCommentEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
comment = document.insertComment(offset);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertElementEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertElementEdit.java
index f3f55eb..5ffb26c 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertElementEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertElementEdit.java
@@ -1,3 +1,14 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.core.runtime.QualifiedName;
@@ -5,7 +16,7 @@ import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IDocument;
import org.eclipse.vex.core.provisional.dom.IElement;
-public class InsertElementEdit implements IUndoableEdit {
+public class InsertElementEdit extends AbstractUndoableEdit {
private final IDocument document;
private final int offset;
@@ -19,11 +30,8 @@ public class InsertElementEdit implements IUndoableEdit {
element = null;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
document.delete(element.getRange());
element = null;
@@ -32,11 +40,12 @@ public class InsertElementEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
element = document.insertElement(offset, elementName);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertFragmentEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertFragmentEdit.java
index eef230a..7383ac0 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertFragmentEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertFragmentEdit.java
@@ -1,26 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IDocument;
import org.eclipse.vex.core.provisional.dom.IDocumentFragment;
-public class InsertFragmentEdit implements IUndoableEdit {
+public class InsertFragmentEdit extends AbstractUndoableEdit {
private final IDocument document;
private final int offset;
private final IDocumentFragment fragment;
public InsertFragmentEdit(final IDocument document, final int offset, final IDocumentFragment fragment) {
+ super();
this.document = document;
this.offset = offset;
this.fragment = fragment;
}
- public boolean combine(final IUndoableEdit edit) {
- return false;
- }
-
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
document.delete(fragment.getContent().getRange().moveBy(offset));
} catch (final DocumentValidationException ex) {
@@ -28,11 +37,12 @@ public class InsertFragmentEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
document.insertFragment(offset, fragment);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}
diff --git a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertTextEdit.java b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertTextEdit.java
index 4dcb065..c6a87bb 100644
--- a/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertTextEdit.java
+++ b/org.eclipse.vex.core/src/org/eclipse/vex/core/internal/undo/InsertTextEdit.java
@@ -1,22 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2013 John Krasnay and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * John Krasnay - initial API and implementation
+ * Carsten Hiesserich - Refactored to use AbstractUndoableEdit
+ *******************************************************************************/
package org.eclipse.vex.core.internal.undo;
import org.eclipse.vex.core.provisional.dom.ContentRange;
import org.eclipse.vex.core.provisional.dom.DocumentValidationException;
import org.eclipse.vex.core.provisional.dom.IDocument;
-public class InsertTextEdit implements IUndoableEdit {
+public class InsertTextEdit extends AbstractUndoableEdit {
private final IDocument document;
private final int offset;
private String text;
public InsertTextEdit(final IDocument document, final int offset, final String text) {
+ super();
this.document = document;
this.offset = offset;
this.text = text;
}
- public boolean combine(final IUndoableEdit edit) {
+ @Override
+ protected boolean performCombine(final IUndoableEdit edit) {
if (edit instanceof InsertTextEdit) {
final InsertTextEdit ite = (InsertTextEdit) edit;
if (ite.offset == offset + text.length()) {
@@ -27,7 +40,8 @@ public class InsertTextEdit implements IUndoableEdit {
return false;
}
- public void undo() throws CannotUndoException {
+ @Override
+ protected void performUndo() throws CannotUndoException {
try {
document.delete(new ContentRange(offset, offset + text.length() - 1));
} catch (final DocumentValidationException ex) {
@@ -35,11 +49,12 @@ public class InsertTextEdit implements IUndoableEdit {
}
}
- public void redo() throws CannotRedoException {
+ @Override
+ protected void performRedo() throws CannotRedoException {
try {
document.insertText(offset, text);
} catch (final DocumentValidationException ex) {
- throw new CannotUndoException();
+ throw new CannotRedoException();
}
}