Search in sources :

Example 31 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project translationstudio8 by heartsome.

the class TmImporter method runExtension.

/**
	 * 加载记忆库匹配实现 ;
	 */
private void runExtension() {
    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMIMPORTER_EXTENSION_ID);
    try {
        for (IConfigurationElement e : config) {
            final Object o = e.createExecutableExtension("class");
            if (o instanceof ITmImporter) {
                ISafeRunnable runnable = new ISafeRunnable() {

                    public void handleException(Throwable exception) {
                        logger.error(Messages.getString("importer.TmImporter.logger1"), exception);
                    }

                    public void run() throws Exception {
                        tmImporter = (ITmImporter) o;
                    }
                };
                SafeRunner.run(runnable);
            }
        }
    } catch (CoreException ex) {
        logger.error(Messages.getString("importer.TmImporter.logger1"), ex);
    }
}
Also used : ITmImporter(net.heartsome.cat.ts.tm.importer.extension.ITmImporter) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 32 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project translationstudio8 by heartsome.

the class TmMatcher method runExtension.

/**
	 * 加哉记忆库匹配实现 ;
	 */
private void runExtension() {
    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(TMMATCH_EXTENSION_ID);
    try {
        for (IConfigurationElement e : config) {
            final Object o = e.createExecutableExtension("class");
            if (o instanceof ITmMatch) {
                ISafeRunnable runnable = new ISafeRunnable() {

                    public void handleException(Throwable exception) {
                        logger.error(Messages.getString("match.TmMatcher.logger1"), exception);
                    }

                    public void run() throws Exception {
                        tmTranslation = (ITmMatch) o;
                    }
                };
                SafeRunner.run(runnable);
            }
        }
    } catch (CoreException ex) {
        logger.error(Messages.getString("match.TmMatcher.logger1"), ex);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) ITmMatch(net.heartsome.cat.ts.tm.match.extension.ITmMatch)

Example 33 with ISafeRunnable

use of org.eclipse.core.runtime.ISafeRunnable in project translationstudio8 by heartsome.

the class SimpleMatcherFactory method runExtension.

/**
	 * 加载记忆库匹配实现 ;
	 */
private void runExtension() {
    IConfigurationElement[] config = Platform.getExtensionRegistry().getConfigurationElementsFor(EXTENSION_ID);
    try {
        for (IConfigurationElement e : config) {
            final Object o = e.createExecutableExtension("class");
            if (o instanceof ISimpleMatcher) {
                ISafeRunnable runnable = new ISafeRunnable() {

                    public void handleException(Throwable exception) {
                        logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), exception);
                    }

                    public void run() throws Exception {
                        ISimpleMatcher simpleMatcher = (ISimpleMatcher) o;
                        matchers.add(simpleMatcher);
                    }
                };
                SafeRunner.run(runnable);
            }
        }
    } catch (CoreException ex) {
        logger.error(Messages.getString("simpleMatch.SimpleMatcherFactory.logger1"), ex);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement)

Example 34 with ISafeRunnable

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

the class HyperlinkDetectorDescriptor method createHyperlinkDetectorImplementation.

/**
 * Creates a new {@link IHyperlinkDetector}.
 *
 * @return the hyperlink detector or <code>null</code> if the plug-in isn't loaded yet
 * @throws CoreException if a failure occurred during creation
 * @since 3.9
 */
public IHyperlinkDetector createHyperlinkDetectorImplementation() throws CoreException {
    final Throwable[] exception = new Throwable[1];
    final IHyperlinkDetector[] result = new IHyperlinkDetector[1];
    String message = NLSUtility.format(EditorMessages.Editor_error_HyperlinkDetector_couldNotCreate_message, new String[] { getId(), fElement.getContributor().getName() });
    ISafeRunnable code = new SafeRunnable(message) {

        @Override
        public void run() throws Exception {
            String pluginId = fElement.getContributor().getName();
            boolean isPlugInActivated = Platform.getBundle(pluginId).getState() == Bundle.ACTIVE;
            if (isPlugInActivated || canActivatePlugIn())
                result[0] = (IHyperlinkDetector) fElement.createExecutableExtension(CLASS_ATTRIBUTE);
        }

        @Override
        public void handleException(Throwable ex) {
            super.handleException(ex);
            exception[0] = ex;
        }
    };
    SafeRunner.run(code);
    if (exception[0] == null)
        return result[0];
    throw new CoreException(new Status(IStatus.ERROR, TextEditorPlugin.PLUGIN_ID, IStatus.OK, message, exception[0]));
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) CoreException(org.eclipse.core.runtime.CoreException) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable) SafeRunnable(org.eclipse.jface.util.SafeRunnable) ISafeRunnable(org.eclipse.core.runtime.ISafeRunnable)

Example 35 with ISafeRunnable

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

the class SpellingConfigurationBlock method dispose.

@Override
public void dispose() {
    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.dispose();
            }

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

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