@Nullable
 public CvsTabbedWindow openTabbedWindow(final CvsHandler output) {
   if (ApplicationManager.getApplication().isUnitTestMode()) return null;
   if (myProject != null && myProject.isDefault()) return null;
   if (myProject != null) {
     if (myConfiguration != null && myConfiguration.SHOW_OUTPUT && !myIsQuietOperation) {
       if (ApplicationManager.getApplication().isDispatchThread()) {
         connectToOutput(output);
       } else {
         ApplicationManager.getApplication()
             .invokeAndWait(
                 new Runnable() {
                   public void run() {
                     connectToOutput(output);
                   }
                 },
                 ModalityState.defaultModalityState());
       }
     }
     if (!myProject.isDisposed()) {
       return CvsTabbedWindow.getInstance(myProject);
     }
   }
   return null;
 }
  @Override
  public void addMessageToConsoleWindow(final String message, final TextAttributes attributes) {
    if (!Registry.is("vcs.showConsole")) {
      return;
    }
    if (StringUtil.isEmptyOrSpaces(message)) {
      return;
    }

    ApplicationManager.getApplication()
        .invokeLater(
            new Runnable() {
              @Override
              public void run() {
                // for default and disposed projects the ContentManager is not available.
                if (myProject.isDisposed() || myProject.isDefault()) return;
                final ContentManager contentManager = getContentManager();
                if (contentManager == null) {
                  myPendingOutput.add(Pair.create(message, attributes));
                } else {
                  getOrCreateConsoleContent(contentManager);
                  myEditorAdapter.appendString(message, attributes);
                }
              }
            },
            ModalityState.defaultModalityState());
  }
  public boolean confirmUndeploy() {
    final Ref<Boolean> confirmed = new Ref<Boolean>(false);
    ApplicationManager.getApplication()
        .invokeAndWait(
            new Runnable() {

              @Override
              public void run() {
                String title = CloudBundle.getText("cloud.undeploy.confirm.title");
                while (true) {
                  String password =
                      Messages.showPasswordDialog(
                          CloudBundle.getText("cloud.undeploy.confirm.message", myPresentableName),
                          title);
                  if (password == null) {
                    return;
                  }
                  if (password.equals(myConfiguration.getPassword())) {
                    confirmed.set(true);
                    return;
                  }
                  Messages.showErrorDialog(
                      CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
                }
              }
            },
            ModalityState.defaultModalityState());
    return confirmed.get();
  }
 @Override
 protected byte[] key(@Nullable final Project project) throws PasswordSafeException {
   ApplicationEx application = (ApplicationEx) ApplicationManager.getApplication();
   if (!isTestMode() && application.isHeadlessEnvironment()) {
     throw new MasterPasswordUnavailableException(
         "The provider is not available in headless environment");
   }
   if (key.get() == null) {
     if (isPasswordEncrypted()) {
       try {
         String s = decryptPassword(database.getPasswordInfo());
         setMasterPassword(s);
       } catch (PasswordSafeException e) {
         // ignore exception and ask password
       }
     }
     if (key.get() == null) {
       final Ref<PasswordSafeException> ex = new Ref<PasswordSafeException>();
       if (application.holdsReadLock()) {
         throw new IllegalStateException(
             "Access from read action is not allowed, because it might lead to a deadlock.");
       }
       application.invokeAndWait(
           new Runnable() {
             public void run() {
               if (key.get() == null) {
                 try {
                   if (isTestMode()) {
                     throw new MasterPasswordUnavailableException(
                         "Master password must be specified in test mode.");
                   }
                   if (database.isEmpty()) {
                     if (!ResetPasswordDialog.newPassword(project, MasterKeyPasswordSafe.this)) {
                       throw new MasterPasswordUnavailableException(
                           "Master password is required to store passwords in the database.");
                     }
                   } else {
                     MasterPasswordDialog.askPassword(project, MasterKeyPasswordSafe.this);
                   }
                 } catch (PasswordSafeException e) {
                   ex.set(e);
                 } catch (Exception e) {
                   //noinspection ThrowableInstanceNeverThrown
                   ex.set(
                       new MasterPasswordUnavailableException(
                           "The problem with retrieving the password", e));
                 }
               }
             }
           },
           ModalityState.defaultModalityState());
       //noinspection ThrowableResultOfMethodCallIgnored
       if (ex.get() != null) {
         throw ex.get();
       }
     }
   }
   return this.key.get();
 }
 private void showMergeDialog(@NotNull final Collection<VirtualFile> initiallyUnmergedFiles) {
   ApplicationManager.getApplication()
       .invokeAndWait(
           () -> {
             MergeProvider mergeProvider = new GitMergeProvider(myProject, myParams.reverse);
             myVcsHelper.showMergeDialog(
                 new ArrayList<>(initiallyUnmergedFiles),
                 mergeProvider,
                 myParams.myMergeDialogCustomizer);
           },
           ModalityState.defaultModalityState());
 }
 /**
  * Opens an error dialog with the specified title. Ensures that the error dialog is opened on the
  * UI thread.
  *
  * @param message The message to be displayed.
  * @param title The title of the error dialog to be displayed
  */
 public static void showErrorDialog(final String message, @NotNull final String title) {
   if (ApplicationManager.getApplication().isDispatchThread()) {
     Messages.showErrorDialog(message, title);
   } else {
     ApplicationManager.getApplication()
         .invokeLater(
             new Runnable() {
               @Override
               public void run() {
                 Messages.showErrorDialog(message, title);
               }
             },
             ModalityState.defaultModalityState());
   }
 }
 @Override
 protected void loadLibraries() {
   if (!ThreadUtils.isEventDispatchThread()) {
     ApplicationManager.getApplication()
         .invokeAndWait(
             new Runnable() {
               @Override
               public void run() {
                 ProjectLibraryManager.super.loadLibraries();
               }
             },
             ModalityState.defaultModalityState());
   } else {
     super.loadLibraries();
   }
 }
Example #8
0
  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);
                  }
                });
          }
        };

    app.invokeAndWait(action, ModalityState.defaultModalityState());

    return file[0];
  }
