Search in sources :

Example 1 with MessageType

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

the class CompileDriver method notifyCompilationCompleted.

/** @noinspection SSBasedInspection*/
private long notifyCompilationCompleted(final CompileContextImpl compileContext, final CompileStatusNotification callback, final ExitStatus _status) {
    final long duration = System.currentTimeMillis() - compileContext.getStartCompilationStamp();
    if (!myProject.isDisposed()) {
        // refresh on output roots is required in order for the order enumerator to see all roots via VFS
        final Module[] affectedModules = compileContext.getCompileScope().getAffectedModules();
        if (_status != ExitStatus.UP_TO_DATE && _status != ExitStatus.CANCELLED) {
            // have to refresh in case of errors too, because run configuration may be set to ignore errors
            Collection<String> affectedRoots = ContainerUtil.newHashSet(CompilerPathsEx.getOutputPaths(affectedModules));
            if (!affectedRoots.isEmpty()) {
                ProgressIndicator indicator = compileContext.getProgressIndicator();
                indicator.setText("Synchronizing output directories...");
                CompilerUtil.refreshOutputRoots(affectedRoots);
                indicator.setText("");
            }
        }
    }
    SwingUtilities.invokeLater(() -> {
        int errorCount = 0;
        int warningCount = 0;
        try {
            errorCount = compileContext.getMessageCount(CompilerMessageCategory.ERROR);
            warningCount = compileContext.getMessageCount(CompilerMessageCategory.WARNING);
        } finally {
            if (callback != null) {
                callback.finished(_status == ExitStatus.CANCELLED, errorCount, warningCount, compileContext);
            }
        }
        if (!myProject.isDisposed()) {
            final String statusMessage = createStatusMessage(_status, warningCount, errorCount, duration);
            final MessageType messageType = errorCount > 0 ? MessageType.ERROR : warningCount > 0 ? MessageType.WARNING : MessageType.INFO;
            if (duration > ONE_MINUTE_MS && CompilerWorkspaceConfiguration.getInstance(myProject).DISPLAY_NOTIFICATION_POPUP) {
                ToolWindowManager.getInstance(myProject).notifyByBalloon(ToolWindowId.MESSAGES_WINDOW, messageType, statusMessage);
            }
            final String wrappedMessage = _status != ExitStatus.UP_TO_DATE ? "<a href='#'>" + statusMessage + "</a>" : statusMessage;
            final Notification notification = CompilerManager.NOTIFICATION_GROUP.createNotification("", wrappedMessage, messageType.toNotificationType(), new MessagesActivationListener(compileContext)).setImportant(false);
            compileContext.getBuildSession().registerCloseAction(notification::expire);
            notification.notify(myProject);
            if (_status != ExitStatus.UP_TO_DATE && compileContext.getMessageCount(null) > 0) {
                final String msg = DateFormatUtil.formatDateTime(new Date()) + " - " + statusMessage;
                compileContext.addMessage(CompilerMessageCategory.INFORMATION, msg, null, -1, -1);
            }
        }
    });
    return duration;
}
Also used : ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Module(com.intellij.openapi.module.Module) MessageType(com.intellij.openapi.ui.MessageType) Notification(com.intellij.notification.Notification)

Example 2 with MessageType

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

the class TestsUIUtil method notifyByBalloon.

public static void notifyByBalloon(@NotNull final Project project, final AbstractTestProxy root, final TestConsoleProperties properties, TestResultPresentation testResultPresentation) {
    if (project.isDisposed())
        return;
    if (properties == null)
        return;
    TestStatusListener.notifySuiteFinished(root, properties.getProject());
    final String testRunDebugId = properties.isDebug() ? ToolWindowId.DEBUG : ToolWindowId.RUN;
    final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(project);
    final String title = testResultPresentation.getTitle();
    final String text = testResultPresentation.getText();
    final String balloonText = testResultPresentation.getBalloonText();
    final MessageType type = testResultPresentation.getType();
    if (!Comparing.strEqual(toolWindowManager.getActiveToolWindowId(), testRunDebugId)) {
        toolWindowManager.notifyByBalloon(testRunDebugId, type, balloonText, null, null);
    }
    NOTIFICATION_GROUP.createNotification(balloonText, type).notify(project);
    SystemNotifications.getInstance().notify("TestRunner", title, text);
}
Also used : ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) MessageType(com.intellij.openapi.ui.MessageType)

