Search in sources :

Example 1 with Application

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

the class ProjectFilesUtils method getOrCreateDirectory.

@Nullable
private static VirtualFile getOrCreateDirectory(@NotNull VirtualFile baseDir, @NotNull String directoryPath) {
    final VirtualFile[] srcDir = { baseDir.findFileByRelativePath(directoryPath) };
    if (srcDir[0] == null) {
        Application application = ApplicationManager.getApplication();
        application.invokeAndWait(() -> srcDir[0] = application.runWriteAction((Computable<VirtualFile>) () -> {
            VirtualFile dir;
            try {
                String[] paths = directoryPath.split("/");
                dir = baseDir;
                for (String path : paths) {
                    VirtualFile child = dir.findChild(path);
                    if (child == null) {
                        dir = dir.createChildDirectory(null, path);
                    } else {
                        dir = child;
                    }
                }
            } catch (IOException e) {
                return null;
            }
            return dir;
        }));
    }
    return srcDir[0];
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IOException(java.io.IOException) Application(com.intellij.openapi.application.Application) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Application

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

the class StepikProjectManager method refreshCourse.

private void refreshCourse() {
    if (project == null || root == null) {
        return;
    }
    root.setProject(project);
    executor.execute(() -> {
        StepikApiClient stepikApiClient = authAndGetStepikApiClient();
        if (isAuthenticated()) {
            root.reloadData(project, stepikApiClient);
        }
        ProgressManager.getInstance().run(new Task.Backgroundable(project, "Synchronize Project") {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                if (project.isDisposed()) {
                    return;
                }
                repairProjectFiles(root);
                repairSandbox();
                ApplicationManager.getApplication().invokeLater(() -> {
                    VirtualFileManager.getInstance().syncRefresh();
                    setSelected(selected, false);
                });
            }

            private void repairSandbox() {
                VirtualFile projectDir = project.getBaseDir();
                if (projectDir != null && projectDir.findChild(EduNames.SANDBOX_DIR) == null) {
                    Application application = ApplicationManager.getApplication();
                    ModifiableModuleModel model = application.runReadAction((Computable<ModifiableModuleModel>) () -> ModuleManager.getInstance(project).getModifiableModel());
                    application.invokeLater(() -> application.runWriteAction(() -> {
                        try {
                            new SandboxModuleBuilder(projectDir.getPath()).createModule(model);
                            model.commit();
                        } catch (IOException | ConfigurationException | JDOMException | ModuleWithNameAlreadyExists e) {
                            logger.warn("Failed repair Sandbox", e);
                        }
                    }));
                }
            }
        });
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) StepikAuthManager.authAndGetStepikApiClient(org.stepik.core.stepik.StepikAuthManager.authAndGetStepikApiClient) StepikApiClient(org.stepik.api.client.StepikApiClient) Task(com.intellij.openapi.progress.Task) SandboxModuleBuilder(org.stepik.plugin.projectWizard.idea.SandboxModuleBuilder) ModuleWithNameAlreadyExists(com.intellij.openapi.module.ModuleWithNameAlreadyExists) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) ModifiableModuleModel(com.intellij.openapi.module.ModifiableModuleModel) ConfigurationException(com.intellij.openapi.options.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Application(com.intellij.openapi.application.Application) Computable(com.intellij.openapi.util.Computable)

Example 3 with Application

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

the class StepikPyProjectGenerator method createCourseFromGenerator.

private void createCourseFromGenerator(@NotNull Project project) {
    generator.generateProject(project);
    FileUtil.createDirectory(new File(project.getBasePath(), EduNames.SANDBOX_DIR));
    StepikProjectManager projectManager = StepikProjectManager.getInstance(project);
    if (projectManager == null) {
        logger.warn("failed to generate builders: StepikProjectManager is null");
        return;
    }
    projectManager.setDefaultLang(generator.getDefaultLang());
    StudyNode root = projectManager.getProjectRoot();
    if (root == null) {
        logger.warn("failed to generate builders: Root is null");
        return;
    }
    if (root instanceof StepNode) {
        getOrCreateSrcDirectory(project, (StepNode) root, true);
    } else {
        createSubDirectories(project, generator.getDefaultLang(), root, null);
        VirtualFileManager.getInstance().syncRefresh();
    }
    Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_BACKGROUND, () -> application.runWriteAction(() -> {
        StudyProjectComponent.getInstance(project).registerStudyToolWindow();
        StepikProjectManager.updateAdaptiveSelected(project);
    })));
}
Also used : StepikProjectManager(org.stepik.core.StepikProjectManager) StepNode(org.stepik.core.courseFormat.StepNode) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Application(com.intellij.openapi.application.Application) StudyNode(org.stepik.core.courseFormat.StudyNode)

Example 4 with Application

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

the class SvnAuthenticationNotifier method clearAuthenticationDirectory.

