adds more details to the undo exception, see #364

This commit is contained in:
hneemann 2019-10-19 10:37:03 +02:00
parent 680312a31e
commit ce301ddbec

View File

@ -66,7 +66,7 @@ public class UndoManager<A extends Copyable<A>> {
modificationCounter = modifications.size();
fireChangedEvent();
} catch (ModifyException e) {
throw createTrace(e);
throw createTrace(e, null);
}
}
@ -87,7 +87,7 @@ public class UndoManager<A extends Copyable<A>> {
modificationCounter++;
fireChangedEvent();
} catch (ModifyException e) {
throw createTrace(e);
throw createTrace(e, null);
}
}
}
@ -106,27 +106,34 @@ public class UndoManager<A extends Copyable<A>> {
*/
public void undo() throws ModifyException {
if (undoAvailable()) {
Modification<A> lastWorkingModification = null;
try {
A newActual = initial.createDeepCopy();
for (int i = 0; i < modificationCounter - 1; i++)
modifications.get(i).modify(newActual);
for (int i = 0; i < modificationCounter - 1; i++) {
Modification<A> m = modifications.get(i);
m.modify(newActual);
lastWorkingModification = m;
}
modificationCounter--;
actual = newActual;
fireChangedEvent();
} catch (ModifyException e) {
throw createTrace(e);
throw createTrace(e, lastWorkingModification);
}
}
}
private ModifyException createTrace(ModifyException cause) {
private ModifyException createTrace(ModifyException cause, Modification<A> lastWorkingModification) {
StringBuilder sb = new StringBuilder("Exception during event processing");
for (int i = 0; i < modifications.size(); i++) {
if (i == modificationCounter)
sb.append("\n>");
else
sb.append("\n ");
sb.append(modifications.get(i).toString());
Modification<A> m = modifications.get(i);
sb.append(m.toString());
if (m == lastWorkingModification)
sb.append("\n -> exception in the following modification!");
}
if (modificationCounter == modifications.size())
sb.append("\n>");