Search in sources :

Example 96 with Notification

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

the class StudyProjectComponent method updateCourse.

private void updateCourse() {
    final Course currentCourse = StudyTaskManager.getInstance(myProject).getCourse();
    final CourseInfo info = CourseInfo.fromCourse(currentCourse);
    if (info == null)
        return;
    final File resourceDirectory = new File(currentCourse.getCourseDirectory());
    if (resourceDirectory.exists()) {
        FileUtil.delete(resourceDirectory);
    }
    final Course course = EduStepicConnector.getCourse(myProject, info);
    if (course == null)
        return;
    flushCourse(course);
    course.initCourse(false);
    StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
    if (manager == null) {
        LOG.info("Study Language Manager is null for " + course.getLanguageById().getDisplayName());
        return;
    }
    final ArrayList<Lesson> updatedLessons = new ArrayList<>();
    int lessonIndex = 0;
    for (Lesson lesson : course.getLessons()) {
        lessonIndex += 1;
        Lesson studentLesson = currentCourse.getLesson(lesson.getId());
        final String lessonDirName = EduNames.LESSON + String.valueOf(lessonIndex);
        final File lessonDir = new File(myProject.getBasePath(), lessonDirName);
        if (!lessonDir.exists()) {
            final File fromLesson = new File(resourceDirectory, lessonDirName);
            try {
                FileUtil.copyDir(fromLesson, lessonDir);
            } catch (IOException e) {
                LOG.warn("Failed to copy lesson " + fromLesson.getPath());
            }
            lesson.setIndex(lessonIndex);
            lesson.initLesson(currentCourse, false);
            for (int i = 1; i <= lesson.getTaskList().size(); i++) {
                Task task = lesson.getTaskList().get(i - 1);
                task.setIndex(i);
            }
            updatedLessons.add(lesson);
            continue;
        }
        studentLesson.setIndex(lessonIndex);
        updatedLessons.add(studentLesson);
        int index = 0;
        final ArrayList<Task> tasks = new ArrayList<>();
        for (Task task : lesson.getTaskList()) {
            index += 1;
            final Task studentTask = studentLesson.getTask(task.getStepId());
            if (studentTask != null && StudyStatus.Solved.equals(studentTask.getStatus())) {
                studentTask.setIndex(index);
                tasks.add(studentTask);
                continue;
            }
            task.initTask(studentLesson, false);
            task.setIndex(index);
            final String taskDirName = EduNames.TASK + String.valueOf(index);
            final File toTask = new File(lessonDir, taskDirName);
            final String taskPath = FileUtil.join(resourceDirectory.getPath(), lessonDirName, taskDirName);
            final File taskDir = new File(taskPath);
            if (!taskDir.exists())
                return;
            final File[] taskFiles = taskDir.listFiles();
            if (taskFiles == null)
                continue;
            for (File fromFile : taskFiles) {
                copyFile(fromFile, new File(toTask, fromFile.getName()));
            }
            tasks.add(task);
        }
        studentLesson.updateTaskList(tasks);
    }
    currentCourse.setLessons(updatedLessons);
    final Notification notification = new Notification("Update.course", "Course update", "Current course is synchronized", NotificationType.INFORMATION);
    notification.notify(myProject);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) CourseInfo(com.jetbrains.edu.learning.courseFormat.CourseInfo) Notification(com.intellij.notification.Notification) StudyProjectGenerator.flushCourse(com.jetbrains.edu.learning.courseGeneration.StudyProjectGenerator.flushCourse) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 97 with Notification

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

the class PythonSdkType method notifyRemoteSdkSkeletonsFail.

public static void notifyRemoteSdkSkeletonsFail(final InvalidSdkException e, @Nullable final Runnable restartAction) {
    NotificationListener notificationListener;
    String notificationMessage;
    if (e.getCause() instanceof VagrantNotStartedException) {
        notificationListener = new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
                if (manager != null) {
                    try {
                        VagrantNotStartedException cause = (VagrantNotStartedException) e.getCause();
                        manager.runVagrant(cause.getVagrantFolder(), cause.getMachineName());
                    } catch (ExecutionException e1) {
                        throw new RuntimeException(e1);
                    }
                }
                if (restartAction != null) {
                    restartAction.run();
                }
            }
        };
        notificationMessage = e.getMessage() + "\n<a href=\"#\">Launch vagrant and refresh skeletons</a>";
    } else if (ExceptionUtil.causedBy(e, ExceptionFix.class)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final ExceptionFix fix = ExceptionUtil.findCause(e, ExceptionFix.class);
        notificationListener = new NotificationListener() {

            @Override
            public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
                fix.apply();
                if (restartAction != null) {
                    restartAction.run();
                }
            }
        };
        notificationMessage = fix.getNotificationMessage(e.getMessage());
    } else {
        notificationListener = null;
        notificationMessage = e.getMessage();
    }
    Notifications.Bus.notify(new Notification(SKELETONS_TOPIC, "Couldn't refresh skeletons for remote interpreter", notificationMessage, NotificationType.WARNING, notificationListener));
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) ExecutionException(com.intellij.execution.ExecutionException) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager) NotNull(org.jetbrains.annotations.NotNull) Notification(com.intellij.notification.Notification) NotificationListener(com.intellij.notification.NotificationListener)

