1 package com.atlassian.theplugin.idea.crucible.comments;
2
3 import com.intellij.util.ui.UIUtil;
4 import com.intellij.util.ui.ListTableModel;
5 import com.atlassian.theplugin.idea.IdeaHelper;
6 import com.atlassian.theplugin.idea.TableColumnInfo;
7 import com.atlassian.theplugin.idea.ui.*;
8 import com.atlassian.theplugin.idea.crucible.ReviewDataInfoAdapter;
9 import com.atlassian.theplugin.idea.crucible.CrucibleConstants;
10 import com.atlassian.theplugin.idea.crucible.events.ShowGeneralCommentEvent;
11 import com.atlassian.theplugin.idea.crucible.events.FocusOnGeneralCommentReplyEvent;
12 import com.atlassian.theplugin.commons.crucible.api.model.ReviewItem;
13 import com.atlassian.theplugin.commons.crucible.api.model.GeneralComment;
14 import com.atlassian.theplugin.commons.crucible.api.model.VersionedComment;
15 import com.atlassian.theplugin.commons.crucible.CrucibleServerFacadeImpl;
16 import com.atlassian.theplugin.commons.crucible.CrucibleServerFacade;
17 import com.atlassian.theplugin.commons.remoteapi.RemoteApiException;
18 import com.atlassian.theplugin.commons.exception.ServerPasswordNotProvidedException;
19 import com.atlassian.theplugin.commons.util.Logger;
20 import com.atlassian.theplugin.util.PluginUtil;
21
22 import javax.swing.table.TableCellRenderer;
23 import java.awt.*;
24 import java.util.List;
25 import java.util.Collection;
26
27
28
29
30
31
32
33
34 public class ReviewCommentsPanel extends AbstractCommentPanel {
35 private static ReviewCommentsPanel instance = null;
36 protected TableColumnProvider commentTableColumnProvider = new CommentColumnProvider();
37 protected TableColumnProvider commentReplyTableColumnProvider = new CommentReplyColumnProvider();
38 private CrucibleServerFacade crucibleServerFacade;
39 public static final Logger LOGGER = PluginUtil.getLogger();
40 private UserTableContext context;
41
42
43 protected ReviewCommentsPanel() {
44 super();
45 context = new UserTableContext();
46 IdeaHelper.getReviewActionEventBroker().registerListener(this);
47 crucibleServerFacade = CrucibleServerFacadeImpl.getInstance();
48 setCommentTableModel(new ListTableModel(getCommentTableColumnProvider().makeColumnInfo()));
49 setCommentReplyTableModel(new ListTableModel(getCommentReplyTableColumnProvider().makeColumnInfo()));
50
51 initialize();
52
53 getCommentsTable().getTable().setStateContext(context);
54 getCommentReplyTable().getTable().setStateContext(context);
55 }
56
57 protected String getCommentToolbarPlace() {
58 return "atlassian.toolwindow.serverToolBar";
59 }
60
61 protected String getCommentReplyToolbarPlace() {
62 return "atlassian.toolwindow.serverToolBar";
63 }
64
65 protected String getCommentToolbarActionGroup() {
66 return "ThePlugin.EmptyToolBar";
67
68 }
69
70 protected String getCommentReplyToolbarActionGroup() {
71 return "ThePlugin.CrucibleGeneralCommentReplyToolBar";
72 }
73
74 protected TableColumnProvider getCommentTableColumnProvider() {
75 return commentTableColumnProvider;
76 }
77
78 protected TableColumnProvider getCommentReplyTableColumnProvider() {
79 return commentReplyTableColumnProvider;
80 }
81
82 public static ReviewCommentsPanel getInstance() {
83 if (instance == null) {
84 instance = new ReviewCommentsPanel();
85 }
86 return instance;
87 }
88
89 protected TableItemSelectedListener getCommentReplySelectedListener() {
90 TableItemSelectedListener commentReplySelectedListener;
91 commentReplySelectedListener = new TableItemSelectedListener() {
92 public void itemSelected(Object item, int noClicks) {
93 GeneralComment selectedComment = (GeneralComment) item;
94 if (noClicks == 2) {
95 IdeaHelper.getReviewActionEventBroker().trigger(
96 new FocusOnGeneralCommentReplyEvent(
97 I_WANT_THIS_MESSAGE_BACK,
98 (ReviewDataInfoAdapter) CrucibleConstants.CrucibleTableState.REVIEW_ADAPTER.getValue(context),
99 selectedComment
100 )
101 );
102 }
103 }
104 };
105 return commentReplySelectedListener;
106 }
107
108 protected TableItemSelectedListener getCommentSelectedListener() {
109 TableItemSelectedListener commentSelectedListener;
110 commentSelectedListener = new TableItemSelectedListener() {
111 public void itemSelected(Object item, int noClicks) {
112 GeneralComment selectedComment = (GeneralComment) item;
113 if (noClicks == 2) {
114 IdeaHelper.getReviewActionEventBroker().trigger(
115 new ShowGeneralCommentEvent(
116 I_WANT_THIS_MESSAGE_BACK,
117 (ReviewDataInfoAdapter) CrucibleConstants.CrucibleTableState.REVIEW_ADAPTER.getValue(context),
118 selectedComment
119 )
120 );
121 }
122 }
123 };
124 return commentSelectedListener;
125 }
126
127 public void focusOnReview(ReviewDataInfoAdapter reviewDataInfoAdapter) {
128
129 }
130
131 public void focusOnFile(ReviewDataInfoAdapter reviewDataInfoAdapter, ReviewItem reviewItem) {
132
133 }
134
135 public void focusOnGeneralComment(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
136
137 }
138
139 public void focusOnGeneralCommentReply(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
140
141 }
142
143 public void focusOnVersionedComment(ReviewDataInfoAdapter reviewDataInfoAdapter, ReviewItem reviewItem, Collection<VersionedComment> versionedComments, VersionedComment versionedComment) {
144
145 }
146
147 public void focusOnVersionedCommentReply(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
148
149 }
150
151 public void showReview(ReviewDataInfoAdapter reviewDataInfoAdapter) {
152 try {
153 getProgressAnimation().startProgressAnimation();
154 final List<GeneralComment> generalComments = crucibleServerFacade.getGeneralComments(reviewDataInfoAdapter.getServer(),
155 reviewDataInfoAdapter.getPermaId());
156 EventQueue.invokeLater(new CommentListChangedListener(reviewDataInfoAdapter, generalComments));
157 } catch (RemoteApiException e) {
158 LOGGER.warn("Error retrieving comments", e);
159 } catch (ServerPasswordNotProvidedException e) {
160 LOGGER.warn("Error retrieving comments", e);
161 } finally {
162 getProgressAnimation().stopProgressAnimation();
163 }
164 }
165
166 public void showReviewedFileItem(ReviewDataInfoAdapter reviewDataInfoAdapter, ReviewItem reviewItem) {
167 }
168
169 public void showGeneralComment(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
170 EventQueue.invokeLater(new CommentSelectedListener(reviewDataInfoAdapter, comment));
171 }
172
173 public void showGeneralCommentReply(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
174
175 }
176
177 public void showVersionedComment(ReviewDataInfoAdapter reviewDataInfoAdapter, final ReviewItem reviewItem,
178 Collection<VersionedComment> versionedComments, final VersionedComment versionedComment) {
179 }
180
181 public void showVersionedCommentReply(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
182
183 }
184
185
186 public static class CommentColumnProvider implements TableColumnProvider {
187 public TableColumnInfo[] makeColumnInfo() {
188 return new TableColumnInfo[]{
189 new CommentCreateDateColumn(),
190 new CommentAuthorColumn(),
191 new CommentSummaryColumn(),
192 new CommentStateColumn(),
193 new CommentRepliesColumn()
194 };
195 }
196
197 public TableCellRenderer[] makeRendererInfo() {
198 return new TableCellRenderer[]{
199 null,
200 null,
201 null,
202 null,
203 null
204 };
205 }
206 }
207
208 public static class CommentReplyColumnProvider implements TableColumnProvider {
209 public TableColumnInfo[] makeColumnInfo() {
210 return new TableColumnInfo[]{
211 new CommentCreateDateColumn(),
212 new CommentAuthorColumn(),
213 new CommentSummaryColumn(),
214 new CommentStateColumn()
215 };
216 }
217
218 public TableCellRenderer[] makeRendererInfo() {
219 return new TableCellRenderer[]{
220 null,
221 null,
222 null,
223 null
224 };
225 }
226 }
227
228
229 private class CommentListChangedListener implements Runnable {
230 private ReviewDataInfoAdapter reviewDataInfoAdapter;
231 private final List<GeneralComment> generalComments;
232
233 public CommentListChangedListener(ReviewDataInfoAdapter reviewDataInfoAdapter, List<GeneralComment> generalComments) {
234 this.reviewDataInfoAdapter = reviewDataInfoAdapter;
235 this.generalComments = generalComments;
236 }
237
238 public void run() {
239 CrucibleConstants.CrucibleTableState.REVIEW_ADAPTER.setValue(context, reviewDataInfoAdapter);
240 getCommentTableModel().setItems(generalComments);
241 getCommentTableModel().fireTableDataChanged();
242 getCommentsTable().getHeaderLabel().setText("General comments to " + reviewDataInfoAdapter);
243 getCommentsTable().getTable().revalidate();
244 getCommentsTable().getTable().setEnabled(true);
245 getCommentsTable().getTable().setForeground(UIUtil.getActiveTextColor());
246
247 switchToComments();
248 }
249 }
250
251 private class CommentSelectedListener implements Runnable {
252 private ReviewDataInfoAdapter reviewDataInfoAdapter;
253 private GeneralComment comment;
254
255 public CommentSelectedListener(ReviewDataInfoAdapter reviewDataInfoAdapter, GeneralComment comment) {
256 this.reviewDataInfoAdapter = reviewDataInfoAdapter;
257 this.comment = comment;
258 }
259
260 public void run() {
261 getCommentReplyTableModel().setItems(comment.getReplies());
262 getCommentReplyTableModel().fireTableDataChanged();
263 StringBuffer buffer = new StringBuffer();
264 buffer.append("Replies to a comment \"");
265 buffer.append(comment.toString());
266 buffer.append("\" made by ");
267 buffer.append(comment.getDisplayUser());
268 buffer.append(" [");
269 buffer.append(CommentCreateDateColumn.FORMATTER.format(comment.getCreateDate()));
270 buffer.append("]");
271 getCommentReplyTable().setHeaderText(buffer.toString());
272 getCommentReplyTable().getTable().revalidate();
273 getCommentReplyTable().getTable().setEnabled(true);
274 getCommentReplyTable().getTable().setForeground(UIUtil.getActiveTextColor());
275
276 switchToCommentReplies();
277 }
278 }
279
280 }