Example #9
0
  @Nullable
  public static VirtualFile waitForTheFile(@Nullable final String path) {
    if (path == null) return null;

    final VirtualFile[] file = new VirtualFile[1];
    final Application app = ApplicationManager.getApplication();
    Runnable action =
        new Runnable() {
          public void run() {
            app.runWriteAction(
                new Runnable() {
                  public void run() {
                    file[0] = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
                  }
                });
          }
        };
    if (app.isDispatchThread()) {
      action.run();
    } else {
      app.invokeAndWait(action, ModalityState.defaultModalityState());
    }
    return file[0];
  }
 public EmptyProgressIndicator() {
   this(ModalityState.defaultModalityState());
 }
  public static void generate(GeneratingCompiler compiler, final CompileContext context) {
    if (context == null) {
      return;
    }

    final Set<Module> affectedModules = new HashSet<Module>();
    Collections.addAll(affectedModules, context.getCompileScope().getAffectedModules());

    ApplicationManager.getApplication()
        .invokeAndWait(
            new Runnable() {
              @Override
              public void run() {
                for (Module module : affectedModules) {
                  if (module.isDisposed() || module.getProject().isDisposed()) {
                    continue;
                  }

                  final AndroidFacet facet = AndroidFacet.getInstance(module);
                  if (facet != null) {
                    AndroidCompileUtil.createGenModulesAndSourceRoots(facet);
                  }
                }
              }
            },
            ModalityState.defaultModalityState());

    List<GeneratingCompiler.GenerationItem> itemsToGenerate =
        new ArrayList<GeneratingCompiler.GenerationItem>();
    for (GeneratingCompiler.GenerationItem item : compiler.getGenerationItems(context)) {
      if (affectedModules.contains(item.getModule())) {
        itemsToGenerate.add(item);
      }
    }

    GeneratingCompiler.GenerationItem[] items =
        itemsToGenerate.toArray(new GeneratingCompiler.GenerationItem[itemsToGenerate.size()]);

    final boolean[] run = {true};
    final VirtualFile[] files = getFilesToCheckReadonlyStatus(items);
    if (files.length > 0) {
      ApplicationManager.getApplication()
          .invokeAndWait(
              new Runnable() {
                @Override
                public void run() {
                  ApplicationManager.getApplication()
                      .runReadAction(
                          new Runnable() {
                            @Override
                            public void run() {
                              final Project project = context.getProject();
                              run[0] =
                                  !project.isDisposed()
                                      && ReadonlyStatusHandler.ensureFilesWritable(project, files);
                            }
                          });
                }
              },
              ModalityState.defaultModalityState());
    }

    if (run[0]) {
      compiler.generate(context, items, null);
    }
  }
 @NotNull
 static ActionCallback invokeLater(@NotNull Runnable runnable, @NotNull Condition<?> expired) {
   ModalityState modalityState = ModalityState.defaultModalityState();
   return invokeLater(runnable, modalityState, expired);
 }
  public void startPLugin() {
    if (hasRanPreviously() && isGuidewireApp()) {
      ExceptionUtil.showError(
          GosuBundle.message("error.plugin_disabled"),
          GosuBundle.message("error.plugin_disabled.description"));
      return;
    }

    for (ITypeSystemStartupContributor contributor : getStartupContributors()) {
      String message = contributor.accepts(_project);
      if (message != null) {
        ExceptionUtil.showInfo(GosuBundle.message("info.plugin.not.started"), message);
        return;
      }
    }

    ApplicationManager.getApplication()
        .invokeAndWait(
            new Runnable() {
              public void run() {
                ApplicationManager.getApplication()
                    .runWriteAction(
                        new Runnable() {
                          public void run() {
                            // pre -startup
                            try {
                              for (ITypeSystemStartupContributor pluginListener :
                                  getStartupContributors()) {
                                pluginListener.beforeTypesystemStartup(_project);
                              }
                            } catch (Exception e) {
                              reportStartupError(e);
                              return;
                            }

                            // !PW leaks reference to GosuLoader, if we ever want to support clean
                            // unloading of plugin
                            _applicationConnection =
                                ApplicationManager.getApplication().getMessageBus().connect();

                            setDumbMode(true);
                            try {
                              startTypeSystem();
                              initGosuPlugin();
                              for (ITypeSystemStartupContributor pluginListener :
                                  getStartupContributors()) {
                                pluginListener.afterTypesystemStartup(_project);
                              }
                              System.out.println("Initialized Gosu with IJ Project: " + _project);
                            } catch (Throwable e) {
                              reportStartupError(e);
                              System.out.println("¿prolbem?");
                            } finally {
                              setDumbMode(false);
                            }
                          }
                        });
              }
            },
            ModalityState.defaultModalityState());
  }
 public CvsOperationExecutor(Project project) {
   this(true, project, ModalityState.defaultModalityState());
 }
