Java Code Examples for com.intellij.openapi.application.ModalityState

The following are top voted examples for showing how to use com.intellij.openapi.application.ModalityState. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: intellij-plugin   File: NavigatorUtil.java   View source code 6 votes vote down vote up
public static void smartInvokeAndWait(final Project p, final ModalityState state, final Runnable r) {
    if (isNoBackgroundMode() || ApplicationManager.getApplication().isDispatchThread()) {
        r.run();
    } else {
        final Semaphore semaphore = new Semaphore();
        semaphore.down();
        DumbService.getInstance(p).smartInvokeLater(() -> {
            try {
                r.run();
            } finally {
                semaphore.up();
            }
        }, state);
        semaphore.waitFor();
    }
}
 
Example 2
Project: intellij-ce-playground   File: DelayedDocumentWatcher.java   View source code 6 votes vote down vote up
private void asyncCheckErrors(@NotNull final Collection<VirtualFile> files,
                              @NotNull final Consumer<Boolean> errorsFoundConsumer) {
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      final boolean errorsFound = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
        @Override
        public Boolean compute() {
          for (VirtualFile file : files) {
            if (PsiErrorElementUtil.hasErrors(myProject, file)) {
              return true;
            }
          }
          return false;
        }
      });
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          errorsFoundConsumer.consume(errorsFound);
        }
      }, ModalityState.any());
    }
  });
}
 
Example 3
Project: PackageTemplates   File: FileWriter.java   View source code 6 votes vote down vote up
public static PsiDirectory findCurrentDirectory(Project project, VirtualFile file) {
    final PsiDirectory[] result = new PsiDirectory[1];
    ApplicationManager.getApplication().invokeAndWait(() ->
                    result[0] = ApplicationManager.getApplication().runReadAction((Computable<PsiDirectory>) () -> {
                        if (file == null || project == null) {
                            return null;
                        }

                        if (file.isDirectory()) {
                            return PsiManager.getInstance(project).findDirectory(file);
                        } else {
                            return PsiManager.getInstance(project).findDirectory(file.getParent());
                        }
                    })
            , ModalityState.defaultModalityState());
    return result[0];
}
 
Example 4
Project: intellij-ce-playground   File: GitSSHGUIHandler.java   View source code 6 votes vote down vote up
public boolean verifyServerHostKey(final String hostname,
                                   final int port,
                                   final String serverHostKeyAlgorithm,
                                   final String fingerprint,
                                   final boolean isNew) {
  final String message;
  if (isNew) {
    message = GitBundle.message("ssh.new.host.key", hostname, port, fingerprint, serverHostKeyAlgorithm);
  }
  else {
    message = GitBundle.message("ssh.changed.host.key", hostname, port, fingerprint, serverHostKeyAlgorithm);
  }
  final AtomicBoolean rc = new AtomicBoolean();
  ApplicationManager.getApplication().invokeAndWait(new Runnable() {
    public void run() {
      rc.set(Messages.YES == Messages.showYesNoDialog(myProject, message, GitBundle.getString("ssh.confirm.key.titile"), null));
    }
  }, ModalityState.any());
  return rc.get();
}
 
Example 5
Project: intellij-ce-playground   File: PythonSdkType.java   View source code 6 votes vote down vote up
public void setupSdkPaths(final Sdk sdk, @Nullable final Project project, @Nullable final Component ownerComponent) {
  scheduledToRefresh.add(sdk.getHomePath());
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      try {
        final boolean success = doSetupSdkPaths(project, ownerComponent, PySdkUpdater.fromSdkPath(sdk.getHomePath()));

        if (!success) {
          Messages.showErrorDialog(
            project,
            PyBundle.message("MSG.cant.setup.sdk.$0", FileUtil.toSystemDependentName(sdk.getSdkModificator().getHomePath())),
            PyBundle.message("MSG.title.bad.sdk")
          );
        }
      }
      catch (PySdkUpdater.PySdkNotFoundException e) {
        // sdk was removed from sdk table so no need to setup paths
      }
    }
  }, ModalityState.NON_MODAL);
}
 
