Search in sources :

Example 36 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class SpellingConfigurationBlock method updateListDependencies.

void updateListDependencies() {
    SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
    String id;
    if (desc == null) {
        // safety in case there is no such descriptor
        // $NON-NLS-1$
        id = "";
        String message = TextEditorMessages.SpellingConfigurationBlock_error_not_exist;
        EditorsPlugin.log(new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, IStatus.OK, message, null));
        fCurrentBlock = new ErrorPreferences(message);
    } else {
        id = desc.getId();
        fCurrentBlock = fProviderPreferences.get(id);
        if (fCurrentBlock == null) {
            try {
                fCurrentBlock = desc.createPreferences();
                fProviderPreferences.put(id, fCurrentBlock);
            } catch (CoreException e) {
                EditorsPlugin.log(e);
                fCurrentBlock = new ErrorPreferences(e.getLocalizedMessage());
            }
        }
    }
    Control control = fProviderControls.get(id);
    if (control == null) {
        final Control[] result = new Control[1];
        ISafeRunnable runnable = new ISafeRunnable() {

            @Override
            public void run() throws Exception {
                result[0] = fCurrentBlock.createControl(fGroup);
            }

            @Override
            public void handleException(Throwable x) {
            }
        };
        SafeRunner.run(runnable);
        control = result[0];
        if (control == null) {
            String message = TextEditorMessages.SpellingConfigurationBlock_info_no_preferences;
            EditorsPlugin.log(new Status(IStatus.WARNING, EditorsUI.PLUGIN_ID, IStatus.OK, message, null));
            control = new ErrorPreferences(message).createControl(fGroup);
        } else {
            fProviderControls.put(id, control);
        }
    }
    Dialog.applyDialogFont(control);
    fStackLayout.topControl = control;
    control.pack();
    fGroup.layout();
    fGroup.getParent().layout();
    fStatusMonitor.statusChanged(new StatusInfo());
    ISafeRunnable runnable = new ISafeRunnable() {

        @Override
        public void run() throws Exception {
            fCurrentBlock.initialize(fStatusMonitor);
        }

        @Override
        public void handleException(Throwable x) {
        }
    };
    SafeRunner.run(runnable);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) Control(org.eclipse.swt.widgets.Control) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor)

Example 37 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class SpellingConfigurationBlock method performDefaults.

@Override
public void performDefaults() {
    restoreFromPreferences();
    for (Iterator<ISpellingPreferenceBlock> it = fProviderPreferences.values().iterator(); it.hasNext(); ) {
        final ISpellingPreferenceBlock block = it.next();
        ISafeRunnable runnable = new ISafeRunnable() {

            @Override
            public void run() throws Exception {
                block.performDefaults();
            }

            @Override
            public void handleException(Throwable x) {
            }
        };
        SafeRunner.run(runnable);
    }
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) ISpellingPreferenceBlock(org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)

Example 38 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class SpellingConfigurationBlock method canPerformOk.

@Override
public boolean canPerformOk() {
    SpellingEngineDescriptor desc = EditorsUI.getSpellingService().getActiveSpellingEngineDescriptor(fStore);
    // $NON-NLS-1$
    String id = desc != null ? desc.getId() : "";
    final ISpellingPreferenceBlock block = fProviderPreferences.get(id);
    if (block == null)
        return true;
    final Boolean[] result = new Boolean[] { Boolean.TRUE };
    ISafeRunnable runnable = new ISafeRunnable() {

        @Override
        public void run() throws Exception {
            result[0] = Boolean.valueOf(block.canPerformOk());
        }

        @Override
        public void handleException(Throwable x) {
        }
    };
    SafeRunner.run(runnable);
    return result[0].booleanValue();
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SpellingEngineDescriptor(org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor) ISpellingPreferenceBlock(org.eclipse.ui.texteditor.spelling.ISpellingPreferenceBlock)

Example 39 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class AbstractTextSearchViewPage method showMatch.

private void showMatch(final Match match, final boolean activateEditor) {
    ISafeRunnable runnable = new ISafeRunnable() {

        @Override
        public void handleException(Throwable exception) {
            if (exception instanceof PartInitException) {
                PartInitException pie = (PartInitException) exception;
                ErrorDialog.openError(getSite().getShell(), SearchMessages.DefaultSearchViewPage_show_match, SearchMessages.DefaultSearchViewPage_error_no_editor, pie.getStatus());
            }
        }

        @Override
        public void run() throws Exception {
            IRegion location = getCurrentMatchLocation(match);
            showMatch(match, location.getOffset(), location.getLength(), activateEditor);
        }
    };
    SafeRunner.run(runnable);
}
Also used : ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) PartInitException(org.eclipse.ui.PartInitException) IRegion(org.eclipse.jface.text.IRegion)

Example 40 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project eclipse.platform.text by eclipse.

the class ResourceTextFileBufferManager method createEmptyDocument.

public IDocument createEmptyDocument(final IFile file) {
    IDocument documentFromFactory = createEmptyDocumentFromFactory(file);
    final IDocument document;
    if (documentFromFactory != null)
        document = documentFromFactory;
    else
        document = new SynchronizableDocument();
    // Set the initial line delimiter
    if (document instanceof IDocumentExtension4) {
        String initalLineDelimiter = getLineDelimiterPreference(file);
        if (initalLineDelimiter != null)
            ((IDocumentExtension4) document).setInitialLineDelimiter(initalLineDelimiter);
    }
    final IDocumentSetupParticipant[] participants = ((ResourceExtensionRegistry) fRegistry).getDocumentSetupParticipants(file);
    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, file.getFullPath(), LocationKind.IFILE);
                    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)

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