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(); modificationCounter = modifications.size();
fireChangedEvent(); fireChangedEvent();
} catch (ModifyException e) { } catch (ModifyException e) {
throw createTrace(e); throw createTrace(e, null);
} }
} }
@ -87,7 +87,7 @@ public class UndoManager<A extends Copyable<A>> {
modificationCounter++; modificationCounter++;
fireChangedEvent(); fireChangedEvent();
} catch (ModifyException e) { } 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 { public void undo() throws ModifyException {
if (undoAvailable()) { if (undoAvailable()) {
Modification<A> lastWorkingModification = null;
try { try {
A newActual = initial.createDeepCopy(); A newActual = initial.createDeepCopy();
for (int i = 0; i < modificationCounter - 1; i++) for (int i = 0; i < modificationCounter - 1; i++) {
modifications.get(i).modify(newActual); Modification<A> m = modifications.get(i);
m.modify(newActual);
lastWorkingModification = m;
}
modificationCounter--; modificationCounter--;
actual = newActual; actual = newActual;
fireChangedEvent(); fireChangedEvent();
} catch (ModifyException e) { } 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"); StringBuilder sb = new StringBuilder("Exception during event processing");
for (int i = 0; i < modifications.size(); i++) { for (int i = 0; i < modifications.size(); i++) {
if (i == modificationCounter) if (i == modificationCounter)
sb.append("\n>"); sb.append("\n>");
else else
sb.append("\n "); 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()) if (modificationCounter == modifications.size())
sb.append("\n>"); sb.append("\n>");