Example 6
Project: intellij-ce-playground   File: ParameterInfoController.java   View source code 6 votes vote down vote up
private void addAlarmRequest(){
  Runnable request = new Runnable(){
    @Override
    public void run(){
      if (!myDisposed && !myProject.isDisposed()) {
        DumbService.getInstance(myProject).withAlternativeResolveEnabled(new Runnable() {
          @Override
          public void run() {
            updateComponent();
          }
        });
      }
    }
  };
  myAlarm.addRequest(request, DELAY, ModalityState.stateForComponent(myEditor.getComponent()));
}
 
Example 7
Project: intellij-ce-playground   File: FindDialog.java   View source code 6 votes vote down vote up
public FindDialog(@NotNull Project project, @NotNull FindModel model, @NotNull Consumer<FindModel> myOkHandler){
  super(project, true);
  myProject = project;
  myModel = model;

  this.myOkHandler = myOkHandler;

  updateTitle();
  setOKButtonText(FindBundle.message("find.button"));
  init();
  initByModel();
  updateReplaceVisibility();

  if (haveResultsPreview()) {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
      @Override
      public void run() {
        scheduleResultsUpdate();
      }
    }, ModalityState.any());
  }
}
 
Example 8
Project: intellij-ce-playground   File: ProjectListBuilder.java   View source code 6 votes vote down vote up
public void addUpdateRequest(final boolean shouldRefreshSelection) {
  final Runnable request = new Runnable() {
    @Override
    public void run() {
      if (!myProject.isDisposed()) {
        // Rely on project view to commit PSI and wait until it's updated.
        if (myTreeStructure.hasSomethingToCommit() ) {
          myUpdateAlarm.cancelAllRequests();
          myUpdateAlarm.addRequest(this, 300, ModalityState.stateForComponent(myList));
          return;
        }
        updateList(shouldRefreshSelection);
      }
    }
  };

  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    myUpdateAlarm.cancelAllRequests();
    myUpdateAlarm.addRequest(request, 300, ModalityState.stateForComponent(myList));
  }
  else {
    request.run();
  }
}
 
Example 9
Project: intellij-ce-playground   File: CommandConsole.java   View source code 6 votes vote down vote up
/**
 * Switches console to "command-mode" (see class doc for details)
 */
private void switchToCommandMode() {
  // "upper" and "bottom" parts of console both need padding in command mode
  myProcessHandler = null;
  setPrompt(getTitle() + " > ");
  ApplicationManager.getApplication().invokeAndWait(new Runnable() {
    @Override
    public void run() {
      notifyStateChangeListeners();
      configureLeftBorder(true, getConsoleEditor(), getHistoryViewer());
      setLanguage(CommandLineLanguage.INSTANCE);
      final CommandLineFile file = PyUtil.as(getFile(), CommandLineFile.class);
      resetConsumer(null);
      if (file == null || myCommandsAndDefaultExecutor == null) {
        return;
      }
      file.setCommands(myCommandsAndDefaultExecutor.first);
      final CommandConsole console = CommandConsole.this;
      resetConsumer(new CommandModeConsumer(myCommandsAndDefaultExecutor.first, myModule, console, myCommandsAndDefaultExecutor.second));
    }
  }, ModalityState.NON_MODAL);
}
 
Example 10
Project: intellij-ce-playground   File: RegistryUi.java   View source code 6 votes vote down vote up
private void processClose() {
  if (Registry.getInstance().isRestartNeeded()) {
    final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
    final ApplicationInfo info = ApplicationInfo.getInstance();

    final int r = Messages.showOkCancelDialog(myContent, "You need to restart " + info.getVersionName() + " for the changes to take effect", "Restart Required",
                                              app.isRestartCapable() ? "Restart Now" : "Shutdown Now",
                                              app.isRestartCapable() ? "Restart Later": "Shutdown Later"
        , Messages.getQuestionIcon());


    if (r == Messages.OK) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          app.restart(true);
        }
      }, ModalityState.NON_MODAL);
    }
  }
}
 
