Search in sources :

Example 1 with NotificationType

use of com.intellij.notification.NotificationType in project intellij-plugins by StepicOrg.

the class SendAction method notify.

private static void notify(@NotNull Project project, @NotNull StepNode stepNode, @Nullable String stepStatus, @NotNull String hint) {
    NotificationType notificationType;
    if (StudyStatus.of(stepStatus) == SOLVED) {
        notificationType = NotificationType.INFORMATION;
        hint = "Success!";
        stepNode.passed();
    } else {
        notificationType = NotificationType.WARNING;
    }
    String title = String.format("%s is %s", stepNode.getName(), stepStatus);
    ActionUtils.notify(project, title, hint, notificationType);
}
Also used : NotificationType(com.intellij.notification.NotificationType)

Example 2 with NotificationType

use of com.intellij.notification.NotificationType in project intellij-community by JetBrains.

the class InternetAttachSourceProvider method getActions.

@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, @Nullable PsiFile psiFile) {
    final VirtualFile jar = getJarByPsiFile(psiFile);
    if (jar == null)
        return Collections.emptyList();
    final String jarName = jar.getNameWithoutExtension();
    int index = jarName.lastIndexOf('-');
    if (index == -1)
        return Collections.emptyList();
    final String version = jarName.substring(index + 1);
    final String artifactId = jarName.substring(0, index);
    if (!ARTIFACT_IDENTIFIER.matcher(version).matches() || !ARTIFACT_IDENTIFIER.matcher(artifactId).matches()) {
        return Collections.emptyList();
    }
    final Set<Library> libraries = new HashSet<>();
    for (LibraryOrderEntry orderEntry : orderEntries) {
        ContainerUtil.addIfNotNull(libraries, orderEntry.getLibrary());
    }
    if (libraries.isEmpty())
        return Collections.emptyList();
    final String sourceFileName = jarName + "-sources.jar";
    for (Library library : libraries) {
        for (VirtualFile file : library.getFiles(OrderRootType.SOURCES)) {
            if (file.getPath().contains(sourceFileName)) {
                if (isRootInExistingFile(file)) {
                    // Sources already attached, but source-jar doesn't contain current class.
                    return Collections.emptyList();
                }
            }
        }
    }
    final File libSourceDir = getLibrarySourceDir();
    final File sourceFile = new File(libSourceDir, sourceFileName);
    if (sourceFile.exists()) {
        return Collections.singleton(new LightAttachSourcesAction() {

            @Override
            public String getName() {
                return "Attach downloaded source";
            }

            @Override
            public String getBusyText() {
                return getName();
            }

            @Override
            public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
                attachSourceJar(sourceFile, libraries);
                return ActionCallback.DONE;
            }
        });
    }
    return Collections.singleton(new LightAttachSourcesAction() {

        @Override
        public String getName() {
            return "Download...";
        }

        @Override
        public String getBusyText() {
            return "Searching...";
        }

        @Override
        public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) {
            final Task task = new Task.Modal(psiFile.getProject(), "Searching source...", true) {

                @Override
                public void run(@NotNull final ProgressIndicator indicator) {
                    String artifactUrl = null;
                    SourceSearcher[] searchers = { new MavenCentralSourceSearcher(), new SonatypeSourceSearcher() };
                    for (SourceSearcher searcher : searchers) {
                        try {
                            artifactUrl = searcher.findSourceJar(indicator, artifactId, version, jar);
                        } catch (SourceSearchException e) {
                            LOG.warn(e);
                            showMessage("Downloading failed", e.getMessage(), NotificationType.ERROR);
                            continue;
                        }
                        if (artifactUrl != null)
                            break;
                    }
                    if (artifactUrl == null) {
                        showMessage("Sources not found", "Sources for '" + jarName + ".jar' not found", NotificationType.WARNING);
                        return;
                    }
                    if (!(libSourceDir.isDirectory() || libSourceDir.mkdirs())) {
                        showMessage("Downloading failed", "Failed to create directory to store sources: " + libSourceDir, NotificationType.ERROR);
                        return;
                    }
                    try {
                        File tmpDownload = FileUtil.createTempFile(libSourceDir, "download.", ".tmp", false, false);
                        HttpRequests.request(artifactUrl).saveToFile(tmpDownload, indicator);
                        if (!sourceFile.exists() && !tmpDownload.renameTo(sourceFile)) {
                            LOG.warn("Failed to rename file " + tmpDownload + " to " + sourceFileName);
                        }
                    } catch (IOException e) {
                        LOG.warn(e);
                        showMessage("Downloading failed", "Connection problem. See log for more details.", NotificationType.ERROR);
                    }
                }

                @Override
                public void onSuccess() {
                    attachSourceJar(sourceFile, libraries);
                }

                private void showMessage(String title, String message, NotificationType notificationType) {
                    new Notification("Source searcher", title, message, notificationType).notify(getProject());
                }
            };
            task.queue();
            return ActionCallback.DONE;
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) ActionCallback(com.intellij.openapi.util.ActionCallback) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) IOException(java.io.IOException) Notification(com.intellij.notification.Notification) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) NotificationType(com.intellij.notification.NotificationType) Library(com.intellij.openapi.roots.libraries.Library) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with NotificationType

