use of org.eclipse.text.edits.UndoEdit in project che by eclipse.
the class UndoTextFileChange method performEdits.
private UndoEdit performEdits(ITextFileBuffer buffer, final IDocument document, final boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException {
if (!buffer.isSynchronizationContextRequested()) {
return doPerformEdits(document, setContentStampSuccess);
}
ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
/** The lock for waiting for computation in the UI thread to complete. */
final Lock completionLock = new Lock();
final UndoEdit[] result = new UndoEdit[1];
final BadLocationException[] badLocationException = new BadLocationException[1];
final MalformedTreeException[] malformedTreeException = new MalformedTreeException[1];
final CoreException[] coreException = new CoreException[1];
Runnable runnable = new Runnable() {
public void run() {
synchronized (completionLock) {
try {
result[0] = doPerformEdits(document, setContentStampSuccess);
} catch (BadLocationException e) {
badLocationException[0] = e;
} catch (MalformedTreeException e) {
malformedTreeException[0] = e;
} catch (CoreException e) {
coreException[0] = e;
} finally {
completionLock.fDone = true;
completionLock.notifyAll();
}
}
}
};
synchronized (completionLock) {
fileBufferManager.execute(runnable);
while (!completionLock.fDone) {
try {
completionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (badLocationException[0] != null) {
throw badLocationException[0];
} else if (malformedTreeException[0] != null) {
throw malformedTreeException[0];
} else if (coreException[0] != null) {
throw coreException[0];
}
return result[0];
}
use of org.eclipse.text.edits.UndoEdit in project che by eclipse.
the class UndoTextFileChange method doPerformEdits.
private UndoEdit doPerformEdits(IDocument document, boolean[] setContentStampSuccess) throws MalformedTreeException, BadLocationException, CoreException {
// perform the changes
LinkedModeModel.closeAllModels(document);
UndoEdit redo = fUndo.apply(document, TextEdit.CREATE_UNDO);
// try to restore the document content stamp
setContentStampSuccess[0] = ContentStamps.set(document, fContentStampToRestore);
return redo;
}
use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testNestedCopySource.
@Test
public void testNestedCopySource() throws Exception {
CopySourceEdit s1 = new CopySourceEdit(1, 5);
CopySourceEdit s2 = new CopySourceEdit(2, 3);
CopySourceEdit s3 = new CopySourceEdit(3, 1);
s1.addChild(s2);
s2.addChild(s3);
CopyTargetEdit t1 = new CopyTargetEdit(9, s1);
CopyTargetEdit t2 = new CopyTargetEdit(8, s2);
CopyTargetEdit t3 = new CopyTargetEdit(7, s3);
fRoot.addChild(s1);
fRoot.addChild(t1);
fRoot.addChild(t2);
fRoot.addChild(t3);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 1, 5);
assertEquals(s2, 2, 3);
assertEquals(s3, 3, 1);
assertEquals(t1, 13, 5);
assertEquals(t2, 9, 3);
assertEquals(t3, 7, 1);
String result = "0123456372348123459";
Assert.assertEquals("Buffer content", result, fDocument.get());
doUndoRedo(undo, result);
}
use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testInsert1.
@Test
public void testInsert1() throws Exception {
// [][ ]
TextEdit e1 = new InsertEdit(2, "yy");
TextEdit e2 = new ReplaceEdit(2, 3, "3456");
fRoot.addChild(e1);
fRoot.addChild(e2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(fRoot, 2, 6);
assertEquals(e1, 2, 2);
assertEquals(e2, 4, 4);
Assert.assertEquals("Buffer content", "01yy345656789", fDocument.get());
doUndoRedo(undo, "01yy345656789");
}
use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.
the class TextEditTests method testDoubleCopy.
@Test
public void testDoubleCopy() throws Exception {
CopySourceEdit s1 = new CopySourceEdit(5, 2);
CopyTargetEdit t1 = new CopyTargetEdit(8, s1);
CopySourceEdit s2 = new CopySourceEdit(5, 2);
CopyTargetEdit t2 = new CopyTargetEdit(2, s2);
s1.addChild(s2);
fRoot.addChild(s1);
fRoot.addChild(t1);
fRoot.addChild(t2);
UndoEdit undo = fRoot.apply(fDocument);
assertEquals(s1, 7, 2);
assertEquals(t1, 10, 2);
assertEquals(s2, 7, 2);
assertEquals(t2, 2, 2);
String result = "01562345675689";
Assert.assertEquals("Buffer content", result, fDocument.get());
doUndoRedo(undo, result);
}
Aggregations