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"));
}
}
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);
}
};
}
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);
}
}
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);
}
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);
}
}
}
});
}
Aggregations