Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 247745 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/ExtensibleTaskEditorCommentPart.java (-4 / +23 lines)
Lines 20-28 Link Here
20
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.jface.layout.GridDataFactory;
21
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
21
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
22
import org.eclipse.mylyn.internal.sandbox.ui.editors.CommentGroupStrategy.CommentGroup;
22
import org.eclipse.mylyn.internal.sandbox.ui.editors.CommentGroupStrategy.CommentGroup;
23
import org.eclipse.mylyn.internal.tasks.core.TaskComment;
23
import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
24
import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
24
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorCommentPart;
25
import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorCommentPart;
26
import org.eclipse.mylyn.tasks.core.ITaskComment;
25
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
27
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
28
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
26
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.layout.GridLayout;
Lines 61-69 Link Here
61
		setPartName("Comments");
64
		setPartName("Comments");
62
	}
65
	}
63
66
67
	private TaskComment convertToTaskComment(TaskDataModel taskDataModel, TaskAttribute commentAttribute) {
68
		TaskComment taskComment = new TaskComment(taskDataModel.getTaskRepository(), taskDataModel.getTask(),
69
				commentAttribute);
70
		taskDataModel.getTaskData().getAttributeMapper().updateTaskComment(taskComment, commentAttribute);
71
		return taskComment;
72
	}
73
64
	private void createCommentSubsections(final FormToolkit toolkit, final Composite composite,
74
	private void createCommentSubsections(final FormToolkit toolkit, final Composite composite,
65
			List<TaskAttribute> comments) {
75
			List<TaskAttribute> commentAttributes) {
66
		List<CommentGroup> commentGroups = getCommentGroupStrategy().groupCommentsFromModel(getModel());
76
		List<ITaskComment> comments = new ArrayList<ITaskComment>();
77
		for (TaskAttribute commentAttribute : commentAttributes) {
78
			comments.add(convertToTaskComment(getModel(), commentAttribute));
79
		}
80
		String currentPersonId = getModel().getTaskRepository().getUserName();
81
		List<CommentGroup> commentGroups = getCommentGroupStrategy().groupComments(comments, currentPersonId);
67
82
68
		// if there is only one subsection, then don't show it
83
		// if there is only one subsection, then don't show it
69
		if (commentGroups.size() == 1) {
84
		if (commentGroups.size() == 1) {
Lines 217-225 Link Here
217
232
218
	private CommentGroupStrategy getCommentGroupStrategy() {
233
	private CommentGroupStrategy getCommentGroupStrategy() {
219
		if (commentGroupStrategy == null) {
234
		if (commentGroupStrategy == null) {
220
			commentGroupStrategy = new CommentGroupStrategy();
235
			commentGroupStrategy = new CommentGroupStrategy() {
236
				@Override
237
				protected boolean hasIncomingChanges(ITaskComment taskComment) {
238
					return getModel().hasIncomingChanges(taskComment.getTaskAttribute());
239
				}
240
			};
221
		}
241
		}
222
223
		return commentGroupStrategy;
242
		return commentGroupStrategy;
224
	}
243
	}
225
244
(-)src/org/eclipse/mylyn/internal/sandbox/ui/editors/CommentGroupStrategy.java (-32 / +34 lines)
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
}
(-).refactorings/2008/9/38/refactorings.history (+4 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<session version="1.0">
3
<refactoring comment="Extract method &apos;private void hasIncomingChanges(ITaskComment taskComment)&apos; from &apos;org.eclipse.mylyn.internal.sandbox.ui.editors.CommentGroupStrategy.groupCommentsFromModel()&apos; to &apos;org.eclipse.mylyn.internal.sandbox.ui.editors.CommentGroupStrategy&apos;&#x0A;- Original project: &apos;org.eclipse.mylyn.sandbox.ui&apos;&#x0A;- Method name: &apos;hasIncomingChanges&apos;&#x0A;- Destination type: &apos;org.eclipse.mylyn.internal.sandbox.ui.editors.CommentGroupStrategy&apos;&#x0A;- Declared visibility: &apos;private&apos;" comments="false" description="Extract method &apos;hasIncomingChanges&apos;" destination="0" exceptions="false" flags="786434" id="org.eclipse.jdt.ui.extract.method" input="/src&lt;org.eclipse.mylyn.internal.sandbox.ui.editors{CommentGroupStrategy.java" name="hasIncomingChanges" replace="false" selection="2421 64" stamp="1221946498104" version="1.0" visibility="2"/>
4
</session>
(-).refactorings/2008/9/38/refactorings.index (+1 lines)
Added Link Here
1
1221946498104	Extract method 'hasIncomingChanges'

Return to bug 247745