use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class EduAdaptiveStepicConnector method addNextRecommendedTask.
public static void addNextRecommendedTask(@NotNull Project project, @NotNull ProgressIndicator indicator, int reaction) {
final StudyEditor editor = StudyUtils.getSelectedStudyEditor(project);
final Course course = StudyTaskManager.getInstance(project).getCourse();
if (course != null && editor != null && editor.getTaskFile() != null) {
indicator.checkCanceled();
final StepicUser user = StepicUpdateSettings.getInstance().getUser();
final boolean recommendationReaction = postRecommendationReaction(String.valueOf(editor.getTaskFile().getTask().getLesson().getId()), String.valueOf(user.getId()), reaction);
if (recommendationReaction) {
indicator.checkCanceled();
final Task task = getNextRecommendation(project, course);
if (task != null) {
final Lesson adaptive = course.getLessons().get(0);
final Task unsolvedTask = adaptive.getTaskList().get(adaptive.getTaskList().size() - 1);
final String lessonName = EduNames.LESSON + String.valueOf(adaptive.getIndex());
if (reaction == TOO_HARD_RECOMMENDATION_REACTION || reaction == TOO_BORING_RECOMMENDATION_REACTION) {
unsolvedTask.copyParametersOf(task);
final Map<String, TaskFile> taskFiles = task.getTaskFiles();
if (taskFiles.size() == 1) {
final TaskFile taskFile = editor.getTaskFile();
taskFile.text = ((TaskFile) taskFiles.values().toArray()[0]).text;
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
final Document document = editor.getEditor().getDocument();
document.setText(taskFile.text);
}));
} else {
LOG.warn("Got task without unexpected number of task files: " + taskFiles.size());
}
final File lessonDirectory = new File(course.getCourseDirectory(), lessonName);
final String taskName = EduNames.TASK + String.valueOf(adaptive.getTaskList().size());
final File taskDirectory = new File(lessonDirectory, taskName);
StudyProjectGenerator.flushTask(task, taskDirectory);
StudyProjectGenerator.flushCourseJson(course, new File(course.getCourseDirectory()));
final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
if (lessonDir != null) {
createTestFiles(course, project, unsolvedTask, lessonDir);
}
final StudyToolWindow window = StudyUtils.getStudyToolWindow(project);
if (window != null) {
window.setTaskText(StudyUtils.wrapTextToDisplayLatex(unsolvedTask.getText()), unsolvedTask.getTaskDir(project), project);
}
StudyNavigator.navigateToTask(project, lessonName, taskName);
} else {
adaptive.addTask(task);
task.setIndex(adaptive.getTaskList().size());
final VirtualFile lessonDir = project.getBaseDir().findChild(lessonName);
if (lessonDir != null) {
ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
try {
final File lessonDirectory = new File(course.getCourseDirectory(), lessonName);
final String taskName = EduNames.TASK + String.valueOf(task.getIndex());
final File taskDir = new File(lessonDirectory, taskName);
StudyProjectGenerator.flushTask(task, taskDir);
StudyProjectGenerator.flushCourseJson(course, new File(course.getCourseDirectory()));
StudyGenerator.createTask(task, lessonDir, new File(course.getCourseDirectory(), lessonDir.getName()), project);
adaptive.initLesson(course, true);
StudyNavigator.navigateToTask(project, lessonName, taskName);
} catch (IOException e) {
LOG.warn(e.getMessage());
}
}));
}
}
} else {
ApplicationManager.getApplication().invokeLater(() -> {
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Couldn't load a new recommendation", MessageType.ERROR, null).createBalloon();
StudyUtils.showCheckPopUp(project, balloon);
});
}
ApplicationManager.getApplication().invokeLater(() -> {
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
ProjectView.getInstance(project).refresh();
});
} else {
LOG.warn("Recommendation reactions weren't posted");
ApplicationManager.getApplication().invokeLater(() -> StudyUtils.showErrorPopupOnToolbar(project, "Couldn't post your reaction"));
}
}
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class EduAdaptiveStepicConnector method getNextRecommendation.
@Nullable
public static Task getNextRecommendation(@NotNull Project project, @NotNull Course course) {
try {
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null) {
LOG.warn("Http client is null");
return null;
}
final URI uri = new URIBuilder(EduStepicNames.STEPIC_API_URL + EduStepicNames.RECOMMENDATIONS_URL).addParameter(EduNames.COURSE, String.valueOf(course.getId())).build();
final HttpGet request = new HttpGet(uri);
setTimeout(request);
final CloseableHttpResponse response = client.execute(request);
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
final int statusCode = response.getStatusLine().getStatusCode();
EntityUtils.consume(responseEntity);
if (statusCode == HttpStatus.SC_OK) {
final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final StepicWrappers.RecommendationWrapper recomWrapper = gson.fromJson(responseString, StepicWrappers.RecommendationWrapper.class);
if (recomWrapper.recommendations.length != 0) {
final StepicWrappers.Recommendation recommendation = recomWrapper.recommendations[0];
final String lessonId = recommendation.lesson;
final StepicWrappers.LessonContainer lessonContainer = EduStepicAuthorizedClient.getFromStepic(EduStepicNames.LESSONS + lessonId, StepicWrappers.LessonContainer.class);
if (lessonContainer != null && lessonContainer.lessons.size() == 1) {
final Lesson realLesson = lessonContainer.lessons.get(0);
course.getLessons().get(0).setId(Integer.parseInt(lessonId));
for (int stepId : realLesson.steps) {
final Task taskFromStep = getTask(project, realLesson.getName(), stepId);
if (taskFromStep != null)
return taskFromStep;
}
} else {
LOG.warn("Got unexpected number of lessons: " + (lessonContainer == null ? null : lessonContainer.lessons.size()));
}
} else {
LOG.warn("Got empty recommendation for the task: " + responseString);
}
} else {
throw new IOException("Stepic returned non 200 status code: " + responseString);
}
} catch (IOException e) {
LOG.warn(e.getMessage());
final String connectionMessages = "Connection problems, Please, try again";
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(connectionMessages, MessageType.ERROR, null).createBalloon();
ApplicationManager.getApplication().invokeLater(() -> {
if (StudyUtils.getSelectedEditor(project) != null) {
StudyUtils.showCheckPopUp(project, balloon);
}
});
} catch (URISyntaxException e) {
LOG.warn(e.getMessage());
}
return null;
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-community by JetBrains.
the class PyStudyExecutor method showNoSdkNotification.
public void showNoSdkNotification(@NotNull final Project project) {
final String text = "<html>No Python interpreter configured for the project<br><a href=\"\">Configure interpreter</a></html>";
final BalloonBuilder balloonBuilder = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(text, null, MessageType.WARNING.getPopupBackground(), event -> {
if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
ApplicationManager.getApplication().invokeLater(() -> ShowSettingsUtil.getInstance().showSettingsDialog(project, "Project Interpreter"));
}
});
balloonBuilder.setHideOnLinkClick(true);
final Balloon balloon = balloonBuilder.createBalloon();
StudyUtils.showCheckPopUp(project, balloon);
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-plugins by JetBrains.
the class DocumentProblemManager method report.
// Notification.notify is not suitable for us -
// 1) it is not suitable for content with <ul> tags (due to <p> around message, see NotificationsUtil.buildHtml)
// 2) it is buggy - balloon disappeared while user selects message text
// 3) in any case, event log cannot show our message, may be due to <ul> tags?
// todo fix platform Notification impl or how use it correctly?
public void report(@Nullable final Project project, String message, MessageType messageType) {
//Notification notification = new Notification(FlashUIDesignerBundle.message("plugin.name"),
// title == null ? FlashUIDesignerBundle.message("plugin.name") : title, message, NotificationType.ERROR);
//notification.notify(project);
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, BrowserHyperlinkListener.INSTANCE).setShowCallout(false).setHideOnAction(false).createBalloon();
ApplicationManager.getApplication().invokeLater(() -> {
Window window = WindowManager.getInstance().getFrame(project);
if (window == null) {
window = JOptionPane.getRootFrame();
}
if (window instanceof IdeFrame) {
BalloonLayout layout = ((IdeFrame) window).getBalloonLayout();
if (layout != null) {
layout.add(balloon);
}
}
});
}
use of com.intellij.openapi.ui.popup.Balloon in project intellij-plugins by JetBrains.
the class DartFeedbackBuilder method showErrorNotification.
private static void showErrorNotification(@NotNull Notification notification, @NotNull Project project) {
// Adapted from IdeMessagePanel.showErrorNotification()
IdeFrame myFrame = WindowManager.getInstance().getIdeFrame(project);
BalloonLayout layout = myFrame.getBalloonLayout();
assert layout != null;
BalloonLayoutData layoutData = BalloonLayoutData.createEmpty();
layoutData.fadeoutTime = 5000;
layoutData.fillColor = new JBColor(0XF5E6E7, 0X593D41);
layoutData.borderColor = new JBColor(0XE0A8A9, 0X73454B);
Balloon balloon = NotificationsManagerImpl.createBalloon(myFrame, notification, false, false, new Ref<>(layoutData), project);
layout.add(balloon);
}
Aggregations