Search in sources :

Example 6 with ProgressWindow

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

the class AbstractLayoutCodeProcessor method runLayoutCodeProcess.

private void runLayoutCodeProcess(final Runnable readAction, final Runnable writeAction) {
    final ProgressWindow progressWindow = new ProgressWindow(true, myProject);
    progressWindow.setTitle(myCommandName);
    progressWindow.setText(myProgressText);
    final ModalityState modalityState = ModalityState.current();
    final Runnable process = () -> ApplicationManager.getApplication().runReadAction(readAction);
    Runnable runnable = () -> {
        try {
            ProgressManager.getInstance().runProcess(process, progressWindow);
        } catch (ProcessCanceledException e) {
            return;
        } catch (IndexNotReadyException e) {
            LOG.warn(e);
            return;
        }
        final Runnable writeRunnable = () -> CommandProcessor.getInstance().executeCommand(myProject, () -> {
            try {
                writeAction.run();
                if (myPostRunnable != null) {
                    ApplicationManager.getApplication().invokeLater(myPostRunnable);
                }
            } catch (IndexNotReadyException e) {
                LOG.warn(e);
            }
        }, myCommandName, null);
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            writeRunnable.run();
        } else {
            ApplicationManager.getApplication().invokeLater(writeRunnable, modalityState, myProject.getDisposed());
        }
    };
    if (ApplicationManager.getApplication().isUnitTestMode()) {
        runnable.run();
    } else {
        ApplicationManager.getApplication().executeOnPooledThread(runnable);
    }
}
Also used : ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) ModalityState(com.intellij.openapi.application.ModalityState) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 7 with ProgressWindow

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

the class JavaContentEntriesEditor method addSourceRoots.

