use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class DeleteResourceChange method saveFileIfNeeded.
private static void saveFileIfNeeded(IFile file, IProgressMonitor pm) throws CoreException {
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
if (buffer != null && buffer.isDirty() && buffer.isStateValidated() && buffer.isSynchronized()) {
//$NON-NLS-1$
pm.beginTask("", 2);
buffer.commit(new SubProgressMonitor(pm, 1), false);
file.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(pm, 1));
pm.done();
} else {
//$NON-NLS-1$
pm.beginTask("", 1);
pm.worked(1);
pm.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class UndoTextFileChange method isValid.
/**
* {@inheritDoc}
*/
public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
//$NON-NLS-1$
pm.beginTask("", 1);
try {
if (fValidationState == null)
//$NON-NLS-1$
throw new CoreException(new Status(IStatus.ERROR, RefactoringCorePlugin.getPluginId(), "UndoTextFileChange has not been initialialized"));
ITextFileBuffer buffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
fDirty = buffer != null && buffer.isDirty();
return fValidationState.isValid(needsSaving(), true);
} finally {
pm.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class UndoTextFileChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
boolean[] setContentStampSuccess = { false };
UndoEdit redo = performEdits(buffer, document, setContentStampSuccess);
if (needsSaving()) {
buffer.commit(pm, false);
if (!setContentStampSuccess[0]) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange(redo, currentStamp);
} catch (BadLocationException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (MalformedTreeException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw Changes.asCoreException(e);
else
return new NullChange();
} catch (CoreException e) {
if (fValidationState == null || !fValidationState.wasDerived())
throw e;
else
return new NullChange();
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class ModificationStampValidationState method getBuffer.
protected static ITextFileBuffer getBuffer(IFile file) {
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
IPath path = file.getFullPath();
ITextFileBuffer buffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
return buffer;
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project che by eclipse.
the class UndoDocumentChange method performEdits.
private UndoEdit performEdits() throws BadLocationException, MalformedTreeException {
ITextFileBufferManager fileBufferManager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = fileBufferManager.getTextFileBuffer(fDocument);
if (fileBuffer == null || !fileBuffer.isSynchronizationContextRequested()) {
return fUndo.apply(fDocument, TextEdit.CREATE_UNDO);
}
/** 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[] exception = new BadLocationException[1];
Runnable runnable = new Runnable() {
public void run() {
synchronized (completionLock) {
try {
result[0] = fUndo.apply(fDocument, TextEdit.CREATE_UNDO);
} catch (BadLocationException e) {
exception[0] = e;
} finally {
completionLock.fDone = true;
completionLock.notifyAll();
}
}
}
};
synchronized (completionLock) {
fileBufferManager.execute(runnable);
while (!completionLock.fDone) {
try {
completionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (exception[0] != null) {
throw exception[0];
}
return result[0];
}
Aggregations