Example 11
Project: intellij-ce-playground   File: bigFile.java   View source code 6 votes vote down vote up
private void setMouseSelectionState(@MouseSelectionState int mouseSelectionState) {
  if (getMouseSelectionState() == mouseSelectionState) return;

  myMouseSelectionState = mouseSelectionState;
  myMouseSelectionChangeTimestamp = System.currentTimeMillis();

  myMouseSelectionStateAlarm.cancelAllRequests();
  if (myMouseSelectionState != MOUSE_SELECTION_STATE_NONE) {
    if (myMouseSelectionStateResetRunnable == null) {
      myMouseSelectionStateResetRunnable = new Runnable() {
        @Override
        public void run() {
          resetMouseSelectionState(null);
        }
      };
    }
    myMouseSelectionStateAlarm.addRequest(myMouseSelectionStateResetRunnable, Registry.intValue("editor.mouseSelectionStateResetTimeout"),
                                          ModalityState.stateForComponent(myEditorComponent));
  }
}
 
Example 12
Project: intellij-ce-playground   File: VcsEventWatcher.java   View source code 6 votes vote down vote up
@Override
public void projectOpened() {
  MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
  connection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootAdapter() {
    @Override
    public void rootsChanged(ModuleRootEvent event) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          if (myProject.isDisposed()) return;
          VcsDirtyScopeManager.getInstance(myProject).markEverythingDirty();
        }
      }, ModalityState.NON_MODAL);
    }
  });
  final WolfTheProblemSolver.ProblemListener myProblemListener = new MyProblemListener();
  WolfTheProblemSolver.getInstance(myProject).addProblemListener(myProblemListener,myProject);
}
 
Example 13
Project: intellij-ce-playground   File: CardLayoutPanel.java   View source code 6 votes vote down vote up
private void selectLater(final ActionCallback callback, final K key) {
  ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
    @Override
    public void run() {
      if (!myDisposed) {
        final UI ui = prepare(key);
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          @Override
          public void run() {
            if (!myDisposed) {
              select(callback, key, ui);
            }
            else callback.setRejected();
          }
        }, ModalityState.any());
      }
      else callback.setRejected();
    }
  });
}
 
Example 14
Project: intellij-ce-playground   File: ModuleManagerImpl.java   View source code 6 votes vote down vote up
@NotNull
private Module loadModuleInternal(@NotNull String filePath) throws ModuleWithNameAlreadyExists, IOException {
  filePath = resolveShortWindowsName(filePath);
  final VirtualFile moduleFile = StandardFileSystems.local().findFileByPath(filePath);
  if (moduleFile == null || !moduleFile.exists()) {
    throw new FileNotFoundException(ProjectBundle.message("module.file.does.not.exist.error", filePath));
  }

  String path = moduleFile.getPath();
  ModuleEx module = getModuleByFilePath(path);
  if (module == null) {
    ApplicationManager.getApplication().invokeAndWait(new Runnable() {
      @Override
      public void run() {
        moduleFile.refresh(false, false);
      }
    }, ModalityState.any());
    module = createAndLoadModule(path);
    initModule(module, path, null);
  }
  return module;
}
 
Example 15
Project: intellij-ce-playground   File: CloudGitApplicationRuntime.java   View source code 6 votes vote down vote up
private 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", getApplicationName()), title);
        if (password == null) {
          return;
        }
        if (password.equals(getServerRuntime().getConfiguration().getPassword())) {
          confirmed.set(true);
          return;
        }
        Messages.showErrorDialog(CloudBundle.getText("cloud.undeploy.confirm.password.incorrect"), title);
      }
    }
  }, ModalityState.defaultModalityState());
  return confirmed.get();
}
 
Example 16
Project: intellij-ce-playground   File: ServersToolWindowContent.java   View source code 6 votes vote down vote up
private static void pollDeployments(final ServerConnection connection) {
  connection.computeDeployments(new Runnable() {

    @Override
    public void run() {
      new Alarm().addRequest(new Runnable() {

        @Override
        public void run() {
          if (connection == ServerConnectionManager.getInstance().getConnection(connection.getServer())) {
            pollDeployments(connection);
          }
        }
      }, POLL_DEPLOYMENTS_DELAY, ModalityState.any());
    }
  });
}
 
