1 package com.atlassian.theplugin.idea.crucible.editor;
2
3 import com.atlassian.theplugin.commons.crucible.ValueNotYetInitialized;
4 import com.atlassian.theplugin.commons.crucible.api.model.*;
5 import com.atlassian.theplugin.idea.crucible.CommentDateUtil;
6 import com.atlassian.theplugin.idea.crucible.CommentTooltipPanel;
7 import com.atlassian.theplugin.idea.crucible.CommentTooltipPanelWithRunners;
8 import com.atlassian.theplugin.idea.Constants;
9 import com.intellij.openapi.actionSystem.AnAction;
10 import com.intellij.openapi.actionSystem.AnActionEvent;
11 import com.intellij.openapi.editor.markup.GutterIconRenderer;
12 import com.intellij.openapi.editor.Editor;
13 import org.jetbrains.annotations.NotNull;
14
15 import javax.swing.*;
16
17 public class CrucibleGutterIconRenderer extends GutterIconRenderer {
18 private Editor editor;
19 private final ReviewAdapter review;
20 private final CrucibleFileInfo fileInfo;
21 private final VersionedComment comment;
22
23 public CrucibleGutterIconRenderer(Editor editor, ReviewAdapter review,
24 CrucibleFileInfo fileInfo, VersionedComment comment) {
25 this.editor = editor;
26 this.review = review;
27 this.fileInfo = fileInfo;
28 this.comment = comment;
29 }
30
31 @NotNull
32 public Icon getIcon() {
33 return Constants.CRUCIBLE_REVIEW_PANEL_ICON;
34 }
35
36 @Override
37 public String getTooltipText() {
38 StringBuilder s = new StringBuilder();
39 s.append("<html><b>")
40 .append(comment.getAuthor().getDisplayName())
41 .append("</b> said <i>on ")
42 .append(CommentDateUtil.getDateText(comment.getCreateDate()))
43 .append("</i>:<br>")
44 .append(comment.getMessage().replace("\n", "<br>"));
45 for (Comment versionedComment : comment.getReplies()) {
46 s.append("<br> <b>")
47 .append(versionedComment.getAuthor().getDisplayName())
48 .append("</b> replied <i> on ")
49 .append(CommentDateUtil.getDateText(versionedComment.getCreateDate()))
50 .append("</i>:<br> ")
51 .append(versionedComment.getMessage().replace("\n", "<br>"));
52 }
53 s.append("</html>");
54 return s.toString();
55 }
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 @Override
97 public AnAction getClickAction() {
98 return new ClickAction();
99 }
100
101 public boolean isNavigateAction() {
102 return true;
103 }
104
105 private class ClickAction extends AnAction {
106 public void actionPerformed(final AnActionEvent e) {
107 CommentTooltipPanel lctp = new CommentTooltipPanelWithRunners(e, review, fileInfo, comment, null);
108 e.getPresentation().putClientProperty(CommentTooltipPanel.JBPOPUP_PARENT_COMPONENT, editor.getComponent());
109
110 CommentTooltipPanel.showCommentTooltipPopup(e, lctp, lctp, null);
111 }
112 }
113
114 protected boolean checkIfDraftAndAuthor() {
115 return checkIfUserAnAuthor() && comment.isDraft();
116 }
117
118 protected boolean checkIfUserAnAuthor() {
119 return review.getServerData().getUserName().equals(comment.getAuthor().getUserName());
120 }
121
122 protected boolean checkIfAuthorized() {
123 if (review == null) {
124 return false;
125 }
126 try {
127 if (!review.getActions().contains(CrucibleAction.COMMENT)) {
128 return false;
129 }
130 } catch (ValueNotYetInitialized valueNotYetInitialized) {
131 return false;
132 }
133 return true;
134 }
135 }
136