Search in sources :

Example 6 with ApplicationEx

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

the class NotificationsManagerImpl method showNotification.

private static void showNotification(@NotNull final Notification notification, @Nullable final Project project) {
    Application application = ApplicationManager.getApplication();
    if (application instanceof ApplicationEx && !((ApplicationEx) application).isLoaded()) {
        application.invokeLater(() -> showNotification(notification, project), ModalityState.current());
        return;
    }
    String groupId = notification.getGroupId();
    final NotificationSettings settings = NotificationsConfigurationImpl.getSettings(groupId);
    NotificationDisplayType type = settings.getDisplayType();
    String toolWindowId = NotificationsConfigurationImpl.getInstanceImpl().getToolWindowId(groupId);
    if (type == NotificationDisplayType.TOOL_WINDOW && (toolWindowId == null || project == null || !ToolWindowManager.getInstance(project).canShowNotification(toolWindowId))) {
        type = NotificationDisplayType.BALLOON;
    }
    switch(type) {
        case NONE:
            return;
        //  break;
        case STICKY_BALLOON:
        case BALLOON:
        default:
            Balloon balloon = notifyByBalloon(notification, type, project);
            if (project == null || project.isDefault()) {
                return;
            }
            if (!settings.isShouldLog() || type == NotificationDisplayType.STICKY_BALLOON) {
                if (balloon == null) {
                    notification.expire();
                } else {
                    balloon.addListener(new JBPopupAdapter() {

                        @Override
                        public void onClosed(LightweightWindowEvent event) {
                            if (!event.isOk()) {
                                notification.expire();
                            }
                        }
                    });
                }
            }
            break;
        case TOOL_WINDOW:
            MessageType messageType = notification.getType() == NotificationType.ERROR ? MessageType.ERROR : notification.getType() == NotificationType.WARNING ? MessageType.WARNING : MessageType.INFO;
            final NotificationListener notificationListener = notification.getListener();
            HyperlinkListener listener = notificationListener == null ? null : new HyperlinkListener() {

                @Override
                public void hyperlinkUpdate(HyperlinkEvent e) {
                    notificationListener.hyperlinkUpdate(notification, e);
                }
            };
            assert toolWindowId != null;
            String msg = notification.getTitle();
            if (StringUtil.isNotEmpty(notification.getContent())) {
                if (StringUtil.isNotEmpty(msg)) {
                    msg += "<br>";
                }
                msg += notification.getContent();
            }
            Window window = findWindowForBalloon(project);
            if (window instanceof IdeFrame) {
                BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
                if (layout != null) {
                    ((BalloonLayoutImpl) layout).remove(notification);
                }
            }
            //noinspection SSBasedInspection
            ToolWindowManager.getInstance(project).notifyByBalloon(toolWindowId, messageType, msg, notification.getIcon(), listener);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) IdeFrame(com.intellij.openapi.wm.IdeFrame) WelcomeBalloonLayoutImpl(com.intellij.openapi.wm.impl.welcomeScreen.WelcomeBalloonLayoutImpl) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) HyperlinkListener(javax.swing.event.HyperlinkListener) Application(com.intellij.openapi.application.Application) MessageType(com.intellij.openapi.ui.MessageType)

Example 7 with ApplicationEx

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