Example 17
Project: intellij-ce-playground   File: AndroidProjectComponent.java   View source code 6 votes vote down vote up
private void generate(final Map<AndroidFacet, Collection<AndroidAutogeneratorMode>> facetsToProcess) {
  ApplicationManager.getApplication().invokeAndWait(new Runnable() {
    @Override
    public void run() {
      AndroidCompileUtil.createGenModulesAndSourceRoots(myProject, facetsToProcess.keySet());
    }
  }, ModalityState.defaultModalityState());

  for (Map.Entry<AndroidFacet, Collection<AndroidAutogeneratorMode>> entry : facetsToProcess.entrySet()) {
    final AndroidFacet facet = entry.getKey();
    final Collection<AndroidAutogeneratorMode> modes = entry.getValue();

    for (AndroidAutogeneratorMode mode : modes) {
      AndroidCompileUtil.doGenerate(facet, mode);
    }
  }
}
 
Example 18
Project: intellij-ce-playground   File: ComboBoxAction.java   View source code 6 votes vote down vote up
@NotNull
private Runnable setForcePressed() {
  myForcePressed = true;
  repaint();

  return new Runnable() {
    @Override
    public void run() {
      // give the button a chance to handle action listener
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          myForcePressed = false;
          myPopup = null;
        }
      }, ModalityState.any());
      repaint();
      fireStateChanged();
    }
  };
}
 
Example 19
Project: intellij-ce-playground   File: WaitForProgressToShow.java   View source code 6 votes vote down vote up
public static void runOrInvokeLaterAboveProgress(final Runnable command, @Nullable final ModalityState modalityState, @NotNull final Project project) {
  final Application application = ApplicationManager.getApplication();
  if (application.isDispatchThread()) {
    command.run();
  } else {
    final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
    if (pi != null) {
      execute(pi);
      application.invokeLater(command, pi.getModalityState(), new Condition() {
        @Override
        public boolean value(Object o) {
          return (! project.isOpen()) || project.isDisposed();
        }
      });
    } else {
      final ModalityState notNullModalityState = modalityState == null ? ModalityState.NON_MODAL : modalityState;
      application.invokeLater(command, notNullModalityState, project.getDisposed());
    }
  }
}
 
Example 20
Project: intellij-ce-playground   File: ToolWindowImpl.java   View source code 6 votes vote down vote up
@Override
public void activate(@Nullable final Runnable runnable, boolean autoFocusContents, boolean forced) {
  ApplicationManager.getApplication().assertIsDispatchThread();

  final UiActivity activity = new UiActivity.Focus("toolWindow:" + myId);
  UiActivityMonitor.getInstance().addActivity(myToolWindowManager.getProject(), activity, ModalityState.NON_MODAL);

  myToolWindowManager.activateToolWindow(myId, forced, autoFocusContents);

  getActivation().doWhenDone(new Runnable() {
    @Override
    public void run() {
      myToolWindowManager.invokeLater(new Runnable() {
        @Override
        public void run() {
          if (runnable != null) {
            runnable.run();
          }
          UiActivityMonitor.getInstance().removeActivity(myToolWindowManager.getProject(), activity);
        }
      });
    }
  });
}
 
Example 21
Project: intellij-ce-playground   File: HTMLExportUtil.java   View source code 6 votes vote down vote up
public static void writeFile(final String folder, @NonNls final String fileName, CharSequence buf, final Project project) {
  try {
    HTMLExporter.writeFileImpl(folder, fileName, buf);
  }
  catch (IOException e) {
    Runnable showError = new Runnable() {
      @Override
      public void run() {
        final String fullPath = folder + File.separator + fileName;
        Messages.showMessageDialog(
          project,
          InspectionsBundle.message("inspection.export.error.writing.to", fullPath),
          InspectionsBundle.message("inspection.export.results.error.title"),
          Messages.getErrorIcon()
        );
      }
    };
    ApplicationManager.getApplication().invokeLater(showError, ModalityState.NON_MODAL);
    throw new ProcessCanceledException();
  }
}
 
Example 22
Project: hybris-integration-intellij-idea-plugin   File: ProjectRefreshAction.java   View source code 5 votes vote down vote up
public static void triggerAction(final DataContext dataContext) {
    ApplicationManager.getApplication().invokeLater(() -> {
        final AnAction action = new ProjectRefreshAction();
        final AnActionEvent actionEvent = AnActionEvent.createFromAnAction(
            action,
            null,
            ActionPlaces.UNKNOWN,
            dataContext
        );
        action.actionPerformed(actionEvent);
    }, ModalityState.NON_MODAL);
}
 