Example 3 with MessageType

use of com.intellij.openapi.ui.MessageType 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 4 with MessageType

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

the class AbstractSchemeActions method exportScheme.

/**
   * Export the scheme using the given exporter name.
   *
   * @param scheme The scheme to export.
   * @param exporterName The exporter name.
   * @see SchemeExporter
   * @see SchemeExporterEP
   */
protected void exportScheme(@NotNull T scheme, @NotNull String exporterName) {
    SchemeExporter<T> exporter = SchemeExporterEP.getExporter(exporterName, getSchemeType());
    if (exporter != null) {
        String ext = exporter.getExtension();
        FileSaverDialog saver = FileChooserFactory.getInstance().createSaveFileDialog(new FileSaverDescriptor(ApplicationBundle.message("scheme.exporter.ui.file.chooser.title"), ApplicationBundle.message("scheme.exporter.ui.file.chooser.message"), ext), getSchemesPanel());
        VirtualFileWrapper target = saver.save(null, SchemeManager.getDisplayName(scheme) + "." + ext);
        if (target != null) {
            VirtualFile targetFile = target.getVirtualFile(true);
            String message;
            MessageType messageType;
            if (targetFile != null) {
                try {
                    WriteAction.run(() -> {
                        OutputStream outputStream = targetFile.getOutputStream(this);
                        try {
                            exporter.exportScheme(scheme, outputStream);
                        } finally {
                            outputStream.close();
                        }
                    });
                    message = ApplicationBundle.message("scheme.exporter.ui.scheme.exported.message", scheme.getName(), getSchemesPanel().getSchemeTypeName(), targetFile.getPresentableUrl());
                    messageType = MessageType.INFO;
                } catch (Exception e) {
                    message = ApplicationBundle.message("scheme.exporter.ui.export.failed", e.getMessage());
                    messageType = MessageType.ERROR;
                }
            } else {
                message = ApplicationBundle.message("scheme.exporter.ui.cannot.write.message");
                messageType = MessageType.ERROR;
            }
            getSchemesPanel().showStatus(message, messageType);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileSaverDescriptor(com.intellij.openapi.fileChooser.FileSaverDescriptor) FileSaverDialog(com.intellij.openapi.fileChooser.FileSaverDialog) OutputStream(java.io.OutputStream) MessageType(com.intellij.openapi.ui.MessageType) VirtualFileWrapper(com.intellij.openapi.vfs.VirtualFileWrapper)

Example 5 with MessageType

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

the class IdeaGradleProjectSettingsControlBuilder method showBalloonIfNecessary.

void showBalloonIfNecessary() {
    if (!myShowBalloonIfNecessary || (myGradleHomePathField != null && !myGradleHomePathField.isEnabled())) {
        return;
    }
    myShowBalloonIfNecessary = false;
    MessageType messageType = null;
    switch(myGradleHomeSettingType) {
        case DEDUCED:
            messageType = MessageType.INFO;
            break;
        case EXPLICIT_INCORRECT:
        case UNKNOWN:
            messageType = MessageType.ERROR;
            break;
        default:
    }
    if (messageType != null) {
        new DelayedBalloonInfo(messageType, myGradleHomeSettingType, BALLOON_DELAY_MILLIS).run();
    }
}
Also used : MessageType(com.intellij.openapi.ui.MessageType)

Aggregations

MessageType (com.intellij.openapi.ui.MessageType)5 Notification (com.intellij.notification.Notification)1 Application (com.intellij.openapi.application.Application)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 FileSaverDescriptor (com.intellij.openapi.fileChooser.FileSaverDescriptor)1 FileSaverDialog (com.intellij.openapi.fileChooser.FileSaverDialog)1 Module (com.intellij.openapi.module.Module)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileWrapper (com.intellij.openapi.vfs.VirtualFileWrapper)1 IdeFrame (com.intellij.openapi.wm.IdeFrame)1 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)1 WelcomeBalloonLayoutImpl (com.intellij.openapi.wm.impl.welcomeScreen.WelcomeBalloonLayoutImpl)1 OutputStream (java.io.OutputStream)1 HyperlinkEvent (javax.swing.event.HyperlinkEvent)1 HyperlinkListener (javax.swing.event.HyperlinkListener)1