Search in sources :

Example 6 with Application

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

the class LongRunningReadTask method runWithWriteActionPriority.

/**
     * Execute action with immediate stop when write lock is required.
     *
     * {@link ProgressIndicatorUtils#runWithWriteActionPriority(Runnable)}
     *
     * @param indicator
     * @param action
     */
public static void runWithWriteActionPriority(@NotNull final ProgressIndicator indicator, @NotNull final Runnable action) {
    ApplicationAdapter listener = new ApplicationAdapter() {

        @Override
        public void beforeWriteActionStart(Object action) {
            indicator.cancel();
        }
    };
    final Application application = ApplicationManager.getApplication();
    try {
        application.addApplicationListener(listener);
        ProgressManager.getInstance().runProcess(new Runnable() {

            @Override
            public void run() {
                application.runReadAction(action);
            }
        }, indicator);
    } finally {
        application.removeApplicationListener(listener);
    }
}
Also used : ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) Application(com.intellij.openapi.application.Application)

Example 7 with Application

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

the class LiveProvider method getEarliestBunchInIntervalImpl.

private Fragment getEarliestBunchInIntervalImpl(long earliestRevision, final long oldestRevision, final int desirableSize, final boolean includeYoungest, final boolean includeOldest, final long earliestToTake) throws VcsException {
    if ((myEarliestRevisionWasAccessed) || ((oldestRevision == myYoungestRevision) && ((!includeYoungest) || (!includeOldest)))) {
        return null;
    }
    final SVNRevision youngRevision = (earliestRevision == -1) ? SVNRevision.HEAD : SVNRevision.create(earliestRevision);
    final Ref<List<CommittedChangeList>> refToList = new Ref<>();
    final Ref<VcsException> exceptionRef = new Ref<>();
    final Runnable loader = () -> {
        try {
            refToList.set(myLoader.loadInterval(youngRevision, SVNRevision.create(oldestRevision), desirableSize, includeYoungest, includeOldest));
        } catch (VcsException e) {
            exceptionRef.set(e);
        }
    };
    final Application application = ApplicationManager.getApplication();
    if (application.isUnitTestMode() || !application.isDispatchThread()) {
        loader.run();
    } else {
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProgressIndicator ind = ProgressManager.getInstance().getProgressIndicator();
            if (ind != null) {
                ind.setText(SvnBundle.message("progress.live.provider.loading.revisions.details.text"));
            }
            loader.run();
        }, SvnBundle.message("progress.live.provider.loading.revisions.text"), false, myVcs.getProject());
    }
    if (!exceptionRef.isNull()) {
        final VcsException e = exceptionRef.get();
        if (isElementNotFound(e)) {
            // occurs when target URL is deleted in repository
            // try to find latest existent revision. expensive ...
            final LatestExistentSearcher searcher = new LatestExistentSearcher(oldestRevision, myYoungestRevision, (oldestRevision != 0), myVcs, myLocation.toSvnUrl(), myRepositoryUrl);
            final long existent = searcher.getLatestExistent();
            if ((existent == -1) || (existent == earliestRevision)) {
                myEarliestRevisionWasAccessed = true;
                return null;
            }
            return getEarliestBunchInIntervalImpl(existent, oldestRevision, includeYoungest ? desirableSize : (desirableSize + 1), true, includeOldest, Math.min(existent, earliestRevision));
        }
        throw e;
    }
    final List<CommittedChangeList> list = refToList.get();
    if (list.isEmpty()) {
        myEarliestRevisionWasAccessed = (oldestRevision == 0);
        return null;
    }
    if (earliestToTake > 0) {
        for (Iterator<CommittedChangeList> iterator = list.iterator(); iterator.hasNext(); ) {
            final CommittedChangeList changeList = iterator.next();
            if (changeList.getNumber() > earliestToTake)
                iterator.remove();
        }
    }
    myEarliestRevisionWasAccessed = (oldestRevision == 0) && ((list.size() + ((!includeOldest) ? 1 : 0) + ((!includeYoungest) ? 1 : 0)) < desirableSize);
    return new Fragment(Origin.LIVE, list, true, true, null);
}
Also used : CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VcsException(com.intellij.openapi.vcs.VcsException) List(java.util.List) CommittedChangeList(com.intellij.openapi.vcs.versionBrowser.CommittedChangeList) SVNRevision(org.tmatesoft.svn.core.wc.SVNRevision) Application(com.intellij.openapi.application.Application)

Example 8 with Application

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

the class PythonLanguageLevelPusher method updateSdkLanguageLevel.

private void updateSdkLanguageLevel(@NotNull final Project project, final Sdk sdk) {
    final LanguageLevel languageLevel = PythonSdkType.getLanguageLevelForSdk(sdk);
    final VirtualFile[] files = sdk.getRootProvider().getFiles(OrderRootType.CLASSES);
    final Application application = ApplicationManager.getApplication();
    PyUtil.invalidateLanguageLevelCache(project);
    final Runnable markFiles = () -> application.runReadAction(() -> {
        if (project.isDisposed()) {
            return;
        }
        for (VirtualFile file : files) {
            if (file.isValid()) {
                VirtualFile parent = file.getParent();
                boolean suppressSizeLimit = false;
                if (parent != null && parent.getName().equals(PythonSdkType.SKELETON_DIR_NAME)) {
                    suppressSizeLimit = true;
                }
                markRecursively(project, file, languageLevel, suppressSizeLimit);
            }
        }
    });
    if (application.isUnitTestMode()) {
        markFiles.run();
    } else {
        application.executeOnPooledThread(markFiles);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LanguageLevel(com.jetbrains.python.psi.LanguageLevel) Application(com.intellij.openapi.application.Application)

Example 9 with Application

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

the class PyRemoteProcessStarter method startRemoteProcess.

public ProcessHandler startRemoteProcess(@NotNull Sdk sdk, @NotNull GeneralCommandLine commandLine, @Nullable Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
    PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
    if (manager != null) {
        PyRemoteProcessHandlerBase processHandler;
        try {
            processHandler = doStartRemoteProcess(sdk, commandLine, manager, project, pathMapper);
        } catch (ExecutionException e) {
            final Application application = ApplicationManager.getApplication();
            if (application != null && (application.isUnitTestMode() || application.isHeadlessEnvironment())) {
                throw new RuntimeException(e);
            }
            throw new ExecutionException("Can't run remote python interpreter: " + e.getMessage(), e);
        }
        ProcessTerminatedListener.attach(processHandler);
        return processHandler;
    } else {
        throw new PythonRemoteInterpreterManager.PyRemoteInterpreterExecutionException();
    }
}
Also used : PyRemoteProcessHandlerBase(com.jetbrains.python.remote.PyRemoteProcessHandlerBase) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) Application(com.intellij.openapi.application.Application)

Example 10 with Application

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

the class PyPackageManagerImpl method refresh.

@Override
public void refresh() {
    LOG.debug("Refreshing SDK roots and packages cache");
    final Application application = ApplicationManager.getApplication();
    application.invokeLater(() -> {
        final Sdk sdk = getSdk();
        application.runWriteAction(() -> {
            final VirtualFile[] files = sdk.getRootProvider().getFiles(OrderRootType.CLASSES);
            VfsUtil.markDirtyAndRefresh(true, true, true, files);
        });
        PythonSdkType.getInstance().setupSdkPaths(sdk);
    });
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) 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