Example 23
Project: intellij-plugin   File: NavigatorUtil.java   View source code 5 votes vote down vote up
public static void invokeLater(final Project p, final ModalityState state, final Runnable r) {
    if (isNoBackgroundMode()) {
        r.run();
    } else {
        ApplicationManager.getApplication().invokeLater(DisposeAwareRunnable.create(r, p), state);
    }
}
 
Example 24
Project: intellij-plugin   File: NavigatorUtil.java   View source code 5 votes vote down vote up
public static void invokeAndWait(final Project p, final ModalityState state, final Runnable r) {
    if (isNoBackgroundMode()) {
        r.run();
    } else {
        ApplicationManager.getApplication().invokeAndWait(DisposeAwareRunnable.create(r, p), state);
    }
}
 
Example 25
Project: manifold-ij   File: HotSwapComponent.java   View source code 5 votes vote down vote up
private void hotSwapSessions( final List<DebuggerSession> sessions )
{
  HotSwapProgressImpl findClassesProgress = new HotSwapProgressImpl( getIjProject() );

  ApplicationManager.getApplication().executeOnPooledThread( () ->
  {
    final Map<DebuggerSession, Map<String, HotSwapFile>> modifiedClasses = scanForModifiedClassesWithProgress( sessions, findClassesProgress );

    final Application application = ApplicationManager.getApplication();
    if( modifiedClasses.isEmpty() )
    {
      final String message = DebuggerBundle.message( "status.hotswap.uptodate" );
      NotificationGroup.toolWindowGroup( "HotSwap", ToolWindowId.DEBUG ).createNotification( message, NotificationType.INFORMATION ).notify( getIjProject() );
      return;
    }

    application.invokeLater( () ->
    {
      if( !modifiedClasses.isEmpty() )
      {
        final HotSwapProgressImpl progress = new HotSwapProgressImpl( getIjProject() );
        if( modifiedClasses.keySet().size() == 1 )
        {
          //noinspection ConstantConditions
          progress.setSessionForActions( ContainerUtil.getFirstItem( modifiedClasses.keySet() ) );
        }
        application.executeOnPooledThread( () -> reloadModifiedClasses( modifiedClasses, progress ) );
      }
    }, ModalityState.NON_MODAL );
  } );
}
 
Example 26
Project: intellij-ce-playground   File: SetupTaskChooserAction.java   View source code 5 votes vote down vote up
@Override
public void actionPerformed(AnActionEvent e) {
  final Module module = e.getData(LangDataKeys.MODULE);
  if (module == null) return;
  final Project project = module.getProject();
  final ListChooseByNameModel<SetupTask> model = new ListChooseByNameModel<SetupTask>(project, "Enter setup.py task name",
                                                                                      "No tasks found",
                                                                                      SetupTaskIntrospector.getTaskList(module));
  final ChooseByNamePopup popup = ChooseByNamePopup.createPopup(project, model, GotoActionBase.getPsiContext(e));
  popup.setShowListForEmptyPattern(true);

  popup.invoke(new ChooseByNamePopupComponent.Callback() {
    public void onClose() {
    }

    public void elementChosen(Object element) {
      if (element != null) {
        final SetupTask task = (SetupTask) element;
        ApplicationManager.getApplication().invokeLater(new Runnable() {
          public void run() {
            runSetupTask(task.getName(), module);
          }
        }, ModalityState.NON_MODAL);
      }
    }
  }, ModalityState.current(), false);

}
 
Example 27
Project: intellij-ce-playground   File: HgCloneDialog.java   View source code 5 votes vote down vote up
@Override
protected boolean test(@NotNull final String url) {
  HgIdentifyCommand identifyCommand = new HgIdentifyCommand(myProject);
  identifyCommand.setSource(url);
  HgCommandResult result = identifyCommand.execute(ModalityState.stateForComponent(getRootPane()));
  return result != null && result.getExitValue() == 0;
}
 
Example 28
Project: intellij-ce-playground   File: LaterInvocatorTest.java   View source code 5 votes vote down vote up
public void testTrueReorder() throws InvocationTargetException, InterruptedException {
  SwingUtilities.invokeLater(() -> {
    LaterInvocator.enterModal(myWindow1);
    ApplicationManager.getApplication().invokeLater(new MyRunnable("1"), ModalityState.NON_MODAL);
    SwingUtilities.invokeLater(ENTER_MODAL);
    LaterInvocator.leaveModal(myWindow1);
    SwingUtilities.invokeLater(LEAVE_MODAL);
    ApplicationManager.getApplication().invokeLater(new MyRunnable("2"), ModalityState.NON_MODAL);
  });
  flushSwingQueue();
  flushSwingQueue();
  checkOrder(2);
}
 
