/** * Associates given file with proper {@link IgnoreFileType}. * * @param fileName to associate * @param fileType file type to bind with pattern */ public static void associateFileType(@NotNull final String fileName, @NotNull final IgnoreFileType fileType) { final Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); application.invokeLater(() -> application.runWriteAction(() -> { fileTypeManager.associate(fileType, new ExactFileNameMatcher(fileName)); FILE_TYPES_ASSOCIATION_QUEUE.remove(fileName); }), ModalityState.NON_MODAL); } else if (!FILE_TYPES_ASSOCIATION_QUEUE.containsKey(fileName)) { FILE_TYPES_ASSOCIATION_QUEUE.put(fileName, fileType); } }
reset(editor); if (ApplicationManager.getApplication().isDispatchThread()) { Runnable action = new ActionRunner(editor, context, cmd, key); String name = cmd.getAction().getTemplatePresentation().getText();
public boolean execute() { Logger.getInstance(getClass()).assertTrue(!ApplicationManager.getApplication().isDispatchThread(), "It's bad idea to run external tool on EDT"); Logger.getInstance(getClass()).assertTrue(myProcessHandler == null, "Process has already run with this executor instance");
public boolean execute() { Logger.getInstance(getClass()).assertTrue(!ApplicationManager.getApplication().isDispatchThread(), "It's bad idea to run external tool on EDT"); Logger.getInstance(getClass()).assertTrue(myProcessHandler == null,
@Override @NotNull public String getPassword() { if (!ApplicationManager.getApplication().isDispatchThread()) { if (preloadedPassword == null) { throw new IllegalStateException("Need to call #preloadPassword when password is required in background thread"); } } else { if (!preloadPassword()) { return ""; } } return preloadedPassword.or(""); }
public static void runInSwingThread(Runnable runnable) { Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { runnable.run(); } else { application.invokeLater(runnable); } }
/** * * @param timeout time to wait * @param unit time unit of the time to wait * @return the result of the answer, possibly null. * @throws InterruptedException if the thread was interrupted while waiting * @throws CancellationException if the timeout was exceeded * @throws P4CommandRunner.ServerResultException the failure of the answer. */ @Nullable public S blockingGet(int timeout, @NotNull TimeUnit unit) throws InterruptedException, CancellationException, P4CommandRunner.ServerResultException { if (ApplicationManager.getApplication().isDispatchThread()) { throw new IllegalStateException("Cannot call blocking get from within the EDT."); } if (! latch.await(timeout, unit)) { throw new CancellationException("Timed out after " + timeout + " " + unit.toString().toLowerCase()); } if (error != null) { throw error; } return result; } }
@VisibleForTesting // TODO(ivanporty) move into ThreadUtil common test code. void invokeOnApplicationUIThread(Runnable runnable) { if (ApplicationManager.getApplication().isDispatchThread()) { runnable.run(); } else { ApplicationManager.getApplication().invokeLater(runnable); } }
/** * Perform a write action. If the current thread is the event dispatch thread, * then the run action will block until all other write actions complete. * * @param run function to run that contains a write action. */ public static void writeAction(@NotNull Runnable run) { final Application app = ApplicationManager.getApplication(); if (app.isDispatchThread() && !app.isWriteAccessAllowed()) { app.runWriteAction(run); } else { run.run(); } } }
@Before public void prepare() { MockitoAnnotations.initMocks(this); when(app.isDispatchThread()).thenReturn(true); when(task.isHeadless()).thenReturn(true); when(task.isConditionalModal()).thenReturn(true); when(status.tryRun()).thenReturn(true); when(factory.createTask(any(SonarLintJob.class), eq(true))).thenReturn(task); when(factory.createUserTask(any(SonarLintJob.class), eq(true))).thenReturn(task); }
public static void runInSwingThread(final Task.Backgroundable task){ Application application = ApplicationManager.getApplication(); if (application.isDispatchThread()) { task.queue(); } else { application.invokeLater(new TaskRunner(task)); } }
private void runInEDT(SonarLintTask task) { final Application app = ApplicationManager.getApplication(); // task needs to be submitted in the EDT because progress manager will get the related UI if (!app.isDispatchThread()) { app.invokeLater(() -> runTask(task)); } else { runTask(task); } }
/** * Synchronizes local helpers from {@link PerlPluginUtil#getPluginHelpersRoot() helpers root} with remote machine */ public final void syncHelpers() { if (ApplicationManager.getApplication().isDispatchThread()) { throw new RuntimeException("Should not be invoked from EDT"); } PerlRunUtil.setProgressText(PerlBundle.message("perl.host.progress.uploading.helpers")); try { doSyncHelpers(); } catch (IOException e) { LOG.error(e); } }
public final void refreshConfigConnection() { if (ApplicationManager.getApplication().isDispatchThread()) { ApplicationManager.getApplication().executeOnPooledThread(this::performRefresh); } else { performRefresh(); } }
@Test public void testRunBackground() { manager.submitBackground(mockFiles(), TriggerType.ACTION, null); verify(factory).createTask(any(SonarLintJob.class), eq(true)); verify(app).isDispatchThread(); verify(progressManager).run(task); }
@Test public void testUserTask() { manager.submitManual(mockFiles(), TriggerType.ACTION, true, null); verify(factory).createUserTask(any(SonarLintJob.class), eq(true)); verify(app).isDispatchThread(); verify(progressManager).run(task); }
/** * 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( () -> Messages.showErrorDialog(message, title), ModalityState.defaultModalityState()); } } }
@Override public ProjectData loadCoverageData(@NotNull File sessionDataFile, @Nullable CoverageSuite baseCoverageSuite) { if (!(baseCoverageSuite instanceof PerlCoverageSuite)) { return null; } if (ApplicationManager.getApplication().isDispatchThread()) { final Ref<ProjectData> projectDataRef = new Ref<>(); ProgressManager.getInstance().runProcessWithProgressSynchronously( () -> projectDataRef.set(doLoadCoverageData(sessionDataFile, (PerlCoverageSuite)baseCoverageSuite)), "Loading Coverage Data...", true, baseCoverageSuite.getProject()); return projectDataRef.get(); } else { return doLoadCoverageData(sessionDataFile, (PerlCoverageSuite)baseCoverageSuite); } }
@Override public void actionPerformed(@NotNull VcsContext event) { final Project project = event.getProject(); if (project == null) { return; } final ProjectConfigRegistry registry = ProjectConfigRegistry.getInstance(project); if (registry == null) { return; } final List<ChangeList> changeLists = getSelectedChangeLists(event); if (changeLists.isEmpty()) { return; } if (ApplicationManager.getApplication().isDispatchThread()) { ApplicationManager.getApplication().saveAll(); } ApplicationManager.getApplication().executeOnPooledThread(() -> createSwarmReviews(project, registry, changeLists)); }
@NotNull @Override public Process createProcess() throws ExecutionException { if (!myUsePty && ApplicationManager.getApplication().isDispatchThread()) { throw new RuntimeException("Non-console executions should not be performed on EDT"); } LOG.info("Executing: " + getCommandLineString()); LOG.info(" environment: " + getEnvironment() + " (+" + getParentEnvironmentType() + ")"); LOG.info(" host = " + getEffectiveHostData() + "; vm = " + getEffectiveVersionManagerData() + "; pty = " + isUsePty() + "; charset: " + getCharset()); return myUsePty ? new PtyCommandLine(this) .withConsoleMode(true) .withInitialColumns(256) .withEnvironment("TERM", "xterm-256color") .createProcess() : super.createProcess(); } }