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);
}
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));
}
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);
}
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);
}
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));
}
}
Aggregations