Example 29
Project: PackageTemplates   File: FileWriter.java   View source code 5 votes vote down vote up
private static boolean wrapInWriteLater(Computable<Boolean> computable) {
    final boolean[] result = new boolean[1];

    ApplicationManager.getApplication().invokeAndWait(() ->
            result[0] = ApplicationManager.getApplication().runWriteAction(computable),
            ModalityState.defaultModalityState());

    return result[0];
}
 
Example 30
Project: PackageTemplates   File: FileReaderUtil.java   View source code 5 votes vote down vote up
public static String readFile(File file) {
    final String[] result = new String[1];
    ApplicationManager.getApplication().invokeAndWait(() ->
                    result[0] = ApplicationManager.getApplication().runReadAction((Computable<String>) () -> {
                        try {
                            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), Const.charsets.UTF_8));
                            StringBuilder sb = new StringBuilder();
                            String line = br.readLine();

                            boolean isFirstLine = true;

                            while (line != null) {
                                if (isFirstLine) {
                                    isFirstLine = false;
                                    sb.append(line);
                                } else {
                                    sb.append("\n");
                                    sb.append(line);
                                }

                                line = br.readLine();
                            }

                            br.close();
                            return sb.toString();
                        } catch (Exception e) {
                            Logger.log("Error read file " + e.getMessage());
                            Logger.printStack(e);
                            return null;
                        }
                    })
            , ModalityState.defaultModalityState());
    return result[0];
}
 
Example 31
Project: intellij-ce-playground   File: LaterInvocatorTest.java   View source code 5 votes vote down vote up
public void testDoesNotInvokeWhenModal() throws InvocationTargetException, InterruptedException {
  UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
    LaterInvocator.enterModal(myWindow1);

    ApplicationManager.getApplication().invokeLater(ENTER_MODAL, ModalityState.NON_MODAL);
    ApplicationManager.getApplication().invokeLater(new MyRunnable("1"), ModalityState.NON_MODAL);
    LaterInvocator.leaveModal(myWindow1);
    flushSwingQueue();
    checkOrder(0);
    LaterInvocator.leaveModal(myWindow1);
    flushSwingQueue();
    checkOrder(1);
  });
}
 
Example 32
Project: intellij-ce-playground   File: SessionDialog.java   View source code 5 votes vote down vote up
private void updateButtons() {
  setOKActionEnabled(mySession.canExecute(myChanges, myCommitMessage));
  myOKButtonUpdateAlarm.cancelAllRequests();
  myOKButtonUpdateAlarm.addRequest(new Runnable() {
    public void run() {
      updateButtons();
    }
  }, 300, ModalityState.stateForComponent(myCenterPanel));
}
 
Example 33
Project: intellij-ce-playground   File: LaterInvocatorTest.java   View source code 5 votes vote down vote up
public void testRunQueuedRunnablesOnLeavingModality() {
  UIUtil.invokeAndWaitIfNeeded(new Runnable() {
    @Override
    public void run() {
      LaterInvocator.invokeLater(ENTER_MODAL, ModalityState.NON_MODAL);
      LaterInvocator.invokeLater(new MyRunnable("3"), ModalityState.NON_MODAL);
      flushSwingQueue();
      checkOrder(0);

      final ModalityState modalityState = ModalityState.stateForComponent(myWindow1);
      LaterInvocator.invokeLater(new MyRunnable("1") {
        @Override
        public void run() {
          super.run();
          checkOrder(1);
          LaterInvocator.invokeLater(new MyRunnable("2"), modalityState);
          checkOrder(1);
          LaterInvocator.leaveModal(myWindow1);
          checkOrder(2);
        }
      }, modalityState);
      flushSwingQueue(); // let "1" run

      flushSwingQueue(); // let "3" run
      checkOrder(3);
    }
  });
}
 
