use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.
the class TextFileBufferManager method createEmptyDocument.
@Override
public IDocument createEmptyDocument(final IPath location, final LocationKind locationKind) {
IDocument documentFromFactory = createDocumentFromFactory(location, locationKind);
final IDocument document;
if (documentFromFactory != null)
document = documentFromFactory;
else
document = new SynchronizableDocument();
if (location == null)
return document;
// Set the initial line delimiter
if (document instanceof IDocumentExtension4) {
String initalLineDelimiter = getLineDelimiterPreference(location, locationKind);
if (initalLineDelimiter != null)
((IDocumentExtension4) document).setInitialLineDelimiter(initalLineDelimiter);
}
final IDocumentSetupParticipant[] participants = fRegistry.getDocumentSetupParticipants(location, locationKind);
if (participants != null) {
for (final IDocumentSetupParticipant participant : participants) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void run() throws Exception {
if (participant instanceof IDocumentSetupParticipantExtension)
((IDocumentSetupParticipantExtension) participant).setup(document, location, locationKind);
else
participant.setup(document);
if (document.getDocumentPartitioner() != null) {
String message = NLSUtility.format(FileBuffersMessages.TextFileBufferManager_warning_documentSetupInstallsDefaultPartitioner, participant.getClass());
IStatus status = new Status(IStatus.WARNING, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, message, null);
FileBuffersPlugin.getDefault().getLog().log(status);
}
}
@Override
public void handleException(Throwable t) {
IStatus status = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.TextFileBufferManager_error_documentSetupFailed, t);
FileBuffersPlugin.getDefault().getLog().log(status);
}
};
SafeRunner.run(runnable);
}
}
return document;
}
use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.
the class TextFileBufferManager method createDocumentFromFactory.
/**
* Helper to get rid of deprecation warnings.
*
* @param location the location of the file to be connected
* @param locationKind the kind of the given location
* @return the created empty document or <code>null</code> if none got created
* @since 3.5
* @deprecated As of 3.5
*/
@Deprecated
private IDocument createDocumentFromFactory(final IPath location, final LocationKind locationKind) {
final IDocument[] runnableResult = new IDocument[1];
if (location != null) {
final org.eclipse.core.filebuffers.IDocumentFactory factory = fRegistry.getDocumentFactory(location, locationKind);
if (factory != null) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void run() throws Exception {
runnableResult[0] = factory.createDocument();
}
@Override
public void handleException(Throwable t) {
IStatus status = new Status(IStatus.ERROR, FileBuffersPlugin.PLUGIN_ID, IStatus.OK, FileBuffersMessages.TextFileBufferManager_error_documentFactoryFailed, t);
FileBuffersPlugin.getDefault().getLog().log(status);
}
};
SafeRunner.run(runnable);
}
}
return runnableResult[0];
}
use of org.eclipse.core.runtime.ISafeRunnable 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));
}
}
use of org.eclipse.core.runtime.ISafeRunnable in project linuxtools by eclipse.
the class OSIORestClient method performQuery.
public IStatus performQuery(TaskRepository taskRepository, final IRepositoryQuery query, final TaskDataCollector resultCollector, IOperationMonitor monitor) throws OSIORestException {
String queryUrl = query.getUrl();
// $NON-NLS-1$
int index = queryUrl.indexOf("?");
if (index > 0) {
String queryParams = queryUrl.substring(index + 1);
if (!queryParams.startsWith("filter")) {
// $NON-NLS-1$
queryUrl = formSearchUrl(queryUrl);
}
}
String queryUrlSuffix = connector.getURLSuffix(queryUrl);
try {
List<TaskData> taskDataArray = restRequestProvider.getTaskData(monitor, client, connector, queryUrlSuffix, taskRepository);
for (final TaskData taskData : taskDataArray) {
taskData.setPartial(true);
SafeRunner.run(new ISafeRunnable() {
@Override
public void run() throws Exception {
resultCollector.accept(taskData);
}
@Override
public void handleException(Throwable exception) {
StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Unexpected error during result collection. TaskID {0} in repository {1}", taskData.getTaskId(), taskData.getRepositoryUrl()), exception));
}
});
}
} catch (CoreException e) {
StatusHandler.log(new Status(IStatus.ERROR, OSIORestCore.ID_PLUGIN, // $NON-NLS-1$
NLS.bind(// $NON-NLS-1$
"Unexpected error during result collection in repository {0}", taskRepository.getRepositoryUrl()), e));
}
return Status.OK_STATUS;
}
Aggregations