本文整理匯總了Java中com.intellij.openapi.application.Application.invokeAndWait方法的典型用法代碼示例。如果您正苦於以下問題:Java Application.invokeAndWait方法的具體用法?Java Application.invokeAndWait怎麽用?Java Application.invokeAndWait使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.application.Application
的用法示例。
在下文中一共展示了Application.invokeAndWait方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateVersionTimeFile
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
void updateVersionTimeFile(long versionSeconds) {
final Application application = ApplicationManager.getApplication();
application.invokeAndWait(() -> application.runWriteAction(() -> {
final VirtualFile child = baseDir.findChild(".git");
if (child == null) return;
try {
final VirtualFile timeFile = child.findOrCreateChildData(GitIntegration.class, DTT_TIME_FILE_NAME);
final BufferedReader reader = new BufferedReader(new InputStreamReader(timeFile.getInputStream(), StandardCharsets.UTF_8));
final String line = reader.readLine();
reader.close();
long existingSeconds = 0;
try {
if (line != null) {
existingSeconds = Long.parseLong(line);
}
} catch (NumberFormatException ignored) {}
final long newSeconds = versionSeconds == RESET_TIME_TO_ZERO ? 0 : Math.max(0, existingSeconds + versionSeconds);
timeFile.setBinaryContent(Long.toString(newSeconds).getBytes(StandardCharsets.UTF_8));
} catch (IOException e) {
LOG.log(Level.WARNING, "Error while updating version time file", e);
}
}), ModalityState.defaultModalityState());
}
示例2: waitForTheFile
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
public static VirtualFile waitForTheFile(final String path) {
final VirtualFile[] file = new VirtualFile[1];
final Application app = ApplicationManager.getApplication();
Runnable action = new Runnable() {
@Override
public void run() {
app.runWriteAction(new Runnable() {
@Override
public void run() {
file[0] = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
}
});
}
};
if (app.isDispatchThread()) {
action.run();
}
else {
app.invokeAndWait(action, ModalityState.defaultModalityState());
}
return file[0];
}
示例3: promptToRetry
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
/**
* Shows a retry prompt. Throws an exception to stop the setup process if the user preses cancel or returns normally otherwise.
*/
protected final void promptToRetry(@NotNull final String prompt, @NotNull String failureDescription, @Nullable Exception e) throws WizardException {
final AtomicBoolean response = new AtomicBoolean(false);
Application application = ApplicationManager.getApplication();
application.invokeAndWait(new Runnable() {
@Override
public void run() {
int i = Messages.showYesNoDialog(null, prompt, "Android Studio Setup", "Retry", "Cancel", Messages.getErrorIcon());
response.set(i == Messages.YES);
}
}, application.getAnyModalityState());
if (!response.get()) {
Throwables.propagateIfInstanceOf(e, WizardException.class);
throw new WizardException(failureDescription, e);
}
else {
myContext.print(failureDescription + "\n", ConsoleViewContentType.ERROR_OUTPUT);
}
}
示例4: generateFromStudentCourse
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
public static void generateFromStudentCourse(Project project, Course course) {
StudyTaskManager.getInstance(project).setCourse(course);
course.setCourseMode(CCUtils.COURSE_MODE);
final VirtualFile baseDir = project.getBaseDir();
final Application application = ApplicationManager.getApplication();
application.invokeAndWait(() -> application.runWriteAction(() -> {
final VirtualFile[] children = baseDir.getChildren();
for (VirtualFile child : children) {
StudyUtils.deleteFile(child);
}
StudyGenerator.createCourse(course, baseDir);
}));
baseDir.refresh(false, true);
int index = 1;
int taskIndex = 1;
for (Lesson lesson : course.getLessons()) {
final VirtualFile lessonDir = project.getBaseDir().findChild(EduNames.LESSON + String.valueOf(index));
lesson.setIndex(index);
if (lessonDir == null) continue;
for (Task task : lesson.getTaskList()) {
final VirtualFile taskDir = lessonDir.findChild(EduNames.TASK + String.valueOf(taskIndex));
task.setIndex(taskIndex);
task.setLesson(lesson);
if (taskDir == null) continue;
for (final Map.Entry<String, TaskFile> entry : task.getTaskFiles().entrySet()) {
application.invokeAndWait(() -> application.runWriteAction(() -> createAnswerFile(project, taskDir, entry)));
}
taskIndex += 1;
}
index += 1;
taskIndex = 1;
}
course.initCourse(true);
application.invokeAndWait(() -> StudyUtils.registerStudyToolWindow(course, project));
synchronize(project);
}
示例5: doWriteAction
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
private static void doWriteAction(final Runnable action) {
final Application application = ApplicationManager.getApplication();
application.invokeAndWait(new Runnable() {
@Override
public void run() {
application.runWriteAction(action);
}
}, application.getDefaultModalityState());
}
示例6: executeOnEdt
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
public static void executeOnEdt(boolean synchronous, @NotNull Runnable task) {
final Application app = ApplicationManager.getApplication();
if (app.isDispatchThread()) {
task.run();
return;
}
if (synchronous) {
app.invokeAndWait(task, ModalityState.defaultModalityState());
}
else {
app.invokeLater(task, ModalityState.defaultModalityState());
}
}
示例7: runOrInvokeAndWaitAboveProgress
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
public static void runOrInvokeAndWaitAboveProgress(final Runnable command, @Nullable final ModalityState modalityState) {
final Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
command.run();
} else {
final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
if (pi != null) {
execute(pi);
application.invokeAndWait(command, pi.getModalityState());
} else {
final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
application.invokeAndWait(command, notNullModalityState);
}
}
}
示例8: runAboveAll
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
private static void runAboveAll(@NotNull final Runnable runnable) {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
if (progressIndicator != null && progressIndicator.isModal()) {
WaitForProgressToShow.runOrInvokeAndWaitAboveProgress(runnable);
}
else {
Application app = ApplicationManager.getApplication();
if (app.isDispatchThread()) {
runnable.run();
}
else {
app.invokeAndWait(runnable, ModalityState.any());
}
}
}
示例9: fireModulesAdded
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
@Override
protected void fireModulesAdded() {
if (myModuleModel.myModules.isEmpty()) {
return;
}
Runnable runnableWithProgress = new Runnable() {
@Override
public void run() {
for (final Module module : myModuleModel.myModules.values()) {
final Application app = ApplicationManager.getApplication();
final Runnable swingRunnable = new Runnable() {
@Override
public void run() {
fireModuleAddedInWriteAction(module);
}
};
if (app.isDispatchThread()) {
swingRunnable.run();
}
else {
ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
app.invokeAndWait(swingRunnable, pi.getModalityState());
}
}
}
};
ProgressIndicator progressIndicator = myProgressManager.getProgressIndicator();
if (progressIndicator == null) {
myProgressManager.runProcessWithProgressSynchronously(runnableWithProgress, "Initializing modules...", false, myProject);
}
else {
runnableWithProgress.run();
}
}
示例10: promptUserForSdkCreation
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
@Nullable
private static Sdk promptUserForSdkCreation(@Nullable final IAndroidTarget target,
@Nullable final String androidSdkPath,
@Nullable final String jdkPath) {
final Ref<Sdk> sdkRef = new Ref<Sdk>();
Runnable task = new Runnable() {
@Override
public void run() {
SelectSdkDialog dlg = new SelectSdkDialog(jdkPath, androidSdkPath);
dlg.setModal(true);
if (dlg.showAndGet()) {
Sdk sdk = createNewAndroidPlatform(target, dlg.getAndroidHome(), dlg.getJdkHome());
sdkRef.set(sdk);
if (sdk != null) {
RunAndroidSdkManagerAction.updateInWelcomePage(dlg.getContentPanel());
}
}
}
};
Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
task.run();
return sdkRef.get();
}
application.invokeAndWait(task, ModalityState.any());
return sdkRef.get();
}
示例11: runInDispatchedThread
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
private static void runInDispatchedThread(@NotNull Runnable r, boolean blocking) {
Application application = ApplicationManager.getApplication();
if (application.isDispatchThread()) {
r.run();
}
else if (blocking) {
application.invokeAndWait(r, ModalityState.defaultModalityState());
}
else {
application.invokeLater(r);
}
}
示例12: promptToRetryFailedConnection
import com.intellij.openapi.application.Application; //導入方法依賴的package包/類
@Nullable
private static ConnectionState promptToRetryFailedConnection() {
final AtomicReference<ConnectionState> atomicBoolean = Atomics.newReference();
Application application = ApplicationManager.getApplication();
application.invokeAndWait(new Runnable() {
@Override
public void run() {
atomicBoolean.set(promptUserForProxy());
}
}, application.getAnyModalityState());
return atomicBoolean.get();
}