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);
}
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);
}
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;
}
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();
}
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);
}
}
}
Aggregations