Example #15
0
 public static void invokeAndWait(Project p, Runnable r) {
   invokeAndWait(p, ModalityState.defaultModalityState(), r);
 }
 private void applyInformationToEditorsLater(
     @NotNull final FileEditor fileEditor,
     @NotNull final TextEditorHighlightingPass pass,
     @NotNull final DaemonProgressIndicator updateProgress,
     @NotNull final AtomicInteger threadsToStartCountdown) {
   ApplicationManager.getApplication()
       .invokeLater(
           (DumbAwareRunnable)
               () -> {
                 if (isDisposed() || myProject.isDisposed()) {
                   updateProgress.cancel();
                 }
                 if (updateProgress.isCanceled()) {
                   log(updateProgress, pass, " is canceled during apply, sorry");
                   return;
                 }
                 Document document = pass.getDocument();
                 try {
                   if (fileEditor.getComponent().isDisplayable()
                       || ApplicationManager.getApplication().isUnitTestMode()) {
                     pass.applyInformationToEditor();
                     FileStatusMap fileStatusMap =
                         DaemonCodeAnalyzerEx.getInstanceEx(myProject).getFileStatusMap();
                     if (document != null) {
                       fileStatusMap.markFileUpToDate(document, pass.getId());
                     }
                     log(updateProgress, pass, " Applied");
                   }
                 } catch (ProcessCanceledException e) {
                   log(updateProgress, pass, "Error " + e);
                   throw e;
                 } catch (RuntimeException e) {
                   VirtualFile file =
                       document == null
                           ? null
                           : FileDocumentManager.getInstance().getFile(document);
                   FileType fileType = file == null ? null : file.getFileType();
                   String message =
                       "Exception while applying information to "
                           + fileEditor
                           + "("
                           + fileType
                           + ")";
                   log(updateProgress, pass, message + e);
                   throw new RuntimeException(message, e);
                 }
                 if (threadsToStartCountdown.decrementAndGet() == 0) {
                   log(updateProgress, pass, "Stopping ");
                   updateProgress.stopIfRunning();
                 } else {
                   log(
                       updateProgress,
                       pass,
                       "Finished but there are passes in the queue: "
                           + threadsToStartCountdown.get());
                 }
               },
           Registry.is("ide.perProjectModality")
               ? ModalityState.defaultModalityState()
               : ModalityState.stateForComponent(fileEditor.getComponent()));
 }
  /**
   * The most general execution method.
   *
   * @param sync Set to <code>true</code> to make the calling thread wait for the task execution.
   * @param modal If <code>true</code>, the task will be modal with a modal progress dialog. If
   *     false, the task will be executed in background. <code>modal</code> implies <code>sync
   *     </code>, i.e. if modal then sync doesn't matter: you'll wait anyway.
   * @param resultHandler Handle the result.
   * @see #execute(boolean)
   */
  public void execute(boolean sync, boolean modal, final GitTaskResultHandler resultHandler) {
    final Object LOCK = new Object();
    final AtomicBoolean completed = new AtomicBoolean();

    if (modal) {
      final ModalTask task =
          new ModalTask(myProject, myHandler, myTitle) {
            @Override
            public void onSuccess() {
              commonOnSuccess(LOCK, resultHandler);
              completed.set(true);
            }

            @Override
            public void onCancel() {
              commonOnCancel(LOCK, resultHandler);
              completed.set(true);
            }
          };
      GuiUtils.invokeAndWaitIfNeeded(
          new Runnable() {
            @Override
            public void run() {
              ProgressManager.getInstance().run(task);
            }
          },
          ModalityState.defaultModalityState());
    } else {
      final BackgroundableTask task =
          new BackgroundableTask(myProject, myHandler, myTitle) {
            @Override
            public void onSuccess() {
              commonOnSuccess(LOCK, resultHandler);
              completed.set(true);
            }

            @Override
            public void onCancel() {
              commonOnCancel(LOCK, resultHandler);
              completed.set(true);
            }
          };
      if (myProgressIndicator == null) {
        GitVcs.runInBackground(task);
      } else {
        task.runAlone();
      }
    }

    if (sync) {
      while (!completed.get()) {
        try {
          synchronized (LOCK) {
            LOCK.wait(50);
          }
        } catch (InterruptedException e) {
          LOG.info(e);
        }
      }
    }
  }