public static void clearAuthenticationDirectory(@NotNull SvnConfiguration configuration) {
    final File authDir = new File(configuration.getConfigurationDirectory(), "auth");
    if (authDir.exists()) {
        final Runnable process = () -> {
            final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator();
            if (ind != null) {
                ind.setIndeterminate(true);
                ind.setText("Clearing stored credentials in " + authDir.getAbsolutePath());
            }
            final File[] files = authDir.listFiles((dir, name) -> ourAuthKinds.contains(name));
            for (File dir : files) {
                if (ind != null) {
                    ind.setText("Deleting " + dir.getAbsolutePath());
                }
                FileUtil.delete(dir);
            }
        };
        final Application application = ApplicationManager.getApplication();
        if (application.isUnitTestMode() || !application.isDispatchThread()) {
            process.run();
        } else {
            ProgressManager.getInstance().runProcessWithProgressSynchronously(process, "button.text.clear.authentication.cache", false, configuration.getProject());
        }
    }
}
Also used : IdeFrame(com.intellij.openapi.wm.IdeFrame) Application(com.intellij.openapi.application.Application) MessageType(com.intellij.openapi.ui.MessageType) ScheduledFuture(java.util.concurrent.ScheduledFuture) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ModalityState(com.intellij.openapi.application.ModalityState) Balloon(com.intellij.openapi.ui.popup.Balloon) CommonProxy(com.intellij.util.proxy.CommonProxy) java.net(java.net) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) SVNAuthentication(org.tmatesoft.svn.core.auth.SVNAuthentication) ProgressManager(com.intellij.openapi.progress.ProgressManager) ThreeState(com.intellij.util.ThreeState) org.jetbrains.idea.svn(org.jetbrains.idea.svn) NotificationType(com.intellij.notification.NotificationType) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) ApplicationManager(com.intellij.openapi.application.ApplicationManager) WindowManagerEx(com.intellij.openapi.wm.ex.WindowManagerEx) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) RelativePoint(com.intellij.ui.awt.RelativePoint) SvnBindException(org.jetbrains.idea.svn.commandLine.SvnBindException) java.util(java.util) VcsBalloonProblemNotifier(com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier) Project(com.intellij.openapi.project.Project) NamedRunnable(com.intellij.openapi.util.NamedRunnable) InfoClient(org.jetbrains.idea.svn.info.InfoClient) JobScheduler(com.intellij.concurrency.JobScheduler) HttpConfigurable(com.intellij.util.net.HttpConfigurable) ClientFactory(org.jetbrains.idea.svn.api.ClientFactory) SVNCancelException(org.tmatesoft.svn.core.SVNCancelException) SVNURLUtil(org.tmatesoft.svn.core.internal.util.SVNURLUtil) SVNException(org.tmatesoft.svn.core.SVNException) StringUtil(com.intellij.openapi.util.text.StringUtil) Info(org.jetbrains.idea.svn.info.Info) SVNAuthenticationException(org.tmatesoft.svn.core.SVNAuthenticationException) File(java.io.File) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) ISVNAuthenticationManager(org.tmatesoft.svn.core.auth.ISVNAuthenticationManager) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) SVNURL(org.tmatesoft.svn.core.SVNURL) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) GenericNotifierImpl(com.intellij.openapi.vcs.impl.GenericNotifierImpl) SvnTarget(org.tmatesoft.svn.core.wc2.SvnTarget) javax.swing(javax.swing) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NamedRunnable(com.intellij.openapi.util.NamedRunnable) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Application(com.intellij.openapi.application.Application)

Example 5 with Application

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

the class BaseSpellChecker method doLoadDictionaryAsync.

private void doLoadDictionaryAsync(Loader loader, Consumer<Dictionary> consumer) {
    StartupManager.getInstance(myProject).runWhenProjectIsInitialized(() -> {
        LOG.debug("Loading " + loader.getName());
        Application app = ApplicationManager.getApplication();
        app.executeOnPooledThread(() -> {
            if (app.isDisposed())
                return;
            CompressedDictionary dictionary = CompressedDictionary.create(loader, transform);
            LOG.debug(loader.getName() + " loaded!");
            consumer.consume(dictionary);
            while (!myDictionariesToLoad.isEmpty()) {
                if (app.isDisposed())
                    return;
                Pair<Loader, Consumer<Dictionary>> nextDictionary = myDictionariesToLoad.remove(0);
                Loader nextDictionaryLoader = nextDictionary.getFirst();
                dictionary = CompressedDictionary.create(nextDictionaryLoader, transform);
                LOG.debug(nextDictionaryLoader.getName() + " loaded!");
                nextDictionary.getSecond().consume(dictionary);
            }
            LOG.debug("Loading finished, restarting daemon...");
            myLoadingDictionaries.set(false);
            UIUtil.invokeLaterIfNeeded(() -> {
                if (app.isDisposed())
                    return;
                for (final Project project : ProjectManager.getInstance().getOpenProjects()) {
                    if (project.isInitialized() && project.isOpen() && !project.isDefault()) {
                        DaemonCodeAnalyzer instance = DaemonCodeAnalyzer.getInstance(project);
                        if (instance != null)
                            instance.restart();
                    }
                }
            });
        });
    });
}
Also used : Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) CompressedDictionary(com.intellij.spellchecker.compress.CompressedDictionary) DaemonCodeAnalyzer(com.intellij.codeInsight.daemon.DaemonCodeAnalyzer) Loader(com.intellij.spellchecker.dictionary.Loader) 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