Search in sources :

Example 91 with Application

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

the class RenderActionQueue method execute.

private void execute(RenderAction renderAction) {
    if (suspended) {
        assert !wasPending;
        wasPending = true;
        return;
    }
    renderAction.result.doWhenProcessed(this);
    Application application = ApplicationManager.getApplication();
    boolean isDispatchThread = application.isDispatchThread();
    if (renderAction.isNeedEdt()) {
        if (isDispatchThread) {
            renderAction.run();
        } else {
            application.invokeLater(renderAction);
        }
    } else {
        if (isDispatchThread) {
            application.executeOnPooledThread(renderAction);
        } else {
            renderAction.run();
        }
    }
}
Also used : Application(com.intellij.openapi.application.Application)

Example 92 with Application

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

the class AndroidGradleNotification method showBalloon.

public void showBalloon(@NotNull String title, @NotNull String text, @NotNull NotificationType type, @NotNull NotificationGroup group, @Nullable NotificationListener listener) {
    Notification notification = group.createNotification(title, text, type, listener);
    Runnable notificationTask = () -> {
        if (!myProject.isDisposed() && myProject.isOpen()) {
            Notification old = myNotification;
            if (old != null) {
                boolean similar = Objects.equal(notification.getContent(), old.getContent());
                if (similar) {
                    old.expire();
                }
            }
            myNotification = notification;
            notification.notify(myProject);
        }
    };
    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        notificationTask.run();
    } else {
        application.invokeLater(notificationTask);
    }
}
Also used : Application(com.intellij.openapi.application.Application) Notification(com.intellij.notification.Notification)

Example 93 with Application

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

the class ForcedPluginPreviewVersionUpgradeDialog method setTestDialog.

@TestOnly
public static TestDialog setTestDialog(@NotNull TestDialog newValue) {
    Application application = ApplicationManager.getApplication();
    if (application != null) {
        getLog().assertTrue(application.isUnitTestMode(), "This method is available for tests only");
    }
    TestDialog oldValue = ourTestImplementation;
    ourTestImplementation = newValue;
    return oldValue;
}
Also used : TestDialog(com.intellij.openapi.ui.TestDialog) Application(com.intellij.openapi.application.Application) TestOnly(org.jetbrains.annotations.TestOnly)

Example 94 with Application

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

the class BuildVariantView method updateContents.

public void updateContents() {
    GradleSyncState syncState = GradleSyncState.getInstance(myProject);
    if (syncState.isSyncInProgress() && !syncState.isSyncSkipped()) {
        projectImportStarted();
        return;
    }
    final List<Object[]> rows = Lists.newArrayList();
    final List<BuildVariantItem[]> variantNamesPerRow = Lists.newArrayList();
    for (Module module : getGradleModulesWithAndroidProjects()) {
        AndroidFacet androidFacet = AndroidFacet.getInstance(module);
        NdkFacet ndkFacet = NdkFacet.getInstance(module);
        // getGradleModules() returns only relevant modules.
        assert androidFacet != null || ndkFacet != null;
        String variantName = null;
        if (androidFacet != null) {
            JpsAndroidModuleProperties facetProperties = androidFacet.getProperties();
            variantName = facetProperties.SELECTED_BUILD_VARIANT;
        }
        BuildVariantItem[] variantNames = getVariantItems(module);
        if (variantNames != null) {
            if (androidFacet != null) {
                AndroidModuleModel androidModel = AndroidModuleModel.get(module);
                // AndroidModel may be null when applying a quick fix (e.g. "Fix Gradle version")
                if (androidModel != null) {
                    variantName = androidModel.getSelectedVariant().getName();
                }
            } else {
                // As only the modules backed by either AndroidGradleModel or NativeAndroidGradleModel are shown in the Build Variants View,
                // when a module is not backed by AndroidGradleModel, it surely contains a valid NativeAndroidGradleModel.
                NdkModuleModel ndkModuleModel = NdkModuleModel.get(module);
                if (ndkModuleModel != null) {
                    variantName = ndkModuleModel.getSelectedVariant().getName();
                }
            }
            variantNamesPerRow.add(variantNames);
        }
        if (variantName != null) {
            Object[] row = { module, variantName };
            rows.add(row);
        }
    }
    Runnable setModelTask = () -> getVariantsTable().setModel(rows, variantNamesPerRow);
    Application application = ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        setModelTask.run();
    } else {
        application.invokeLater(setModelTask);
    }
}
Also used : NdkFacet(com.android.tools.idea.gradle.project.facet.ndk.NdkFacet) JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) GradleSyncState(com.android.tools.idea.gradle.project.sync.GradleSyncState) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) Module(com.intellij.openapi.module.Module) NdkModuleModel(com.android.tools.idea.gradle.project.model.NdkModuleModel) Application(com.intellij.openapi.application.Application)

Example 95 with Application

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

the class InstallOperation method promptToRetry.

/**
   * Shows a retry prompt. Throws an exception to stop the setup process if the user preses cancel or returns normally otherwise.
   */
protected final void promptToRetry(@NotNull final String prompt, @NotNull String failureDescription, @Nullable Exception e) throws WizardException {
    final AtomicBoolean response = new AtomicBoolean(false);
    Application application = ApplicationManager.getApplication();
    application.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            int i = Messages.showYesNoDialog(null, prompt, "Android Studio Setup", "Retry", "Cancel", Messages.getErrorIcon());
            response.set(i == Messages.YES);
        }
    }, application.getAnyModalityState());
    if (!response.get()) {
        Throwables.propagateIfInstanceOf(e, WizardException.class);
        throw new WizardException(failureDescription, e);
    } else {
        myContext.print(failureDescription + "\n", ConsoleViewContentType.ERROR_OUTPUT);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) 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