Search in sources :

Example 41 with ISafeRunnable

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IDocumentSetupParticipantExtension(org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IDocumentSetupParticipant(org.eclipse.core.filebuffers.IDocumentSetupParticipant) IDocument(org.eclipse.jface.text.IDocument)

Example 42 with ISafeRunnable

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];
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IDocument(org.eclipse.jface.text.IDocument)

Example 43 with ISafeRunnable

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));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IFileBuffer(org.eclipse.core.filebuffers.IFileBuffer) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SubMonitor(org.eclipse.core.runtime.SubMonitor) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable)

Example 44 with ISafeRunnable

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) CoreException(org.eclipse.core.runtime.CoreException) TaskData(org.eclipse.mylyn.tasks.core.data.TaskData)

Aggregations

ISafeRunnable (org.eclipse.core.runtime.ISafeRunnable)44 CoreException (org.eclipse.core.runtime.CoreException)28 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)11 IStatus (org.eclipse.core.runtime.IStatus)11 Status (org.eclipse.core.runtime.Status)11 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)6 ISpellingPreferenceBlock (org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)5 ExecutionException (org.eclipse.core.commands.ExecutionException)4 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)4 SpellingEngineDescriptor (org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)4 ArrayList (java.util.ArrayList)3 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)3 ASTParser (org.eclipse.jdt.core.dom.ASTParser)3 IDocument (org.eclipse.jface.text.IDocument)3 IUndoManagerListener (org.eclipse.ltk.core.refactoring.IUndoManagerListener)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 IDocumentSetupParticipant (org.eclipse.core.filebuffers.IDocumentSetupParticipant)2 IDocumentSetupParticipantExtension (org.eclipse.core.filebuffers.IDocumentSetupParticipantExtension)2 IFile (org.eclipse.core.resources.IFile)2