Search in sources :

Example 31 with Notification

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

the class VcsBalloonProblemNotifier method run.

public void run() {
    final Notification notification;
    if (myNotificationListener != null && myNotificationListener.length > 0) {
        final StringBuilder sb = new StringBuilder(myMessage);
        for (NamedRunnable runnable : myNotificationListener) {
            final String name = runnable.toString();
            sb.append("<br/><a href=\"").append(name).append("\">").append(name).append("</a>");
        }
        NotificationListener listener = (currentNotification, event) -> {
            if (HyperlinkEvent.EventType.ACTIVATED.equals(event.getEventType())) {
                if (myNotificationListener.length == 1) {
                    myNotificationListener[0].run();
                } else {
                    final String description = event.getDescription();
                    if (description != null) {
                        for (NamedRunnable runnable : myNotificationListener) {
                            if (description.equals(runnable.toString())) {
                                runnable.run();
                                break;
                            }
                        }
                    }
                }
                currentNotification.expire();
            }
        };
        notification = NOTIFICATION_GROUP.createNotification("", sb.toString(), myMessageType.toNotificationType(), listener);
    } else {
        notification = NOTIFICATION_GROUP.createNotification(myMessage, myMessageType);
    }
    notification.notify(myProject.isDefault() ? null : myProject);
}
Also used : Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) Application(com.intellij.openapi.application.Application) MessageType(com.intellij.openapi.ui.MessageType) HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotificationGroup(com.intellij.notification.NotificationGroup) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Project(com.intellij.openapi.project.Project) ChangesViewContentManager(com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager) NamedRunnable(com.intellij.openapi.util.NamedRunnable) NotNull(org.jetbrains.annotations.NotNull) NotificationListener(com.intellij.notification.NotificationListener) NamedRunnable(com.intellij.openapi.util.NamedRunnable) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 32 with Notification

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

the class VcsTestUtil method assertNotificationShown.

public static void assertNotificationShown(@NotNull Project project, @Nullable Notification expected) {
    if (expected != null) {
        Notification actualNotification = ((TestVcsNotifier) VcsNotifier.getInstance(project)).getLastNotification();
        assertNotNull("No notification was shown", actualNotification);
        assertEquals("Notification has wrong title", expected.getTitle(), actualNotification.getTitle());
        assertEquals("Notification has wrong type", expected.getType(), actualNotification.getType());
        assertEquals("Notification has wrong content", adjustTestContent(expected.getContent()), actualNotification.getContent());
    }
}
Also used : Notification(com.intellij.notification.Notification)

Example 33 with Notification

use of com.intellij.notification.Notification 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 34 with Notification

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

the class IvyAttachSourceProvider method getActions.

@NotNull
@Override
public Collection<AttachSourcesAction> getActions(List<LibraryOrderEntry> orderEntries, PsiFile psiFile) {
    VirtualFile jar = getJarByPsiFile(psiFile);
    if (jar == null)
        return Collections.emptyList();
    VirtualFile jarsDir = jar.getParent();
    if (jarsDir == null || !jarsDir.getName().equals("jars"))
        return Collections.emptyList();
    VirtualFile artifactDir = jarsDir.getParent();
    if (artifactDir == null)
        return Collections.emptyList();
    String jarNameWithoutExt = jar.getNameWithoutExtension();
    String artifactName = artifactDir.getName();
    if (!jarNameWithoutExt.startsWith(artifactName) || !jarNameWithoutExt.substring(artifactName.length()).startsWith("-")) {
        return Collections.emptyList();
    }
    String version = jarNameWithoutExt.substring(artifactName.length() + 1);
    //noinspection SpellCheckingInspection
    VirtualFile propertiesFile = artifactDir.findChild("ivydata-" + version + ".properties");
    if (propertiesFile == null)
        return Collections.emptyList();
    Library library = getLibraryFromOrderEntriesList(orderEntries);
    if (library == null)
        return Collections.emptyList();
    String sourceFileName = artifactName + '-' + version + "-sources.jar";
    VirtualFile sources = artifactDir.findChild("sources");
    if (sources != null) {
        VirtualFile srcFile = sources.findChild(sourceFileName);
        if (srcFile != null) {
            // File already downloaded.
            VirtualFile jarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(srcFile);
            if (jarRoot == null || ArrayUtil.contains(jarRoot, (Object[]) library.getFiles(OrderRootType.SOURCES))) {
                // Sources already attached.
                return Collections.emptyList();
            }
            return Collections.singleton(new AttachExistingSourceAction(jarRoot, library, "Attache sources from Ivy repository"));
        }
    }
    String url = extractUrl(propertiesFile, artifactName);
    if (StringUtil.isEmptyOrSpaces(url))
        return Collections.emptyList();
    return Collections.singleton(new DownloadSourcesAction(psiFile.getProject(), "Downloading Ivy Sources", url) {

        @Override
        protected void storeFile(byte[] content) {
            try {
                VirtualFile existingSourcesFolder = sources;
                if (existingSourcesFolder == null) {
                    existingSourcesFolder = artifactDir.createChildDirectory(this, "sources");
                }
                VirtualFile srcFile = existingSourcesFolder.createChildData(this, sourceFileName);
                srcFile.setBinaryContent(content);
                addSourceFile(JarFileSystem.getInstance().getJarRootForLocalFile(srcFile), library);
            } catch (IOException e) {
                String message = "Failed to save " + artifactDir.getPath() + "/sources/" + sourceFileName;
                new Notification(myMessageGroupId, "IO Error", message, NotificationType.ERROR).notify(myProject);
                LOG.warn(e);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Library(com.intellij.openapi.roots.libraries.Library) IOException(java.io.IOException) Notification(com.intellij.notification.Notification) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with Notification

use of com.intellij.notification.Notification in project android by JetBrains.

the class AndroidDbErrorReporterImpl method reportError.

@Override
public synchronized void reportError(@NotNull String message) {
    super.reportError(message);
    final Notification notification = new Notification(AndroidDbManager.NOTIFICATION_GROUP_ID, "Data Source Synchronization Error", "Cannot " + (myUpload ? "upload" : "synchronize") + " '" + myDataSource.getName() + "': " + message, NotificationType.ERROR);
    Notifications.Bus.notify(notification, myProject);
}
Also used : Notification(com.intellij.notification.Notification)

Aggregations

Notification (com.intellij.notification.Notification)114 HyperlinkEvent (javax.swing.event.HyperlinkEvent)34 NotNull (org.jetbrains.annotations.NotNull)34 NotificationListener (com.intellij.notification.NotificationListener)33 Project (com.intellij.openapi.project.Project)20 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 File (java.io.File)11 IOException (java.io.IOException)11 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)8 Nullable (org.jetbrains.annotations.Nullable)8 Task (com.intellij.openapi.progress.Task)7 Module (com.intellij.openapi.module.Module)6 ExecutionException (com.intellij.execution.ExecutionException)4 NotificationAction (com.intellij.notification.NotificationAction)4 NotificationType (com.intellij.notification.NotificationType)4 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)4 Application (com.intellij.openapi.application.Application)3 Library (com.intellij.openapi.roots.libraries.Library)3 ActionCallback (com.intellij.openapi.util.ActionCallback)3 ArrayList (java.util.ArrayList)3