Search in sources :

Example 86 with Application

use of com.intellij.openapi.application.Application in project intellij-community by JetBrains.

the class InterruptibleActivity method execute.

public final int execute() {
    final Application application = ApplicationManager.getApplication();
    /* TODO: uncomment assertion when problems in Perforce plugin are fixed.
    LOG.assertTrue(!application.isDispatchThread(), "InterruptibleActivity is supposed to be lengthy thus must not block Swing UI thread");
    */
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    application.executeOnPooledThread(() -> {
        try {
            start();
        } finally {
            semaphore.up();
        }
    });
    final int rc = waitForSemaphore(semaphore);
    if (rc != 0) {
        application.executeOnPooledThread(() -> interrupt());
    }
    return rc;
}
Also used : Semaphore(com.intellij.util.concurrency.Semaphore) Application(com.intellij.openapi.application.Application)

Example 87 with Application

use of com.intellij.openapi.application.Application in project android by JetBrains.

the class AppBarConfigurationDialog method generatePreviews.

private void generatePreviews() {
    PsiFile expandedFile = generateXml(false);
    PsiFile collapsedFile = generateXml(true);
    myExpandedPreviewFuture = cancel(myExpandedPreviewFuture);
    myCollapsedPreviewFuture = cancel(myCollapsedPreviewFuture);
    Application application = ApplicationManager.getApplication();
    myExpandedPreviewFuture = application.executeOnPooledThread(() -> updateExpandedImage(expandedFile));
    myCollapsedPreviewFuture = application.executeOnPooledThread(() -> updateCollapsedImage(collapsedFile));
}
Also used : PsiFile(com.intellij.psi.PsiFile) Application(com.intellij.openapi.application.Application)

Example 88 with Application

use of com.intellij.openapi.application.Application in project intellij-plugins by JetBrains.

the class BuiltInFlexCompilerHandler method stopCompilerProcess.

public void stopCompilerProcess() {
    final Runnable runnable = () -> {
        cancelAllCompilations(true);
        closeSocket();
    };
    final Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        application.executeOnPooledThread(runnable);
    } else {
        runnable.run();
    }
}
Also used : Application(com.intellij.openapi.application.Application)

Example 89 with Application

use of com.intellij.openapi.application.Application in project intellij-plugins by JetBrains.

the class FlexCompilationManager method refreshAndFindFileInWriteAction.

static VirtualFile refreshAndFindFileInWriteAction(final String outputFilePath, final String... possibleBaseDirs) {
    final LocalFileSystem localFileSystem = LocalFileSystem.getInstance();
    final Ref<VirtualFile> outputFileRef = new Ref<>();
    final Application app = ApplicationManager.getApplication();
    app.invokeAndWait(() -> outputFileRef.set(app.runWriteAction(new NullableComputable<VirtualFile>() {

        public VirtualFile compute() {
            VirtualFile outputFile = localFileSystem.refreshAndFindFileByPath(outputFilePath);
            //}
            if (outputFile == null) {
                for (final String baseDir : possibleBaseDirs) {
                    outputFile = localFileSystem.refreshAndFindFileByPath(baseDir + "/" + outputFilePath);
                    if (outputFile != null) {
                        break;
                    }
                }
            }
            if (outputFile == null)
                return null;
            // it's important because this file has just been created
            outputFile.refresh(false, false);
            return outputFile;
        }
    })));
    return outputFileRef.get();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Ref(com.intellij.openapi.util.Ref) LocalFileSystem(com.intellij.openapi.vfs.LocalFileSystem) Application(com.intellij.openapi.application.Application)

Example 90 with Application

use of com.intellij.openapi.application.Application in project intellij-plugins by JetBrains.

the class FlexBaseRunner method launchWithSelectedApplication.

public static void launchWithSelectedApplication(final String urlOrPath, final LauncherParameters launcherParams) {
    switch(launcherParams.getLauncherType()) {
        case OSDefault:
            BrowserUtil.open(urlOrPath);
            break;
        case Browser:
            final Runnable runnable1 = () -> BrowserLauncher.getInstance().browse(BrowserUtil.isAbsoluteURL(urlOrPath) ? urlOrPath : VfsUtilCore.pathToUrl(urlOrPath), launcherParams.getBrowser());
            final Application application1 = ApplicationManager.getApplication();
            if (application1.isDispatchThread()) {
                runnable1.run();
            } else {
                application1.invokeLater(runnable1);
            }
            break;
        case Player:
            try {
                if (SystemInfo.isMac) {
                    if (launcherParams.isNewPlayerInstance()) {
                        Runtime.getRuntime().exec(new String[] { ExecUtil.getOpenCommandPath(), "-n", "-a", launcherParams.getPlayerPath(), urlOrPath });
                    } else {
                        Runtime.getRuntime().exec(new String[] { ExecUtil.getOpenCommandPath(), "-a", launcherParams.getPlayerPath(), urlOrPath });
                    }
                } else {
                    Runtime.getRuntime().exec(new String[] { launcherParams.getPlayerPath(), urlOrPath });
                }
            // todo read error stream, report errors
            // todo keep process to be able to kill it on user demand
            } catch (final IOException e) {
                final Runnable runnable2 = () -> Messages.showErrorDialog(FlexBundle.message("cant.launch", urlOrPath, launcherParams.getPlayerPath(), e.getMessage()), CommonBundle.getErrorTitle());
                final Application application2 = ApplicationManager.getApplication();
                if (application2.isDispatchThread()) {
                    runnable2.run();
                } else {
                    application2.invokeLater(runnable2);
                }
            }
            break;
    }
}
Also used : IOException(java.io.IOException) Application(com.intellij.openapi.application.Application)

Aggregations

Application (com.intellij.openapi.application.Application)188 NotNull (org.jetbrains.annotations.NotNull)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 IOException (java.io.IOException)14 Project (com.intellij.openapi.project.Project)13 Nullable (org.jetbrains.annotations.Nullable)12 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)9 ModalityState (com.intellij.openapi.application.ModalityState)8 Ref (com.intellij.openapi.util.Ref)7 ArrayList (java.util.ArrayList)7 List (java.util.List)6 ApplicationImpl (com.intellij.openapi.application.impl.ApplicationImpl)5 ApplicationManager (com.intellij.openapi.application.ApplicationManager)4 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)4 Document (com.intellij.openapi.editor.Document)4 Module (com.intellij.openapi.module.Module)4 Computable (com.intellij.openapi.util.Computable)4 PsiFile (com.intellij.psi.PsiFile)4 File (java.io.File)4 Editor (com.intellij.openapi.editor.Editor)3