the class InvalidateCachesAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
    final boolean mac = Messages.canShowMacSheetPanel();
    boolean canRestart = app.isRestartCapable();
    String[] options = new String[canRestart ? 4 : 3];
    options[0] = canRestart ? "Invalidate and &Restart" : "Invalidate and &Exit";
    options[1] = mac ? "Cancel" : "&Invalidate";
    options[2] = mac ? "&Invalidate" : "Cancel";
    if (canRestart) {
        options[3] = "&Just Restart";
    }
    List<String> descriptions = new SmartList<>();
    descriptions.add("Local History");
    for (CachesInvalidator invalidater : CachesInvalidator.EP_NAME.getExtensions()) {
        ContainerUtil.addIfNotNull(descriptions, invalidater.getDescription());
    }
    Collections.sort(descriptions);
    String warnings = "WARNING: ";
    if (descriptions.size() == 1) {
        warnings += descriptions.get(0) + " will be also cleared.";
    } else {
        warnings += "The following items will also be cleared:\n" + StringUtil.join(descriptions, s -> "  " + s, "\n");
    }
    String message = "The caches will be invalidated and rebuilt on the next startup.\n\n" + warnings + "\n\n" + "Would you like to continue?\n";
    int result = Messages.showDialog(e.getData(CommonDataKeys.PROJECT), message, "Invalidate Caches", options, 0, Messages.getWarningIcon());
    if (result == -1 || result == (mac ? 1 : 2)) {
        return;
    }
    if (result == 3) {
        app.restart(true);
        return;
    }
    UsageTrigger.trigger(ApplicationManagerEx.getApplicationEx().getName() + ".caches.invalidated");
    FSRecords.invalidateCaches();
    for (CachesInvalidator invalidater : CachesInvalidator.EP_NAME.getExtensions()) {
        invalidater.invalidateCaches();
    }
    if (result == 0)
        app.restart(true);
}
Also used : CachesInvalidator(com.intellij.ide.caches.CachesInvalidator) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) SmartList(com.intellij.util.SmartList)

Example 8 with ApplicationEx

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

the class AppUIUtil method showPrivacyPolicyAgreement.

/**
   * @param htmlText Updated version of Privacy Policy text if any.
   *                 If it's {@code null}, the standard text from bundled resources would be used.
   */
