Search in sources :

Example 16 with ApplicationEx

use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.

the class PluginManagerMain method notifyPluginsUpdated.

public static void notifyPluginsUpdated(@Nullable Project project) {
    final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
    String title = IdeBundle.message("update.notifications.title");
    String action = IdeBundle.message(app.isRestartCapable() ? "ide.restart.action" : "ide.shutdown.action");
    String message = IdeBundle.message("ide.restart.required.notification", action, ApplicationNamesInfo.getInstance().getFullProductName());
    NotificationListener listener = new NotificationListener() {

        @Override
        public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            notification.expire();
            app.restart(true);
        }
    };
    UpdateChecker.NOTIFICATIONS.createNotification(title, XmlStringUtil.wrapInHtml(message), NotificationType.INFORMATION, listener).notify(project);
}
Also used : HTMLFrameHyperlinkEvent(javax.swing.text.html.HTMLFrameHyperlinkEvent) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 17 with ApplicationEx

use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.

the class LoadAllVfsStoredContentsAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    String m = "Started loading content";
    LOG.info(m);
    System.out.println(m);
    long start = System.currentTimeMillis();
    count.set(0);
    totalSize.set(0);
    ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(() -> {
        PersistentFS vfs = (PersistentFS) application.getComponent(ManagingFS.class);
        VirtualFile[] roots = vfs.getRoots();
        for (VirtualFile root : roots) {
            iterateCached(root);
        }
    }, "Loading", false, null);
    long end = System.currentTimeMillis();
    String message = "Finished loading content of " + count + " files. " + "Total size=" + StringUtil.formatFileSize(totalSize.get()) + ". " + "Elapsed=" + ((end - start) / 1000) + "sec.";
    LOG.info(message);
    System.out.println(message);
}
Also used : NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) PersistentFS(com.intellij.openapi.vfs.newvfs.persistent.PersistentFS) ManagingFS(com.intellij.openapi.vfs.newvfs.ManagingFS)

Example 18 with ApplicationEx

use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.

the class ProgressIndicatorUtils method runWithWriteActionPriority.

public static boolean runWithWriteActionPriority(@NotNull Runnable action, @NotNull ProgressIndicator progressIndicator) {
    final ApplicationEx application = (ApplicationEx) ApplicationManager.getApplication();
    if (application.isDispatchThread()) {
        throw new IllegalStateException("Must not call from EDT");
    }
    if (application.isWriteActionPending()) {
        // tryRunReadAction below would just run without really checking if a write action is pending
        if (!progressIndicator.isCanceled())
            progressIndicator.cancel();
        return false;
    }
    final ApplicationAdapter listener = new ApplicationAdapter() {

        @Override
        public void beforeWriteActionStart(@NotNull Object action) {
            if (!progressIndicator.isCanceled())
                progressIndicator.cancel();
        }
    };
    boolean succeededWithAddingListener = application.tryRunReadAction(() -> {
        // Even if writeLock.lock() acquisition is in progress at this point then runProcess will block wanting read action which is
        // also ok as last resort.
        application.addApplicationListener(listener);
    });
    if (!succeededWithAddingListener) {
        // second catch: writeLock.lock() acquisition is in progress or already acquired
        if (!progressIndicator.isCanceled())
            progressIndicator.cancel();
        return false;
    }
    final Ref<Boolean> wasCancelled = new Ref<>();
    try {
        ProgressManager.getInstance().runProcess(() -> {
            try {
                action.run();
            } catch (ProcessCanceledException ignore) {
                wasCancelled.set(Boolean.TRUE);
            }
        }, progressIndicator);
    } finally {
        application.removeApplicationListener(listener);
    }
    return wasCancelled.get() != Boolean.TRUE;
}
Also used : Ref(com.intellij.openapi.util.Ref) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) ApplicationAdapter(com.intellij.openapi.application.ApplicationAdapter) NotNull(org.jetbrains.annotations.NotNull) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 19 with ApplicationEx

use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.

the class ProjectImpl method dispose.

@Override
public synchronized void dispose() {
    ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    // dispose must be under write action
    application.assertWriteAccessAllowed();
    // can call dispose only via com.intellij.ide.impl.ProjectUtil.closeAndDispose()
    if (ProjectManagerEx.getInstanceEx().isProjectOpened(this)) {
        throw new IllegalStateException("Must call .dispose() for a closed project only. See ProjectManager.closeProject() or ProjectUtil.closeAndDispose().");
    }
    // we use super here, because temporarilyDisposed will be true if project closed
    LOG.assertTrue(!super.isDisposed(), this + " is disposed already");
    if (myProjectManagerListener != null) {
        myProjectManager.removeProjectManagerListener(this, myProjectManagerListener);
    }
    disposeComponents();
    Extensions.disposeArea(this);
    myProjectManager = null;
    myProjectManagerListener = null;
    super.dispose();
    if (!application.isDisposed()) {
        application.getMessageBus().syncPublisher(ProjectLifecycleListener.TOPIC).afterProjectClosed(this);
    }
    TimedReference.disposeTimed();
}
Also used : ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx)

Example 20 with ApplicationEx

use of com.intellij.openapi.application.ex.ApplicationEx in project intellij-community by JetBrains.

the class RegistryUi method processClose.

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(() -> app.restart(true), ModalityState.NON_MODAL);
        }
    }
}
Also used : ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) ApplicationInfo(com.intellij.openapi.application.ApplicationInfo)

Aggregations

ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)21 NotNull (org.jetbrains.annotations.NotNull)5 IOException (java.io.IOException)4 Application (com.intellij.openapi.application.Application)3 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)2 Project (com.intellij.openapi.project.Project)2 SmartList (com.intellij.util.SmartList)2 THashMap (gnu.trove.THashMap)2 HyperlinkEvent (javax.swing.event.HyperlinkEvent)2 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)1 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)1 AsyncFuture (com.intellij.concurrency.AsyncFuture)1 AsyncUtil (com.intellij.concurrency.AsyncUtil)1 JobLauncher (com.intellij.concurrency.JobLauncher)1 GeneralSettings (com.intellij.ide.GeneralSettings)1 SaveAndSyncHandlerImpl (com.intellij.ide.SaveAndSyncHandlerImpl)1 CachesInvalidator (com.intellij.ide.caches.CachesInvalidator)1 IdeaApplication (com.intellij.idea.IdeaApplication)1 IdeaTestApplication (com.intellij.idea.IdeaTestApplication)1 MockApplication (com.intellij.mock.MockApplication)1