Search in sources :

Example 6 with ProgressIndicator

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

the class SvnCheckoutProvider method doImport.

public static void doImport(final Project project, final File target, final SVNURL url, final Depth depth, final boolean includeIgnored, final String message) {
    final Ref<String> errorMessage = new Ref<>();
    final SvnVcs vcs = SvnVcs.getInstance(project);
    final String targetPath = FileUtil.toSystemIndependentName(target.getAbsolutePath());
    ExclusiveBackgroundVcsAction.run(project, () -> ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        final FileIndexFacade facade = PeriodicalTasksCloser.getInstance().safeGetService(project, FileIndexFacade.class);
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        try {
            progressIndicator.setText(message("progress.text.import", target.getAbsolutePath()));
            final VirtualFile targetVf = SvnUtil.getVirtualFile(targetPath);
            if (targetVf == null) {
                errorMessage.set("Can not find file: " + targetPath);
            } else {
                final boolean isInContent = getApplication().runReadAction((Computable<Boolean>) () -> facade.isInContent(targetVf));
                CommitEventHandler handler = new IdeaCommitHandler(progressIndicator);
                boolean useFileFilter = !project.isDefault() && isInContent;
                ISVNCommitHandler commitHandler = useFileFilter ? new MyFilter(LocalFileSystem.getInstance(), new SvnExcludingIgnoredOperation.Filter(project)) : null;
                long revision = vcs.getFactoryFromSettings().createImportClient().doImport(target, url, depth, message, includeIgnored, handler, commitHandler);
                if (revision > 0) {
                    StatusBar.Info.set(message("status.text.comitted.revision", revision), project);
                }
            }
        } catch (VcsException e) {
            errorMessage.set(e.getMessage());
        }
    }, message("message.title.import"), true, project));
    if (!errorMessage.isNull()) {
        showErrorDialog(message("message.text.cannot.import", errorMessage.get()), message("message.title.import"));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) IdeaCommitHandler(org.jetbrains.idea.svn.checkin.IdeaCommitHandler) ISVNCommitHandler(org.tmatesoft.svn.core.wc.ISVNCommitHandler) CommitEventHandler(org.jetbrains.idea.svn.checkin.CommitEventHandler) SvnVcs(org.jetbrains.idea.svn.SvnVcs) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SvnExcludingIgnoredOperation(org.jetbrains.idea.svn.actions.SvnExcludingIgnoredOperation) VcsException(com.intellij.openapi.vcs.VcsException) Computable(com.intellij.openapi.util.Computable) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade)

Example 7 with ProgressIndicator

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

the class ShowPropertiesDiffAction method createHandler.

@NotNull
private static PropertyConsumer createHandler(SVNRevision revision, @NotNull final List<PropertyData> lines) {
    final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
    if (indicator != null) {
        indicator.checkCanceled();
        indicator.setText(SvnBundle.message("show.properties.diff.progress.text.revision.information", revision.toString()));
    }
    return new PropertyConsumer() {

        public void handleProperty(final File path, final PropertyData property) throws SVNException {
            registerProperty(property);
        }

        public void handleProperty(final SVNURL url, final PropertyData property) throws SVNException {
            registerProperty(property);
        }

        public void handleProperty(final long revision, final PropertyData property) throws SVNException {
        // revision properties here
        }

        private void registerProperty(@NotNull PropertyData property) {
            if (indicator != null) {
                indicator.checkCanceled();
                indicator.setText2(SvnBundle.message("show.properties.diff.progress.text2.property.information", property.getName()));
            }
            lines.add(property);
        }
    };
}
Also used : PropertyConsumer(org.jetbrains.idea.svn.properties.PropertyConsumer) PropertyData(org.jetbrains.idea.svn.properties.PropertyData) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) SVNURL(org.tmatesoft.svn.core.SVNURL) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with ProgressIndicator

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

the class PydevConsoleCommunication method execInterpreter.

/**
   * Executes a given line in the interpreter.
   *
   * @param command the command to be executed in the client
   */