private static void addSourceRoots(@NotNull Project project, final ContentEntry[] contentEntries, final Runnable finishRunnable) {
    final HashMap<ContentEntry, Collection<JavaModuleSourceRoot>> entryToRootMap = new HashMap<>();
    final Map<File, ContentEntry> fileToEntryMap = new HashMap<>();
    for (final ContentEntry contentEntry : contentEntries) {
        final VirtualFile file = contentEntry.getFile();
        if (file != null) {
            entryToRootMap.put(contentEntry, null);
            fileToEntryMap.put(VfsUtilCore.virtualToIoFile(file), contentEntry);
        }
    }
    final ProgressWindow progressWindow = new ProgressWindow(true, project);
    final ProgressIndicator progressIndicator = new SmoothProgressAdapter(progressWindow, project);
    final Runnable searchRunnable = () -> {
        final Runnable process = () -> {
            for (final File file : fileToEntryMap.keySet()) {
                progressIndicator.setText(ProjectBundle.message("module.paths.searching.source.roots.progress", file.getPath()));
                final Collection<JavaModuleSourceRoot> roots = JavaSourceRootDetectionUtil.suggestRoots(file);
                entryToRootMap.put(fileToEntryMap.get(file), roots);
            }
        };
        progressWindow.setTitle(ProjectBundle.message("module.paths.searching.source.roots.title"));
        ProgressManager.getInstance().runProcess(process, progressIndicator);
    };
    final Runnable addSourcesRunnable = () -> {
        for (final ContentEntry contentEntry : contentEntries) {
            final Collection<JavaModuleSourceRoot> suggestedRoots = entryToRootMap.get(contentEntry);
            if (suggestedRoots != null) {
                for (final JavaModuleSourceRoot suggestedRoot : suggestedRoots) {
                    final VirtualFile sourceRoot = LocalFileSystem.getInstance().findFileByIoFile(suggestedRoot.getDirectory());
                    final VirtualFile fileContent = contentEntry.getFile();
                    if (sourceRoot != null && fileContent != null && VfsUtilCore.isAncestor(fileContent, sourceRoot, false)) {
                        contentEntry.addSourceFolder(sourceRoot, false, suggestedRoot.getPackagePrefix());
                    }
                }
            }
        }
        if (finishRunnable != null) {
            finishRunnable.run();
        }
    };
    new SwingWorker() {

        @Override
        public Object construct() {
            searchRunnable.run();
            return null;
        }

        @Override
        public void finished() {
            addSourcesRunnable.run();
        }
    }.start();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SmoothProgressAdapter(com.intellij.openapi.progress.util.SmoothProgressAdapter) HashMap(java.util.HashMap) ContentEntry(com.intellij.openapi.roots.ContentEntry) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Collection(java.util.Collection) SwingWorker(com.intellij.util.concurrency.SwingWorker) JavaModuleSourceRoot(com.intellij.ide.util.projectWizard.importSources.JavaModuleSourceRoot) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with ProgressWindow

use of com.intellij.openapi.progress.util.ProgressWindow in project intellij by bazelbuild.

the class ProgressiveTaskWithProgressIndicator method submitTaskWithResult.

/**
 * Runs the given task on the specified executor (defaulting to BlazeExecutor's executor) with a
 * progress dialog.
 */
public <T> ListenableFuture<T> submitTaskWithResult(ProgressiveWithResult<T> progressive) {
    // The progress indicator must be created on the UI thread.
    final ProgressWindow indicator = UIUtil.invokeAndWaitIfNeeded(() -> {
        if (modality == Modality.MODAL) {
            ProgressWindow window = new ProgressWindow(cancelable, project);
            window.setTitle(title);
            return window;
        } else {
            PerformInBackgroundOption backgroundOption = modality == Modality.BACKGROUNDABLE ? PerformInBackgroundOption.DEAF : PerformInBackgroundOption.ALWAYS_BACKGROUND;
            return new BackgroundableProcessIndicator(project, title, backgroundOption, "Cancel", "Cancel", cancelable);
        }
    });
    indicator.setIndeterminate(true);
    indicator.start();
    final ListenableFuture<T> future = executor.submit(() -> ProgressManager.getInstance().runProcess(() -> progressive.compute(indicator), indicator));
    if (cancelable) {
        indicator.addStateDelegate(new AbstractProgressIndicatorExBase() {

            @Override
            public void cancel() {
                super.cancel();
                future.cancel(true);
            }
        });
    }
    return future;
}
Also used : AbstractProgressIndicatorExBase(com.intellij.openapi.progress.util.AbstractProgressIndicatorExBase) ProgressWindow(com.intellij.openapi.progress.util.ProgressWindow) PerformInBackgroundOption(com.intellij.openapi.progress.PerformInBackgroundOption) BackgroundableProcessIndicator(com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)

Aggregations

ProgressWindow (com.intellij.openapi.progress.util.ProgressWindow)8 ModalityState (com.intellij.openapi.application.ModalityState)2 BackgroundableProcessIndicator (com.intellij.openapi.progress.impl.BackgroundableProcessIndicator)2 File (java.io.File)2 NotNull (org.jetbrains.annotations.NotNull)2 IDevice (com.android.ddmlib.IDevice)1 AndroidLocation (com.android.prefs.AndroidLocation)1 RemotePackage (com.android.repository.api.RemotePackage)1 RepoManager (com.android.repository.api.RepoManager)1 StudioDownloader (com.android.tools.idea.sdk.StudioDownloader)1 RepoProgressIndicatorAdapter (com.android.tools.idea.sdk.progress.RepoProgressIndicatorAdapter)1 StudioLoggerProgressIndicator (com.android.tools.idea.sdk.progress.StudioLoggerProgressIndicator)1 DynamicWizard (com.android.tools.idea.wizard.dynamic.DynamicWizard)1 ExecutionException (com.intellij.execution.ExecutionException)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 CapturingAnsiEscapesAwareProcessHandler (com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 BooleanOptionDescription (com.intellij.ide.ui.search.BooleanOptionDescription)1 ChooseByNamePopup (com.intellij.ide.util.gotoByName.ChooseByNamePopup)1 GotoActionItemProvider (com.intellij.ide.util.gotoByName.GotoActionItemProvider)1