use of com.intellij.notification.NotificationType in project intellij-community by JetBrains.

the class GitPushResultNotification method create.

@NotNull
static GitPushResultNotification create(@NotNull Project project, @NotNull GitPushResult pushResult, boolean multiRepoProject) {
    GroupedPushResult grouped = GroupedPushResult.group(pushResult.getResults());
    String title;
    NotificationType type;
    if (!grouped.errors.isEmpty()) {
        if (!grouped.successful.isEmpty()) {
            title = "Push partially failed";
        } else {
            title = "Push failed";
        }
        type = NotificationType.ERROR;
    } else if (!grouped.rejected.isEmpty() || !grouped.customRejected.isEmpty()) {
        if (!grouped.successful.isEmpty()) {
            title = "Push partially rejected";
        } else {
            title = "Push rejected";
        }
        type = NotificationType.WARNING;
    } else {
        title = "Push successful";
        type = NotificationType.INFORMATION;
    }
    String description = formDescription(pushResult.getResults(), multiRepoProject);
    ViewUpdatedFilesNotificationListener listener = null;
    UpdatedFiles updatedFiles = pushResult.getUpdatedFiles();
    if (!updatedFiles.isEmpty()) {
        description += "<br/>" + VIEW_FILES_UPDATED_DURING_THE_PUSH;
        listener = new ViewUpdatedFilesNotificationListener(project, updatedFiles, pushResult.getBeforeUpdateLabel(), pushResult.getAfterUpdateLabel());
    }
    NotificationGroup group = type == NotificationType.INFORMATION ? VcsNotifier.NOTIFICATION_GROUP_ID : VcsNotifier.IMPORTANT_ERROR_NOTIFICATION;
    return new GitPushResultNotification(group.getDisplayId(), title, description, type, listener);
}
Also used : NotificationType(com.intellij.notification.NotificationType) UpdatedFiles(com.intellij.openapi.vcs.update.UpdatedFiles) NotificationGroup(com.intellij.notification.NotificationGroup) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with NotificationType

use of com.intellij.notification.NotificationType in project intellij-plugins by JetBrains.

the class BndProjectImporter method checkWarnings.

private void checkWarnings(Project project, List<String> warnings, boolean error) {
    if (warnings != null && !warnings.isEmpty()) {
        if (!isUnitTestMode()) {
            LOG.warn(warnings.toString());
            String text = message("bnd.import.warn.text", project.getName(), "<br>" + StringUtil.join(warnings, "<br>"));
            NotificationType type = error ? NotificationType.ERROR : NotificationType.WARNING;
            NOTIFICATIONS.createNotification(message("bnd.import.warn.title"), text, type, null).notify(myProject);
        } else {
            throw new AssertionError(warnings.toString());
        }
    }
}
Also used : NotificationType(com.intellij.notification.NotificationType)

Example 5 with NotificationType

use of com.intellij.notification.NotificationType in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoExternalToolsAction method error.

private static void error(@NotNull String title, @NotNull Project project, @Nullable Exception ex) {
    String message = ex == null ? "" : ExceptionUtil.getUserStackTrace(ex, LOG);
    NotificationType type = NotificationType.ERROR;
    Notifications.Bus.notify(GoConstants.GO_EXECUTION_NOTIFICATION_GROUP.createNotification(title, message, type, null), project);
}
Also used : NotificationType(com.intellij.notification.NotificationType)

Aggregations

NotificationType (com.intellij.notification.NotificationType)6 Notification (com.intellij.notification.Notification)2 NotNull (org.jetbrains.annotations.NotNull)2 NotificationGroup (com.intellij.notification.NotificationGroup)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 Library (com.intellij.openapi.roots.libraries.Library)1 ActionCallback (com.intellij.openapi.util.ActionCallback)1 UpdatedFiles (com.intellij.openapi.vcs.update.UpdatedFiles)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 File (java.io.File)1 IOException (java.io.IOException)1