public void execInterpreter(final ConsoleCodeFragment command, final Function<InterpreterResponse, Object> onResponseReceived) {
    if (myDebugCommunication != null && myDebugCommunication.isSuspended()) {
        myDebugCommunication.execInterpreter(command, onResponseReceived);
        //TODO: handle text input and other cases
        return;
    }
    nextResponse = null;
    if (waitingForInput) {
        inputReceived = command.getText();
        waitingForInput = false;
    //the thread that we started in the last exec is still alive if we were waiting for an input.
    } else {
        //create a thread that'll keep locked until an answer is received from the server.
        new Task.Backgroundable(myProject, "REPL Communication", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                boolean needInput = false;
                try {
                    Pair<String, Boolean> executed = null;
                    //the 1st time we'll do a connection attempt, we can try to connect n times (until the 1st time the connection
                    //is accepted) -- that's mostly because the server may take a while to get started.
                    int commAttempts = 0;
                    while (true) {
                        if (indicator.isCanceled()) {
                            return;
                        }
                        executed = exec(command);
                        //executed.o1 is not null only if we had an error
                        String refusedConnPattern = "Failed to read servers response";
                        // the XML-RPC library)
                        if (executed.first != null && executed.first.indexOf(refusedConnPattern) != -1) {
                            if (firstCommWorked) {
                                break;
                            } else {
                                if (commAttempts < MAX_ATTEMPTS) {
                                    commAttempts += 1;
                                    Thread.sleep(250);
                                    executed = Pair.create("", executed.second);
                                } else {
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    //unreachable code!! -- commented because eclipse will complain about it
                    //throw new RuntimeException("Can never get here!");
                    }
                    firstCommWorked = true;
                    boolean more = executed.second;
                    nextResponse = new InterpreterResponse(more, needInput);
                } catch (Exception e) {
                    nextResponse = new InterpreterResponse(false, needInput);
                }
            }
        }.queue();
        //busy loop waiting for the answer (or having the console die).
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
            progressIndicator.setText("Waiting for REPL response with " + (int) (TIMEOUT / 10e8) + "s timeout");
            final long startTime = System.nanoTime();
            while (nextResponse == null) {
                if (progressIndicator.isCanceled()) {
                    LOG.debug("Canceled");
                    nextResponse = new InterpreterResponse(false, false);
                }
                final long time = System.nanoTime() - startTime;
                progressIndicator.setFraction(((double) time) / TIMEOUT);
                if (time > TIMEOUT) {
                    LOG.debug("Timeout exceeded");
                    nextResponse = new InterpreterResponse(false, false);
                }
                synchronized (lock2) {
                    try {
                        lock2.wait(20);
                    } catch (InterruptedException e) {
                        LOG.error(e);
                    }
                }
            }
            if (nextResponse.more) {
                myNeedsMore = true;
                notifyCommandExecuted(true);
            }
            onResponseReceived.fun(nextResponse);
        }, "Waiting for REPL response", true, myProject);
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) XmlRpcException(org.apache.xmlrpc.XmlRpcException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) Pair(com.intellij.openapi.util.Pair)

Example 9 with ProgressIndicator

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

the class SpellCheckerDictionaryGenerator method generate.

public void generate() {
    ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
        ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
        // let's do result a bit more predictable
        // ruby dictionary
        generate(myDefaultDictName, progressIndicator);
        // other gem-related dictionaries in alphabet order
        final List<String> dictionaries = new ArrayList<>(myDict2FolderMap.keySet());
        Collections.sort(dictionaries);
        for (String dict : dictionaries) {
            if (myDefaultDictName.equals(dict)) {
                continue;
            }
            generate(dict, progressIndicator);
        }
    }, "Generating Dictionaries", false, myProject);
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator)

Example 10 with ProgressIndicator

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

the class GroovyImportOptimizerRefactoringHelper method performOperation.

@Override
public void performOperation(final Project project, final Set<GroovyFile> files) {
    final ProgressManager progressManager = ProgressManager.getInstance();
    final Map<GroovyFile, Pair<List<GrImportStatement>, Set<GrImportStatement>>> redundants = new HashMap<>();
    final Runnable findUnusedImports = () -> {
        final ProgressIndicator progressIndicator = progressManager.getProgressIndicator();
        final int total = files.size();
        int i = 0;
        for (final GroovyFile file : files) {
            if (!file.isValid())
                continue;
            final VirtualFile virtualFile = file.getVirtualFile();
            if (!ProjectRootManager.getInstance(project).getFileIndex().isInSource(virtualFile)) {
                continue;
            }
            if (progressIndicator != null) {
                progressIndicator.setText2(virtualFile.getPresentableUrl());
                progressIndicator.setFraction((double) i++ / total);
            }
            ApplicationManager.getApplication().runReadAction(() -> {
                final Set<GrImportStatement> usedImports = GroovyImportUtil.findUsedImports(file);
                final List<GrImportStatement> validImports = PsiUtil.getValidImportStatements(file);
                redundants.put(file, Pair.create(validImports, usedImports));
            });
        }
    };
    if (!progressManager.runProcessWithProgressSynchronously(findUnusedImports, "Optimizing imports (Groovy) ... ", false, project)) {
        return;
    }
    WriteAction.run(() -> {
        for (GroovyFile groovyFile : redundants.keySet()) {
            if (!groovyFile.isValid())
                continue;
            final Pair<List<GrImportStatement>, Set<GrImportStatement>> pair = redundants.get(groovyFile);
            final List<GrImportStatement> validImports = pair.getFirst();
            final Set<GrImportStatement> usedImports = pair.getSecond();
            for (GrImportStatement importStatement : validImports) {
                if (!usedImports.contains(importStatement)) {
                    groovyFile.removeImport(importStatement);
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Set(java.util.Set) HashSet(com.intellij.util.containers.hash.HashSet) HashMap(java.util.HashMap) GrImportStatement(org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement) ProgressManager(com.intellij.openapi.progress.ProgressManager) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) Pair(com.intellij.openapi.util.Pair)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)400 Task (com.intellij.openapi.progress.Task)151 VirtualFile (com.intellij.openapi.vfs.VirtualFile)106 NotNull (org.jetbrains.annotations.NotNull)101 Project (com.intellij.openapi.project.Project)88 File (java.io.File)59 IOException (java.io.IOException)58 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)47 Nullable (org.jetbrains.annotations.Nullable)46 ProgressManager (com.intellij.openapi.progress.ProgressManager)39 List (java.util.List)36 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)31 Ref (com.intellij.openapi.util.Ref)27 Module (com.intellij.openapi.module.Module)26 VcsException (com.intellij.openapi.vcs.VcsException)26 ArrayList (java.util.ArrayList)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 Logger (com.intellij.openapi.diagnostic.Logger)23 AzureString (com.microsoft.azure.toolkit.lib.common.bundle.AzureString)22 AzureTask (com.microsoft.azure.toolkit.lib.common.task.AzureTask)22