Example 34
Project: intellij-ce-playground   File: SaveAndSyncHandlerImpl.java   View source code 5 votes vote down vote up
public void maybeRefresh(@NotNull ModalityState modalityState) {
  if (myBlockSyncOnFrameActivationCount.get() == 0 && mySettings.isSyncOnFrameActivation()) {
    RefreshQueue queue = RefreshQueue.getInstance();
    queue.cancelSession(myRefreshSessionId);

    RefreshSession session = queue.createSession(true, true, null, modalityState);
    session.addAllFiles(ManagingFS.getInstance().getLocalRoots());
    myRefreshSessionId = session.getId();
    session.launch();
  }
}
 
Example 35
Project: intellij-ce-playground   File: FileHistoryPanelImpl.java   View source code 5 votes vote down vote up
private void refreshImpl(final boolean useLastRevision) {
  new AbstractCalledLater(myVcs.getProject(), ModalityState.NON_MODAL) {
    public void run() {
      if (myInRefresh) return;
      myInRefresh = true;
      myTargetSelection = myDualView.getFlatView().getSelectedObjects();

      mySplitter.revalidate();
      mySplitter.repaint();

      myRefresherI.run(true, useLastRevision);
      columnSizesOnce();
    }
  }.callMe();
}
 
Example 36
Project: intellij-ce-playground   File: AvdComboBox.java   View source code 5 votes vote down vote up
private void addUpdatingRequest(@NotNull final ModalityState modalityState) {
  if (myAlarm.isDisposed()) {
    return;
  }
  myAlarm.cancelAllRequests();
  myAlarm.addRequest(new Runnable() {
    @Override
    public void run() {
      startUpdatingAvds(modalityState);
    }
  }, 500, modalityState);
}
 
Example 37
Project: intellij-ce-playground   File: TreeFileChooserDialog.java   View source code 5 votes vote down vote up
@Override
public void selectFile(@NotNull final PsiFile file) {
  // Select element in the tree
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
      if (myBuilder != null) {
        myBuilder.select(file, file.getVirtualFile(), true);
      }
    }
  }, ModalityState.stateForComponent(getWindow()));
}
 
Example 38
Project: intellij-ce-playground   File: TodoView.java   View source code 5 votes vote down vote up
private void _updateFilters() {
  try {
    updateFilters();
  }
  catch (ProcessCanceledException e) {
    DumbService.getInstance(myProject).smartInvokeLater(new Runnable() {
      @Override
      public void run() {
        _updateFilters();
      }
    }, ModalityState.NON_MODAL);
  }
}
 
Example 39
Project: intellij-ce-playground   File: ChangesViewManager.java   View source code 5 votes vote down vote up
public void projectOpened() {
  final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
  changeListManager.addChangeListListener(myListener);
  Disposer.register(myProject, new Disposable() {
    public void dispose() {
      changeListManager.removeChangeListListener(myListener);
    }
  });
  if (ApplicationManager.getApplication().isHeadlessEnvironment()) return;
  myContent = ContentFactory.SERVICE.getInstance().createContent(createChangeViewComponent(), ChangesViewContentManager.LOCAL_CHANGES, false);
  myContent.setCloseable(false);
  myContentManager.addContent(myContent);

  scheduleRefresh();
  myConnection = myProject.getMessageBus().connect(myProject);
  myConnection.subscribe(RemoteRevisionsCache.REMOTE_VERSION_CHANGED, new Runnable() {
    public void run() {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
          refreshView();
        }
      }, ModalityState.NON_MODAL, myProject.getDisposed());
    }
  });
  // not sure we should turn it on on start (and pre-select smthg - rather heavy actions..)
  /*if (VcsConfiguration.getInstance(myProject).CHANGE_DETAILS_ON) {
    myToggleDetailsAction.actionPerformed(null);
  }*/
}
 
Example 40
Project: intellij-ce-playground   File: IDEARemoteTestRunnerClient.java   View source code 5 votes vote down vote up
@Override
protected void notifyStart(final GenericMessage genericMessage) {
    DumbService.getInstance(myProject).smartInvokeLater(new Runnable() {
      public void run() {
        for (final IRemoteSuiteListener listener : m_suiteListeners) {
          listener.onInitialization(genericMessage);
        }
      }
    }, ModalityState.NON_MODAL);
}