|
Lines 7-54
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Jingwen Ou - initial API and implementation |
9 |
* Jingwen Ou - initial API and implementation |
|
|
10 |
* Tasktop Technologies - improvements |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
|
12 |
|
| 12 |
package org.eclipse.mylyn.internal.sandbox.ui.editors; |
13 |
package org.eclipse.mylyn.internal.sandbox.ui.editors; |
| 13 |
|
14 |
|
| 14 |
import java.util.ArrayList; |
15 |
import java.util.ArrayList; |
|
|
16 |
import java.util.Collections; |
| 15 |
import java.util.List; |
17 |
import java.util.List; |
| 16 |
|
18 |
|
| 17 |
import org.eclipse.mylyn.internal.tasks.core.TaskComment; |
|
|
| 18 |
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; |
19 |
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; |
| 19 |
import org.eclipse.mylyn.tasks.core.IRepositoryPerson; |
20 |
import org.eclipse.mylyn.tasks.core.IRepositoryPerson; |
|
|
21 |
import org.eclipse.mylyn.tasks.core.ITaskComment; |
| 20 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
22 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
| 21 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModel; |
|
|
| 22 |
|
23 |
|
| 23 |
/** |
24 |
/** |
| 24 |
* @author Jingwen Ou |
25 |
* @author Jingwen Ou |
|
|
26 |
* @author Steffen Pingel |
| 25 |
*/ |
27 |
*/ |
| 26 |
public class CommentGroupStrategy { |
28 |
public class CommentGroupStrategy { |
|
|
29 |
|
| 27 |
public class CommentGroup { |
30 |
public class CommentGroup { |
| 28 |
private final List<TaskAttribute> commentAttributes; |
31 |
|
|
|
32 |
private final List<ITaskComment> comments; |
| 29 |
|
33 |
|
| 30 |
private final String groupName; |
34 |
private final String groupName; |
| 31 |
|
35 |
|
| 32 |
CommentGroup(String groupName, List<TaskAttribute> commentAttributes) { |
36 |
CommentGroup(String groupName, List<ITaskComment> comments) { |
| 33 |
this.groupName = groupName; |
37 |
this.groupName = groupName; |
| 34 |
this.commentAttributes = commentAttributes; |
38 |
this.comments = comments; |
| 35 |
} |
39 |
} |
| 36 |
|
40 |
|
| 37 |
public List<TaskAttribute> getCommentAttributes() { |
41 |
public List<TaskAttribute> getCommentAttributes() { |
| 38 |
return commentAttributes; |
42 |
List<TaskAttribute> commentAttributes = new ArrayList<TaskAttribute>(comments.size()); |
|
|
43 |
for (ITaskComment comment : comments) { |
| 44 |
commentAttributes.add(comment.getTaskAttribute()); |
| 45 |
} |
| 46 |
return Collections.unmodifiableList(commentAttributes); |
| 47 |
} |
| 48 |
|
| 49 |
public List<ITaskComment> getComments() { |
| 50 |
return Collections.unmodifiableList(comments); |
| 39 |
} |
51 |
} |
| 40 |
|
52 |
|
| 41 |
public String getGroupName() { |
53 |
public String getGroupName() { |
| 42 |
return groupName; |
54 |
return groupName; |
| 43 |
} |
55 |
} |
| 44 |
} |
|
|
| 45 |
|
| 46 |
private TaskComment convertToTaskComment(TaskDataModel taskDataModel, TaskAttribute commentAttribute) { |
| 47 |
TaskComment taskComment = new TaskComment(taskDataModel.getTaskRepository(), taskDataModel.getTask(), |
| 48 |
commentAttribute); |
| 49 |
taskDataModel.getTaskData().getAttributeMapper().updateTaskComment(taskComment, commentAttribute); |
| 50 |
|
56 |
|
| 51 |
return taskComment; |
|
|
| 52 |
} |
57 |
} |
| 53 |
|
58 |
|
| 54 |
/** |
59 |
/** |
|
Lines 58-85
Link Here
|
| 58 |
* extracts groups of comment for the model |
63 |
* extracts groups of comment for the model |
| 59 |
* @return list of comment groups. Groups will be ignored if there are no comments under them. |
64 |
* @return list of comment groups. Groups will be ignored if there are no comments under them. |
| 60 |
*/ |
65 |
*/ |
| 61 |
public List<CommentGroup> groupCommentsFromModel(TaskDataModel taskDataModel) { |
66 |
public List<CommentGroup> groupComments(List<ITaskComment> comments, String currentPersonId) { |
| 62 |
List<TaskAttribute> taskAttributes = taskDataModel.getTaskData().getAttributeMapper().getAttributesByType( |
|
|
| 63 |
taskDataModel.getTaskData(), TaskAttribute.TYPE_COMMENT); |
| 64 |
List<CommentGroup> commentGroups = new ArrayList<CommentGroup>(); |
67 |
List<CommentGroup> commentGroups = new ArrayList<CommentGroup>(); |
| 65 |
List<TaskAttribute> comments = new ArrayList<TaskAttribute>(); |
|
|
| 66 |
|
| 67 |
int currentFromIndex = -1; |
| 68 |
String currentPersonId = taskDataModel.getTaskRepository().getUserName(); |
| 69 |
|
68 |
|
| 70 |
// current |
69 |
// current |
| 71 |
List<TaskAttribute> current = new ArrayList<TaskAttribute>(); |
70 |
int currentFromIndex = -1; |
|
|
71 |
List<ITaskComment> current = new ArrayList<ITaskComment>(); |
| 72 |
|
72 |
|
| 73 |
// update task comment and get current group index |
73 |
// update task comment and get current group index |
| 74 |
TaskComment latestComment = null; |
74 |
ITaskComment latestComment = null; |
| 75 |
for (int i = 0; i < taskAttributes.size(); i++) { |
75 |
for (int i = 0; i < comments.size(); i++) { |
| 76 |
TaskAttribute commentAttribute = taskAttributes.get(i); |
76 |
ITaskComment taskComment = comments.get(i); |
| 77 |
final TaskComment taskComment = convertToTaskComment(taskDataModel, commentAttribute); |
|
|
| 78 |
comments.add(commentAttribute); |
| 79 |
|
77 |
|
| 80 |
// add all incoming changes |
78 |
// add all incoming changes |
| 81 |
if (taskDataModel.hasIncomingChanges(taskComment.getTaskAttribute())) { |
79 |
if (hasIncomingChanges(taskComment)) { |
| 82 |
current.add(commentAttribute); |
80 |
current.add(taskComment); |
| 83 |
} |
81 |
} |
| 84 |
|
82 |
|
| 85 |
IRepositoryPerson person = taskComment.getAuthor(); |
83 |
IRepositoryPerson person = taskComment.getAuthor(); |
|
Lines 98-112
Link Here
|
| 98 |
// bug 238038 comment #58, if the latest comment is generated automatically, lookback one comment |
96 |
// bug 238038 comment #58, if the latest comment is generated automatically, lookback one comment |
| 99 |
if (latestComment != null && latestComment.getText().contains(AttachmentUtil.CONTEXT_DESCRIPTION) |
97 |
if (latestComment != null && latestComment.getText().contains(AttachmentUtil.CONTEXT_DESCRIPTION) |
| 100 |
&& currentFromIndex > 0) { |
98 |
&& currentFromIndex > 0) { |
| 101 |
TaskComment secondLatestComment = convertToTaskComment(taskDataModel, |
99 |
ITaskComment secondLatestComment = comments.get(currentFromIndex - 1); |
| 102 |
comments.get(currentFromIndex - 1)); |
|
|
| 103 |
IRepositoryPerson person = secondLatestComment.getAuthor(); |
100 |
IRepositoryPerson person = secondLatestComment.getAuthor(); |
| 104 |
if (person != null && person.getPersonId().equals(currentPersonId)) { |
101 |
if (person != null && person.getPersonId().equals(currentPersonId)) { |
| 105 |
currentFromIndex--; |
102 |
currentFromIndex--; |
| 106 |
} |
103 |
} |
| 107 |
} |
104 |
} |
| 108 |
|
105 |
|
| 109 |
current.addAll(0, new ArrayList<TaskAttribute>(comments.subList(currentFromIndex, comments.size()))); |
106 |
current.addAll(0, new ArrayList<ITaskComment>(comments.subList(currentFromIndex, comments.size()))); |
| 110 |
if (current.size() > 0) { |
107 |
if (current.size() > 0) { |
| 111 |
comments.removeAll(current); |
108 |
comments.removeAll(current); |
| 112 |
} |
109 |
} |
|
Lines 114-120
Link Here
|
| 114 |
|
111 |
|
| 115 |
// recent |
112 |
// recent |
| 116 |
int recentFromIndex = comments.size() - 20 < 0 ? 0 : comments.size() - 20; |
113 |
int recentFromIndex = comments.size() - 20 < 0 ? 0 : comments.size() - 20; |
| 117 |
List<TaskAttribute> recent = new ArrayList<TaskAttribute>(comments.subList(recentFromIndex, comments.size())); |
114 |
List<ITaskComment> recent = new ArrayList<ITaskComment>(comments.subList(recentFromIndex, comments.size())); |
| 118 |
if (recent.size() > 0) { |
115 |
if (recent.size() > 0) { |
| 119 |
comments.removeAll(recent); |
116 |
comments.removeAll(recent); |
| 120 |
} |
117 |
} |
|
Lines 136-139
Link Here
|
| 136 |
|
133 |
|
| 137 |
return commentGroups; |
134 |
return commentGroups; |
| 138 |
} |
135 |
} |
|
|
136 |
|
| 137 |
protected boolean hasIncomingChanges(ITaskComment taskComment) { |
| 138 |
return false; |
| 139 |
} |
| 140 |
|
| 139 |
} |
141 |
} |