use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class GenericFileBufferOperationRunner method createFileBuffers.
private IFileBuffer[] createFileBuffers(IPath[] locations, IProgressMonitor progressMonitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(progressMonitor, FileBuffersMessages.FileBufferOperationRunner_task_connecting, locations.length);
try {
IFileBuffer[] fileBuffers = new ITextFileBuffer[locations.length];
for (int i = 0; i < locations.length; i++) {
fFileBufferManager.connect(locations[i], LocationKind.NORMALIZE, subMonitor.split(1));
fileBuffers[i] = fFileBufferManager.getFileBuffer(locations[i], LocationKind.NORMALIZE);
}
return fileBuffers;
} catch (CoreException x) {
try {
releaseFileBuffers(locations, new NullProgressMonitor());
} catch (CoreException e) {
}
throw x;
}
}
use of org.eclipse.core.filebuffers.IFileBuffer in project eclipse.platform.text by eclipse.
the class GenericFileBufferOperationRunner method execute.
/**
* Executes the given operation for all file buffers specified by the given locations.
*
* @param locations the file buffer locations
* @param operation the operation to be performed
* @param monitor the progress monitor, or <code>null</code> if progress reporting is not desired
* @throws CoreException in case of error
* @throws OperationCanceledException in case the execution get canceled
*/
public void execute(IPath[] locations, final IFileBufferOperation operation, IProgressMonitor monitor) throws CoreException, OperationCanceledException {
final int size = locations.length;
SubMonitor subMonitor = SubMonitor.convert(monitor, operation.getOperationName(), size * 200);
try {
IFileBuffer[] fileBuffers = createFileBuffers(locations, subMonitor.split(size * 10));
IFileBuffer[] fileBuffers2Save = findFileBuffersToSave(fileBuffers);
fFileBufferManager.validateState(fileBuffers2Save, subMonitor.split(size * 10), fValidationContext);
if (!isCommitable(fileBuffers2Save)) {
throw new OperationCanceledException();
}
IFileBuffer[] unsynchronizedFileBuffers = findUnsynchronizedFileBuffers(fileBuffers);
performOperation(unsynchronizedFileBuffers, operation, subMonitor.split(size * 40));
final IFileBuffer[] synchronizedFileBuffers = findSynchronizedFileBuffers(fileBuffers);
fIsCompleted = false;
fThrowable = null;
synchronized (fCompletionLock) {
executeInContext(new Runnable() {
@Override
public void run() {
synchronized (fCompletionLock) {
try {
SafeRunner.run(new ISafeRunnable() {
@Override
public void handleException(Throwable throwable) {
fThrowable = throwable;
}
@Override
public void run() throws Exception {
performOperation(synchronizedFileBuffers, operation, subMonitor.split(50));
}
});
} finally {
fIsCompleted = true;
fCompletionLock.notifyAll();
}
}
}
});
while (!fIsCompleted) {
try {
fCompletionLock.wait(500);
} catch (InterruptedException x) {
}
}
}
if (fThrowable != null) {
if (fThrowable instanceof CoreException)
throw (CoreException) fThrowable;
throw new CoreException(new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IFileBufferStatusCodes.CONTENT_CHANGE_FAILED, fThrowable.getLocalizedMessage(), fThrowable));
}
commit(fileBuffers2Save, subMonitor.split(size * 80));
} finally {
releaseFileBuffers(locations, subMonitor.split(size * 10));
}
}
Aggregations