use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GuiTestUtil method waitForIdeToStart.
// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
GuiActionRunner.executeInEDT(false);
Robot robot = null;
try {
robot = BasicRobot.robotWithCurrentAwtHierarchy();
final MyProjectManagerListener listener = new MyProjectManagerListener();
//[ACCEPT IntelliJ IDEA Privacy Policy Agreement]
acceptAgreementIfNeeded(robot);
findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
@Override
protected boolean isMatching(@NotNull Frame frame) {
if (frame instanceof IdeFrame) {
if (frame instanceof IdeFrameImpl) {
listener.myActive = true;
ProjectManager.getInstance().addProjectManagerListener(listener);
}
return true;
}
return false;
}
}).withTimeout(LONG_TIMEOUT.duration()).using(robot);
if (listener.myActive) {
Pause.pause(new Condition("Project to be opened") {
@Override
public boolean test() {
boolean notified = listener.myNotified;
if (notified) {
ProgressManager progressManager = ProgressManager.getInstance();
boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
if (isIdle) {
ProjectManager.getInstance().removeProjectManagerListener(listener);
}
return isIdle;
}
return false;
}
}, LONG_TIMEOUT);
}
} finally {
GuiActionRunner.executeInEDT(true);
if (robot != null) {
robot.cleanUpWithoutDisposingWindows();
}
}
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class ImportIntoShelfAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
if (project == null)
return;
final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, false, false, false, true);
FileChooser.chooseFiles(descriptor, project, null, new Consumer<List<VirtualFile>>() {
@Override
public void consume(final List<VirtualFile> files) {
//gatherPatchFiles
final ProgressManager pm = ProgressManager.getInstance();
final ShelveChangesManager shelveChangesManager = ShelveChangesManager.getInstance(project);
final List<VirtualFile> patchTypeFiles = new ArrayList<>();
final boolean filesFound = pm.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
patchTypeFiles.addAll(shelveChangesManager.gatherPatchFiles(files));
}
}, "Looking for patch files...", true, project);
if (!filesFound || patchTypeFiles.isEmpty())
return;
if (!patchTypeFiles.equals(files)) {
final String message = "Found " + (patchTypeFiles.size() == 1 ? "one patch file (" + patchTypeFiles.get(0).getPath() + ")." : (patchTypeFiles.size() + " patch files.")) + "\nContinue with import?";
final int toImport = Messages.showYesNoDialog(project, message, "Import Patches", Messages.getQuestionIcon());
if (Messages.NO == toImport)
return;
}
pm.runProcessWithProgressSynchronously(new Runnable() {
@Override
public void run() {
final List<VcsException> exceptions = new ArrayList<>();
final List<ShelvedChangeList> lists = shelveChangesManager.importChangeLists(patchTypeFiles, new Consumer<VcsException>() {
@Override
public void consume(VcsException e) {
exceptions.add(e);
}
});
if (!lists.isEmpty()) {
ShelvedChangesViewManager.getInstance(project).activateView(lists.get(lists.size() - 1));
}
if (!exceptions.isEmpty()) {
AbstractVcsHelper.getInstance(project).showErrors(exceptions, "Import patches into shelf");
}
if (lists.isEmpty() && exceptions.isEmpty()) {
VcsBalloonProblemNotifier.showOverChangesView(project, "No patches found", MessageType.WARNING);
}
}
}, "Import patches into shelf", true, project);
}
});
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GitHandlerUtil method doSynchronously.
/**
* Execute simple process synchronously with progress
*
* @param handler a handler
* @param operationTitle an operation title shown in progress dialog
* @param operationName an operation name shown in failure dialog
* @return A stdout content or null if there was error (exit code != 0 or exception during start).
*/
@Nullable
public static String doSynchronously(final GitSimpleHandler handler, final String operationTitle, @NonNls final String operationName) {
handler.addListener(new GitHandlerListenerBase(handler, operationName) {
protected String getErrorText() {
String text = handler.getStderr();
if (text.length() == 0) {
text = handler.getStdout();
}
return text;
}
});
final ProgressManager manager = ProgressManager.getInstance();
manager.runProcessWithProgressSynchronously(new Runnable() {
public void run() {
runInCurrentThread(handler, manager.getProgressIndicator(), true, operationTitle);
}
}, operationTitle, false, handler.project());
if (!handler.isStarted() || handler.getExitCode() != 0) {
return null;
}
return handler.getStdout();
}
use of com.intellij.openapi.progress.ProgressManager in project intellij-community by JetBrains.
the class GitHandlerUtil method doSynchronously.
/**
* Execute simple process synchronously with progress
*
* @param handler a handler
* @param operationTitle an operation title shown in progress dialog
* @param operationName an operation name shown in failure dialog
* @return An exit code
*/
public static int doSynchronously(final GitLineHandler handler, final String operationTitle, @NonNls final String operationName) {
final ProgressManager manager = ProgressManager.getInstance();
manager.run(new Task.Modal(handler.project(), operationTitle, true) {
public void run(@NotNull final ProgressIndicator indicator) {
handler.addLineListener(new GitLineHandlerListenerProgress(indicator, handler, operationName, true));
runInCurrentThread(handler, indicator, true, operationTitle);
}
});
if (!handler.isStarted()) {
return -1;
}
return handler.getExitCode();
}
use of com.intellij.openapi.progress.ProgressManager in project android by JetBrains.
the class GuiTests method waitForIdeToStart.
// Called by IdeTestApplication via reflection.
@SuppressWarnings("UnusedDeclaration")
public static void waitForIdeToStart() {
GuiActionRunner.executeInEDT(false);
Robot robot = null;
try {
robot = BasicRobot.robotWithCurrentAwtHierarchy();
MyProjectManagerListener listener = new MyProjectManagerListener();
findFrame(new GenericTypeMatcher<Frame>(Frame.class) {
@Override
protected boolean isMatching(@NotNull Frame frame) {
if (frame instanceof IdeFrame) {
if (frame instanceof IdeFrameImpl) {
listener.myActive = true;
ProjectManager.getInstance().addProjectManagerListener(listener);
}
return true;
}
return false;
}
}).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(robot);
// we attempt to clear here. All other events, including those posted by the Robot, will go through the IDE event queue.
try {
if (SYSTEM_EVENT_QUEUE.peekEvent() != null) {
SYSTEM_EVENT_QUEUE.getNextEvent();
}
} catch (InterruptedException ex) {
// Ignored.
}
if (listener.myActive) {
Wait.seconds(1).expecting("project to be opened").until(() -> {
boolean notified = listener.myNotified;
if (notified) {
ProgressManager progressManager = ProgressManager.getInstance();
boolean isIdle = !progressManager.hasModalProgressIndicator() && !progressManager.hasProgressIndicator() && !progressManager.hasUnsafeProgressIndicator();
if (isIdle) {
ProjectManager.getInstance().removeProjectManagerListener(listener);
}
return isIdle;
}
return false;
});
}
} finally {
GuiActionRunner.executeInEDT(true);
if (robot != null) {
robot.cleanUpWithoutDisposingWindows();
}
}
}
Aggregations