Java Code Examples for com.intellij.openapi.application.Application#invokeLater()
The following examples show how to use
com.intellij.openapi.application.Application#invokeLater() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KPXStartupNotification.java From IntelliJ-Key-Promoter-X with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void runActivity(@NotNull Project project) { if (ApplicationManager.getApplication().isUnitTestMode()) return; final Application application = ApplicationManager.getApplication(); final KeyPromoterSettings settings = ServiceManager.getService(KeyPromoterSettings.class); final String installedVersion = settings.getInstalledVersion(); final IdeaPluginDescriptor plugin = PluginManagerCore.getPlugin(PluginId.getId("Key Promoter X")); if (installedVersion != null && plugin != null) { final int compare = VersionComparatorUtil.compare(installedVersion, plugin.getVersion()); // if (true) { // TODO: Don't forget to remove that! For proofreading. if (compare < 0) { application.invokeLater(() -> KPXStartupDialog.showStartupDialog(project)); settings.setInstalledVersion(plugin.getVersion()); } } }
Example 2
Source File: CompilerTask.java From consulo with Apache License 2.0 | 6 votes |
public void addMessage(final CompilerMessage message) { final CompilerMessageCategory messageCategory = message.getCategory(); if (CompilerMessageCategory.WARNING.equals(messageCategory)) { myWarningCount += 1; } else if (CompilerMessageCategory.ERROR.equals(messageCategory)) { myErrorCount += 1; informWolf(message); } Application application = Application.get(); if (application.isDispatchThread()) { // implicit ui thread //noinspection RequiredXAction doAddMessage(message); } else { application.invokeLater(() -> { if (!myProject.isDisposed()) { doAddMessage(message); } }, ModalityState.NON_MODAL); } }
Example 3
Source File: AsyncRateLimiter.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
private void performRequestOnUiThread() { final Runnable doRun = () -> { if (requestScheduler.isDisposed()) { return; } performRequest(); }; final Application app = ApplicationManager.getApplication(); if (app == null || app.isUnitTestMode()) { // This case exists to support unittesting. SwingUtilities.invokeLater(doRun); } else { app.invokeLater(doRun); } }
Example 4
Source File: VcsBalloonProblemNotifier.java From consulo with Apache License 2.0 | 6 votes |
private static void show(final Project project, final String message, final MessageType type, final boolean showOverChangesView, @Nullable final NamedRunnable[] notificationListener) { final Application application = ApplicationManager.getApplication(); if (application.isHeadlessEnvironment()) return; final Runnable showErrorAction = new Runnable() { public void run() { new VcsBalloonProblemNotifier(project, message, type, showOverChangesView, notificationListener).run(); } }; if (application.isDispatchThread()) { showErrorAction.run(); } else { application.invokeLater(showErrorAction); } }
Example 5
Source File: ExecutionUtil.java From aem-ide-tooling-4-intellij with Apache License 2.0 | 6 votes |
public static void queueTaskLater(final Task task) { final Application app = ApplicationManager.getApplication(); if (app.isDispatchThread()) { task.queue(); } else { app.invokeLater( new Runnable() { @Override public void run() { task.queue(); String test3 = "done"; } }, ModalityState.any() ); String test4 = "done"; } }
Example 6
Source File: VirtualFileManagerImpl.java From consulo with Apache License 2.0 | 6 votes |
@Override public void notifyPropertyChanged(@Nonnull final VirtualFile virtualFile, @Nonnull final String property, final Object oldValue, final Object newValue) { final Application application = ApplicationManager.getApplication(); final Runnable runnable = new Runnable() { @Override public void run() { if (virtualFile.isValid() && !application.isDisposed()) { application.runWriteAction(new Runnable() { @Override public void run() { List<VFilePropertyChangeEvent> events = Collections.singletonList(new VFilePropertyChangeEvent(this, virtualFile, property, oldValue, newValue, false)); BulkFileListener listener = application.getMessageBus().syncPublisher(VirtualFileManager.VFS_CHANGES); listener.before(events); listener.after(events); } }); } } }; application.invokeLater(runnable, ModalityState.NON_MODAL); }
Example 7
Source File: GenericNotifierImpl.java From consulo with Apache License 2.0 | 6 votes |
public void clear() { final List<MyNotification> notifications; synchronized (myLock) { notifications = new ArrayList<MyNotification>(myState.values()); myState.clear(); } final Application application = ApplicationManager.getApplication(); final Runnable runnable = new Runnable() { public void run() { for (MyNotification notification : notifications) { notification.expire(); } } }; if (application.isDispatchThread()) { runnable.run(); } else { application.invokeLater(runnable, ModalityState.NON_MODAL, myProject.getDisposed()); } }
Example 8
Source File: FloobitsWindowManager.java From floobits-intellij with Apache License 2.0 | 6 votes |
public void updateUserList() { Application app = ApplicationManager.getApplication(); if (app == null) { return; } app.invokeLater(new Runnable() { @Override public void run() { FlooHandler flooHandler = context.getFlooHandler(); if (flooHandler == null) { return; } chatForm.updateGravatars(); chatForm.updateFollowing(flooHandler.state.followedUsers); updateTitle(); } }, ModalityState.NON_MODAL); }
Example 9
Source File: OnEventDispatchThread.java From PhpMetrics-jetbrains with MIT License | 5 votes |
@Override public void onSuccess(final String output) { final Application application = ApplicationManager.getApplication(); application.invokeLater(new Runnable() { @Override public void run() { decorated.onSuccess(output); } }, modalityStateFor(modifiedComponent)); }
Example 10
Source File: EdtExecutorServiceImpl.java From consulo with Apache License 2.0 | 5 votes |
@Override public void execute(@Nonnull Runnable command, @Nonnull ModalityState modalityState) { Application application = ApplicationManager.getApplication(); if (application == null) { SwingUtilities.invokeLater(command); } else { application.invokeLater(command, modalityState); } }
Example 11
Source File: CompilerTask.java From consulo with Apache License 2.0 | 5 votes |
private void closeUI() { Application application = Application.get(); application.invokeLater(() -> { final boolean shouldRetainView = myErrorCount > 0 || myWarningCount > 0 && !ProblemsView.getInstance(myProject).isHideWarnings(); if (shouldRetainView) { ProblemsView.getInstance(myProject).selectFirstMessage(); } else { ProblemsView.getInstance(myProject).showOrHide(true); } }, ModalityState.NON_MODAL); }
Example 12
Source File: QueueProcessor.java From consulo with Apache License 2.0 | 5 votes |
private boolean startProcessing() { LOG.assertTrue(Thread.holdsLock(myQueue)); if (isProcessing || !myStarted) { return false; } isProcessing = true; final T item = myQueue.removeFirst(); final Runnable runnable = new Runnable() { @Override public void run() { if (myDeathCondition.value(null)) return; runSafely(new Runnable() { @Override public void run() { myProcessor.consume(item, myContinuationContext); } }); } }; final Application application = ApplicationManager.getApplication(); if (myThreadToUse == ThreadToUse.AWT) { final ModalityState state = myModalityState.remove(new MyOverrideEquals(item)); if (state != null) { application.invokeLater(runnable, state); } else { application.invokeLater(runnable); } } else { application.executeOnPooledThread(runnable); } return true; }
Example 13
Source File: IgnoreManager.java From idea-gitignore with MIT License | 5 votes |
/** * 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); } }
Example 14
Source File: OnEventDispatchThread.java From PhpMetrics-jetbrains with MIT License | 5 votes |
@Override public void onError(final String error, final String output, final int exitCode) { final Application application = ApplicationManager.getApplication(); application.invokeLater(new Runnable() { @Override public void run() { decorated.onError(error, output, exitCode); } }, modalityStateFor(modifiedComponent)); }
Example 15
Source File: OnEventCreateFix.java From litho with Apache License 2.0 | 5 votes |
@Override public void invoke(Project project, Editor editor, PsiFile file) throws IncorrectOperationException { final AtomicReference<PsiMethod> eventMethodRef = new AtomicReference<>(); final Runnable generateOnEvent = () -> OnEventGenerateAction.createHandler( (context, eventProject) -> event, eventMethodRef::set) .invoke(project, editor, file); final Runnable updateArgumentList = () -> Optional.ofNullable(eventMethodRef.get()) .map( eventMethod -> AddArgumentFix.createArgumentList( methodCall, clsName, eventMethod.getName(), JavaPsiFacade.getInstance(project).getElementFactory())) .ifPresent(argumentList -> methodCall.getArgumentList().replace(argumentList)); final Runnable action = () -> { TransactionGuard.getInstance().submitTransactionAndWait(generateOnEvent); WriteCommandAction.runWriteCommandAction(project, updateArgumentList); ComponentGenerateUtils.updateLayoutComponent(layoutCls); LithoLoggerProvider.getEventLogger().log(EventLogger.EVENT_FIX_EVENT_HANDLER + ".new"); }; final Application application = ApplicationManager.getApplication(); if (application.isUnitTestMode()) { action.run(); } else { application.invokeLater(action); } }
Example 16
Source File: ApplicationUtil.java From consulo with Apache License 2.0 | 5 votes |
public static void showDialogAfterWriteAction(@Nonnull Runnable runnable) { Application application = ApplicationManager.getApplication(); if (application.isWriteAccessAllowed()) { application.invokeLater(runnable); } else { runnable.run(); } }
Example 17
Source File: ProgressIndicatorUtils.java From consulo with Apache License 2.0 | 5 votes |
/** * Ensure the current EDT activity finishes in case it requires many write actions, with each being delayed a bit * by background thread read action (until its first checkCanceled call). Shouldn't be called from under read action. */ public static void yieldToPendingWriteActions() { Application application = ApplicationManager.getApplication(); if (application.isReadAccessAllowed()) { throw new IllegalStateException("Mustn't be called from within read action"); } if (application.isDispatchThread()) { throw new IllegalStateException("Mustn't be called from EDT"); } Semaphore semaphore = new Semaphore(1); application.invokeLater(semaphore::up, ModalityState.any()); awaitWithCheckCanceled(semaphore, ProgressIndicatorProvider.getGlobalProgressIndicator()); }
Example 18
Source File: AsyncUtils.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void invokeLater(Runnable runnable) { final Application app = ApplicationManager.getApplication(); if (app == null || app.isUnitTestMode()) { // This case existing to support unit testing. SwingUtilities.invokeLater(runnable); } else { app.invokeLater(runnable); } }
Example 19
Source File: MessageBusUtil.java From consulo with Apache License 2.0 | 5 votes |
public static <T> void invokeLaterIfNeededOnSyncPublisher(final Project project, final Topic<T> topic, final Consumer<T> listener) { final Application application = ApplicationManager.getApplication(); final Runnable runnable = createPublisherRunnable(project, topic, listener); if (application.isDispatchThread()) { runnable.run(); } else { application.invokeLater(runnable); } }
Example 20
Source File: AbstractVcsHelperImpl.java From consulo with Apache License 2.0 | 4 votes |
@Override public void run(@Nonnull final ProgressIndicator indicator) { final AsynchConsumer<List<CommittedChangeList>> appender = myDlg.getAppender(); final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<>(10, appender, -1); final Application application = ApplicationManager.getApplication(); try { myProvider.loadCommittedChanges(mySettings, myLocation, 0, new AsynchConsumer<CommittedChangeList>() { @Override public void consume(CommittedChangeList committedChangeList) { myRevisionsReturned = true; bufferedListConsumer.consumeOne(committedChangeList); if (myCanceled) { indicator.cancel(); } } @Override public void finished() { bufferedListConsumer.flush(); appender.finished(); if (! myRevisionsReturned) { application.invokeLater(new Runnable() { @Override public void run() { myDlg.close(-1); } }, ModalityState.stateForComponent(myDlg.getWindow())); } } }); } catch (VcsException e) { myExceptions.add(e); application.invokeLater(new Runnable() { @Override public void run() { myDlg.close(-1); } }, ModalityState.stateForComponent(myDlg.getWindow())); } }