Example 98 with Notification

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

the class AndroidPropertyFilesUpdater method askUserIfUpdatePropertyFile.

private void askUserIfUpdatePropertyFile(@NotNull Project project, @NotNull Collection<AndroidFacet> facets, @NotNull final Processor<MyResult> callback) {
    final StringBuilder moduleList = new StringBuilder();
    for (AndroidFacet facet : facets) {
        moduleList.append(facet.getModule().getName()).append("<br>");
    }
    myNotification = PROPERTY_FILES_UPDATING_NOTIFICATION.createNotification(AndroidBundle.message("android.update.project.properties.dialog.title"), AndroidBundle.message("android.update.project.properties.dialog.text", moduleList.toString()), NotificationType.INFORMATION, new NotificationListener.Adapter() {

        @Override
        protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
            final String desc = event.getDescription();
            if ("once".equals(desc)) {
                callback.process(MyResult.ONCE);
            } else if ("never".equals(desc)) {
                callback.process(MyResult.NEVER);
            } else {
                callback.process(MyResult.ALWAYS);
            }
            notification.expire();
        }
    });
    myNotification.notify(project);
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) NotNull(org.jetbrains.annotations.NotNull) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Notification(com.intellij.notification.Notification)

Example 99 with Notification

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

the class AndroidUtils method reportImportErrorToEventLog.

public static void reportImportErrorToEventLog(String message, String modName, Project project, NotificationListener listener) {
    Notifications.Bus.notify(new Notification(AndroidBundle.message("android.facet.importing.notification.group"), AndroidBundle.message("android.facet.importing.title", modName), message, NotificationType.ERROR, listener), project);
    LOG.debug(message);
}
Also used : Notification(com.intellij.notification.Notification)

Example 100 with Notification

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

the class AndroidCompileUtil method addSourceRoot.

@Nullable
public static SourceFolder addSourceRoot(final ModifiableRootModel model, @NotNull final VirtualFile root) {
    ContentEntry contentEntry = findContentEntryForRoot(model, root);
    if (contentEntry == null) {
        final Project project = model.getProject();
        final String message = "Cannot mark directory '" + FileUtil.toSystemDependentName(root.getPath()) + "' as source root, because it is not located under content root of module '" + model.getModule().getName() + "'\n<a href='fix'>Open Project Structure</a>";
        final Notification notification = new Notification(AndroidBundle.message("android.autogeneration.notification.group"), "Autogeneration Error", message, NotificationType.ERROR, new NotificationListener.Adapter() {

            @Override
            protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
                notification.expire();
                final ProjectStructureConfigurable configurable = ProjectStructureConfigurable.getInstance(project);
                ShowSettingsUtil.getInstance().editConfigurable(project, configurable, new Runnable() {

                    @Override
                    public void run() {
                        final Module module = model.getModule();
                        final AndroidFacet facet = AndroidFacet.getInstance(module);
                        if (facet != null) {
                            configurable.select(facet, true);
                        }
                    }
                });
            }
        });
        Notifications.Bus.notify(notification, project);
        LOG.debug(message);
        return null;
    } else {
        return contentEntry.addSourceFolder(root, JavaSourceRootType.SOURCE, JpsJavaExtensionService.getInstance().createSourceRootProperties("", true));
    }
}
Also used : Project(com.intellij.openapi.project.Project) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Module(com.intellij.openapi.module.Module) Notification(com.intellij.notification.Notification) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotificationListener(com.intellij.notification.NotificationListener) ProjectStructureConfigurable(com.intellij.openapi.roots.ui.configuration.ProjectStructureConfigurable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Notification (com.intellij.notification.Notification)108 HyperlinkEvent (javax.swing.event.HyperlinkEvent)34 NotNull (org.jetbrains.annotations.NotNull)34 NotificationListener (com.intellij.notification.NotificationListener)33 Project (com.intellij.openapi.project.Project)19 IOException (java.io.IOException)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 File (java.io.File)8 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)7 Nullable (org.jetbrains.annotations.Nullable)7 Module (com.intellij.openapi.module.Module)6 Task (com.intellij.openapi.progress.Task)6 ExecutionException (com.intellij.execution.ExecutionException)4 NotificationType (com.intellij.notification.NotificationType)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 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)2 NotificationAction (com.intellij.notification.NotificationAction)2