public static void showPrivacyPolicyAgreement(@NotNull String htmlText) {
    DialogWrapper dialog = new DialogWrapper(true) {

        @Nullable
        @Override
        protected JComponent createCenterPanel() {
            JPanel centerPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
            JEditorPane viewer = SwingHelper.createHtmlViewer(true, null, JBColor.WHITE, JBColor.BLACK);
            viewer.setFocusable(true);
            viewer.addHyperlinkListener(new HyperlinkAdapter() {

                @Override
                protected void hyperlinkActivated(HyperlinkEvent e) {
                    URL url = e.getURL();
                    if (url != null) {
                        BrowserUtil.browse(url);
                    } else {
                        SwingHelper.scrollToReference(viewer, e.getDescription());
                    }
                }
            });
            viewer.setText(htmlText);
            StyleSheet styleSheet = ((HTMLDocument) viewer.getDocument()).getStyleSheet();
            styleSheet.addRule("body {font-family: \"Segoe UI\", Tahoma, sans-serif;}");
            styleSheet.addRule("body {margin-top:0;padding-top:0;}");
            styleSheet.addRule("body {font-size:" + JBUI.scaleFontSize(13) + "pt;}");
            styleSheet.addRule("h2, em {margin-top:" + JBUI.scaleFontSize(20) + "pt;}");
            styleSheet.addRule("h1, h2, h3, p, h4, em {margin-bottom:0;padding-bottom:0;}");
            styleSheet.addRule("p, h1 {margin-top:0;padding-top:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("li {margin-bottom:" + JBUI.scaleFontSize(6) + "pt;}");
            styleSheet.addRule("h2 {margin-top:0;padding-top:" + JBUI.scaleFontSize(13) + "pt;}");
            viewer.setCaretPosition(0);
            viewer.setBorder(JBUI.Borders.empty(0, 5, 5, 5));
            centerPanel.add(new JLabel("Please read and accept these terms and conditions:"), BorderLayout.NORTH);
            centerPanel.add(new JBScrollPane(viewer, VERTICAL_SCROLLBAR_AS_NEEDED, HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
            return centerPanel;
        }

        @Override
        protected void createDefaultActions() {
            super.createDefaultActions();
            init();
            setOKButtonText("Accept");
            setCancelButtonText("Reject and Exit");
            setAutoAdjustable(false);
        }

        @Override
        public void doCancelAction() {
            super.doCancelAction();
            ApplicationEx application = ApplicationManagerEx.getApplicationEx();
            if (application == null) {
                System.exit(Main.PRIVACY_POLICY_REJECTION);
            } else {
                ((ApplicationImpl) application).exit(true, true, false);
            }
        }
    };
    dialog.setModal(true);
    dialog.setTitle(ApplicationNamesInfo.getInstance().getFullProductName() + " Privacy Policy Agreement");
    dialog.setSize(JBUI.scale(509), JBUI.scale(395));
    dialog.show();
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) HTMLDocument(javax.swing.text.html.HTMLDocument) ApplicationImpl(com.intellij.openapi.application.impl.ApplicationImpl) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) URL(java.net.URL) StyleSheet(javax.swing.text.html.StyleSheet) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 9 with ApplicationEx

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

the class LightPlatformTestCase method runBare.

@SuppressWarnings("AssignmentToStaticFieldFromInstanceMethod")
@Override
public final void runBare() throws Throwable {
    if (!shouldRunTest()) {
        return;
    }
    TestRunnerUtil.replaceIdeEventQueueSafely();
    EdtTestUtil.runInEdtAndWait(() -> {
        try {
            ourTestThread = Thread.currentThread();
            startRunAndTear();
        } finally {
            ourTestThread = null;
            try {
                Application application = ApplicationManager.getApplication();
                if (application instanceof ApplicationEx) {
                    PlatformTestCase.cleanupApplicationCaches(ourProject);
                }
                resetAllFields();
            } catch (Throwable e) {
                //noinspection CallToPrintStackTrace
                e.printStackTrace();
            }
        }
    });
    // just to make sure all deferred Runnables to finish
    SwingUtilities.invokeAndWait(EmptyRunnable.getInstance());
    if (IdeaLogger.ourErrorsOccurred != null) {
        throw IdeaLogger.ourErrorsOccurred;
    }
}
Also used : ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) IdeaTestApplication(com.intellij.idea.IdeaTestApplication) Application(com.intellij.openapi.application.Application) MockApplication(com.intellij.mock.MockApplication)

Example 10 with ApplicationEx

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

the class PatchInstallerUtil method askAboutRestart.

/**
   * If a patch fails to install because Studio is locking some of the files, we have to restart studio. Ask if the user wants
   * to, and then move things into place so they can be picked up on restart.
   */
private static void askAboutRestart(@NotNull PatchRunner patchRunner, @NotNull PatchOperation op, @NotNull final File patchFile, @NotNull FileOp fop, @NotNull final ProgressIndicator progress) {
    final ApplicationEx application = ApplicationManagerEx.getApplicationEx();
    application.invokeLater(() -> {
        String[] options;
        ApplicationNamesInfo names = ApplicationNamesInfo.getInstance();
        boolean restartable = application.isRestartCapable();
        if (restartable) {
            options = new String[] { "Cancel", "Restart Later", "Restart Now" };
        } else {
            options = new String[] { "Cancel", String.format("Exit %s", names.getProductName()) };
        }
        String message;
        if (op.getExisting() != null) {
            message = String.format("%1$s is currently in use by %2$s and cannot be updated. Please restart to complete installation.", op.getExisting().getDisplayName(), names.getFullProductName());
        } else {
            message = String.format("Some files in the destination are currently in use by %1$s. Please restart to complete installation.", names.getFullProductName());
        }
        int result = Messages.showDialog((Project) null, message, "Restart Required", options, options.length - 1, AllIcons.General.QuestionDialog);
        if (result == 0) {
            progress.logInfo("Cancelled");
        } else {
            if (setupPatchDir(patchFile, patchRunner.getPatcherJar(), op.getPackage(), op.getRepoManager(), fop, progress)) {
                if (result == 1 && restartable) {
                    progress.logInfo("Installation will continue after restart");
                } else {
                    application.exit(true, true);
                }
            }
        }
    }, ModalityState.any());
}
Also used : ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) ApplicationNamesInfo(com.intellij.openapi.application.ApplicationNamesInfo)

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