Search in sources :

Example 1 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class MavenProjectsNavigator method doInit.

private void doInit() {
    listenForProjectsChanges();
    if (isUnitTestMode())
        return;
    MavenUtil.runWhenInitialized(myProject, new DumbAwareRunnable() {

        @Override
        public void run() {
            if (myProject.isDisposed())
                return;
            initToolWindow();
        }
    });
}
Also used : DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 2 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class MvcModuleStructureSynchronizer method queue.

public void queue(SyncAction action, Object on) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (myProject.isDisposed())
        return;
    boolean shouldSchedule;
    synchronized (myOrders) {
        shouldSchedule = myOrders.isEmpty();
        myOrders.add(Pair.create(on, action));
    }
    if (shouldSchedule) {
        StartupManager.getInstance(myProject).runWhenProjectIsInitialized(new DumbAwareRunnable() {

            @Override
            public void run() {
                scheduleRunActions();
            }
        });
    }
}
Also used : DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 3 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class RepositoryLibrarySynchronizer method runActivity.

@Override
public void runActivity(@NotNull final Project project) {
    StartupManager.getInstance(project).registerPostStartupActivity(new DumbAwareRunnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                @Override
                public void run() {
                    final Collection<Library> libraries = collectLibraries(project, new Predicate<Library>() {

                        @Override
                        public boolean apply(Library library) {
                            if (!(library instanceof LibraryEx)) {
                                return false;
                            }
                            LibraryEx libraryEx = (LibraryEx) library;
                            return libraryEx.getKind() == RepositoryLibraryType.REPOSITORY_LIBRARY_KIND && libraryEx.getProperties() instanceof RepositoryLibraryProperties && isLibraryNeedToBeReloaded(libraryEx, (RepositoryLibraryProperties) libraryEx.getProperties());
                        }
                    });
                    for (Library library : libraries) {
                        final LibraryEx libraryEx = (LibraryEx) library;
                        RepositoryUtils.reloadDependencies(project, libraryEx);
                    }
                }
            }, project.getDisposed());
        }
    });
}
Also used : LibraryEx(com.intellij.openapi.roots.impl.libraries.LibraryEx) Library(com.intellij.openapi.roots.libraries.Library) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Example 4 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class PyStudyShowTutorial method projectOpened.

@Override
public void projectOpened() {
    ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

        @Override
        public void run() {
            ApplicationManager.getApplication().runWriteAction(new DumbAwareRunnable() {

                @Override
                public void run() {
                    if (PropertiesComponent.getInstance().getBoolean(ourShowPopup, true)) {
                        final String content = "<html>If you'd like to learn more about PyCharm Edu, " + "click <a href=\"https://www.jetbrains.com/pycharm-edu/quickstart/\">here</a> to watch a tutorial</html>";
                        final Notification notification = new Notification("Watch Tutorials!", "", content, NotificationType.INFORMATION, new NotificationListener.UrlOpeningListener(true));
                        Notifications.Bus.notify(notification);
                        Balloon balloon = notification.getBalloon();
                        if (balloon != null) {
                            balloon.addListener(new JBPopupAdapter() {

                                @Override
                                public void onClosed(LightweightWindowEvent event) {
                                    notification.expire();
                                }
                            });
                        }
                        notification.whenExpired(() -> PropertiesComponent.getInstance().setValue(ourShowPopup, false, true));
                    }
                }
            });
        }
    });
}
Also used : Balloon(com.intellij.openapi.ui.popup.Balloon) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent)

Example 5 with DumbAwareRunnable

use of com.intellij.openapi.project.DumbAwareRunnable in project intellij-community by JetBrains.

the class BraceHighlightingHandler method lookForInjectedAndMatchBracesInOtherThread.

static void lookForInjectedAndMatchBracesInOtherThread(@NotNull final Editor editor, @NotNull final Alarm alarm, @NotNull final Processor<BraceHighlightingHandler> processor) {
    ApplicationManagerEx.getApplicationEx().assertIsDispatchThread();
    if (!isValidEditor(editor))
        return;
    if (!PROCESSED_EDITORS.add(editor)) {
        // Assuming to be in EDT here.
        return;
    }
    final int offset = editor.getCaretModel().getOffset();
    final Project project = editor.getProject();
    final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (!isValidFile(psiFile))
        return;
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(() -> {
            final PsiFile injected;
            try {
                if (psiFile instanceof PsiBinaryFile || !isValidEditor(editor) || !isValidFile(psiFile)) {
                    injected = null;
                } else {
                    injected = getInjectedFileIfAny(editor, project, offset, psiFile, alarm);
                }
            } catch (RuntimeException e) {
                // Reset processing flag in case of unexpected exception.
                ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                    @Override
                    public void run() {
                        PROCESSED_EDITORS.remove(editor);
                    }
                });
                throw e;
            }
            ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {

                @Override
                public void run() {
                    try {
                        if (isValidEditor(editor) && isValidFile(injected)) {
                            Editor newEditor = InjectedLanguageUtil.getInjectedEditorForInjectedFile(editor, injected);
                            BraceHighlightingHandler handler = new BraceHighlightingHandler(project, newEditor, alarm, injected);
                            processor.process(handler);
                        }
                    } finally {
                        PROCESSED_EDITORS.remove(editor);
                    }
                }
            }, ModalityState.stateForComponent(editor.getComponent()));
        })) {
            // write action is queued in AWT. restart after it's finished
            ApplicationManager.getApplication().invokeLater(() -> {
                PROCESSED_EDITORS.remove(editor);
                lookForInjectedAndMatchBracesInOtherThread(editor, alarm, processor);
            }, ModalityState.stateForComponent(editor.getComponent()));
        }
    });
}
Also used : Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor) LightweightHint(com.intellij.ui.LightweightHint) DumbAwareRunnable(com.intellij.openapi.project.DumbAwareRunnable)

Aggregations

DumbAwareRunnable (com.intellij.openapi.project.DumbAwareRunnable)16 ToolWindow (com.intellij.openapi.wm.ToolWindow)3 Notification (com.intellij.notification.Notification)2 NotificationListener (com.intellij.notification.NotificationListener)2 Application (com.intellij.openapi.application.Application)2 Project (com.intellij.openapi.project.Project)2 FileStatusListener (com.intellij.openapi.vcs.FileStatusListener)2 DependencyOnPlugin (com.intellij.externalDependencies.DependencyOnPlugin)1 ProjectExternalDependency (com.intellij.externalDependencies.ProjectExternalDependency)1 UISettings (com.intellij.ide.ui.UISettings)1 Editor (com.intellij.openapi.editor.Editor)1 EditorColorsListener (com.intellij.openapi.editor.colors.EditorColorsListener)1 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)1 AbstractExternalSystemSettings (com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings)1 ExternalSystemSettingsListenerAdapter (com.intellij.openapi.externalSystem.settings.ExternalSystemSettingsListenerAdapter)1 LibraryEx (com.intellij.openapi.roots.impl.libraries.LibraryEx)1 Library (com.intellij.openapi.roots.libraries.Library)1 Balloon (com.intellij.openapi.ui.popup.Balloon)1 JBPopupAdapter (com.intellij.openapi.ui.popup.JBPopupAdapter)1 LightweightWindowEvent (com.intellij.openapi.ui.popup.LightweightWindowEvent)1