Search in sources :

Example 16 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class KShortestPathsFinderTest method doTest.

private static void doTest(Map<String, String> graph, final String start, final String finish, final int k, String... expectedPaths) {
    Graph<String> generator = initGraph(graph);
    List<List<String>> paths = getAlgorithmsInstance().findKShortestPaths(generator, start, finish, k, new EmptyProgressIndicator(ModalityState.NON_MODAL));
    List<String> pathStrings = new ArrayList<>();
    Set<Integer> sizes = new HashSet<>();
    for (List<String> path : paths) {
        pathStrings.add(StringUtil.join(path, ""));
        sizes.add(path.size());
    }
    if (sizes.size() != paths.size()) {
        UsefulTestCase.assertSameElements(pathStrings, expectedPaths);
    } else {
        UsefulTestCase.assertOrderedEquals(pathStrings, expectedPaths);
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator)

Example 17 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class PersistenceStressTest method testReadWrite.

public void testReadWrite() throws Exception {
    List<Future<Boolean>> futures = new ArrayList<>();
    for (PersistentHashMap<String, Record> map : myMaps) {
        Future<Boolean> submit = submit(map);
        futures.add(submit);
    }
    Future<?> waitFuture = myThreadPool.submit(() -> {
        try {
            while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
                Thread.sleep(100);
                myMaps.forEach(PersistentHashMap::dropMemoryCaches);
            }
        } catch (InterruptedException ignore) {
        }
    });
    List<VirtualFile> files = new ArrayList<>();
    for (int i = 0; i < 100; i++) {
        File file = FileUtil.createTempFile("", ".txt");
        VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
        assertNotNull(virtualFile);
        PlatformTestCase.setFileText(virtualFile, "foo bar");
        files.add(virtualFile);
    }
    FileBasedIndexImpl index = (FileBasedIndexImpl) FileBasedIndex.getInstance();
    while (ContainerUtil.find(futures, STILL_RUNNING) != null) {
        Thread.sleep(100);
        CacheUpdateRunner.processFiles(new EmptyProgressIndicator(), true, files, getProject(), content -> index.indexFileContent(getProject(), content));
    }
    for (Future<Boolean> future : futures) {
        assertTrue(future.get());
    }
    waitFuture.get();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) FileBasedIndexImpl(com.intellij.util.indexing.FileBasedIndexImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 18 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class PluginManagerMain method loadPluginsFromHostInBackground.

/**
   * Start a new thread which downloads new list of plugins from the site in
   * the background and updates a list of plugins in the table.
   */
protected void loadPluginsFromHostInBackground() {
    setDownloadStatus(true);
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        final List<IdeaPluginDescriptor> list = ContainerUtil.newArrayList();
        final Map<String, String> errors = ContainerUtil.newLinkedHashMap();
        ProgressIndicator indicator = new EmptyProgressIndicator();
        List<String> hosts = RepositoryHelper.getPluginHosts();
        Set<PluginId> unique = ContainerUtil.newHashSet();
        for (String host : hosts) {
            try {
                if (host == null || acceptHost(host)) {
                    List<IdeaPluginDescriptor> plugins = RepositoryHelper.loadPlugins(host, indicator);
                    for (IdeaPluginDescriptor plugin : plugins) {
                        if (unique.add(plugin.getPluginId())) {
                            list.add(plugin);
                        }
                    }
                }
            } catch (FileNotFoundException e) {
                LOG.info(host, e);
            } catch (IOException e) {
                LOG.info(host, e);
                if (host != ApplicationInfoEx.getInstanceEx().getBuiltinPluginsUrl()) {
                    errors.put(host, String.format("'%s' for '%s'", e.getMessage(), host));
                }
            }
        }
        UIUtil.invokeLaterIfNeeded(() -> {
            setDownloadStatus(false);
            if (!list.isEmpty()) {
                InstalledPluginsState state = InstalledPluginsState.getInstance();
                for (IdeaPluginDescriptor descriptor : list) {
                    state.onDescriptorDownload(descriptor);
                }
                modifyPluginsList(list);
                propagateUpdates(list);
            }
            if (!errors.isEmpty()) {
                String message = IdeBundle.message("error.list.of.plugins.was.not.loaded", StringUtil.join(errors.keySet(), ", "), StringUtil.join(errors.values(), ",\n"));
                String title = IdeBundle.message("title.plugins");
                String ok = CommonBundle.message("button.retry"), cancel = CommonBundle.getCancelButtonText();
                if (Messages.showOkCancelDialog(message, title, ok, cancel, Messages.getErrorIcon()) == Messages.OK) {
                    loadPluginsFromHostInBackground();
                }
            }
        });
    });
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) PluginId(com.intellij.openapi.extensions.PluginId)

Example 19 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class BackgroundTaskUtil method executeOnPooledThread.

@NotNull
@CalledInAny
public static ProgressIndicator executeOnPooledThread(@NotNull Consumer<ProgressIndicator> task, @NotNull Disposable parent, @NotNull ModalityState modalityState) {
    ProgressIndicator indicator = new EmptyProgressIndicator(modalityState);
    Disposable disposable = new Disposable() {

        @Override
        public void dispose() {
            if (indicator.isRunning())
                indicator.cancel();
        }
    };
    Disposer.register(parent, disposable);
    indicator.start();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            try {
                task.consume(indicator);
            } finally {
                indicator.stop();
                Disposer.dispose(disposable);
            }
        }, indicator);
    });
    return indicator;
}
Also used : Disposable(com.intellij.openapi.Disposable) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CalledInAny(org.jetbrains.annotations.CalledInAny) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with EmptyProgressIndicator

use of com.intellij.openapi.progress.EmptyProgressIndicator in project intellij-community by JetBrains.

the class CommitSelectionListener method processEvent.

public void processEvent() {
    int rows = myGraphTable.getSelectedRowCount();
    if (rows < 1) {
        stopLoading();
        onEmptySelection();
    } else {
        onSelection(myGraphTable.getSelectedRows());
        startLoading();
        final EmptyProgressIndicator indicator = new EmptyProgressIndicator();
        myLastRequest = indicator;
        List<Integer> selectionToLoad = getSelectionToLoad();
        myLogData.getCommitDetailsGetter().loadCommitsData(myGraphTable.getModel().convertToCommitIds(selectionToLoad), detailsList -> {
            if (myLastRequest == indicator && !(indicator.isCanceled())) {
                LOG.assertTrue(selectionToLoad.size() == detailsList.size(), "Loaded incorrect number of details " + detailsList + " for selection " + selectionToLoad);
                myLastRequest = null;
                onDetailsLoaded(detailsList);
                stopLoading();
            }
        }, indicator);
    }
}
Also used : EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator)

Aggregations

EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)46 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)14 NotNull (org.jetbrains.annotations.NotNull)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 IOException (java.io.IOException)6 ProgressManager (com.intellij.openapi.progress.ProgressManager)5 Test (org.junit.Test)5 StudioProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.StudioProgressIndicatorAdapter)4 Processor (com.intellij.util.Processor)4 File (java.io.File)4 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)3 DiffLog (com.intellij.psi.impl.source.text.DiffLog)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Future (java.util.concurrent.Future)3 Nullable (org.jetbrains.annotations.Nullable)3 Disposable (com.intellij.openapi.Disposable)2 ApplicationManager (com.intellij.openapi.application.ApplicationManager)2 Logger (com.intellij.openapi.diagnostic.Logger)2 PluginId (com.intellij.openapi.extensions.PluginId)2