Skip to main content
summaryrefslogtreecommitdiffstats
blob: 380374aa8344706dfffd586a1c5adb0fd413bc08 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*******************************************************************************
 * Copyright (c) 2003 - 2006 University Of British Columbia and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
package org.eclipse.mylar.tasks.ui.editors;

import java.util.ArrayList;
import java.util.Iterator;

import org.eclipse.mylar.internal.tasks.ui.editors.IRepositoryTaskSelection;
import org.eclipse.mylar.tasks.core.TaskComment;
import org.eclipse.mylar.tasks.core.RepositoryTaskData;

/**
 * A node for the tree in the <code>RepositoryTaskOutlinePage</code>.
 * 
 * @author Mik Kersten (hardening of prototype)
 */
public class RepositoryTaskOutlineNode implements IRepositoryTaskSelection {

	public static final String LABEL_DESCRIPTION = "Description";

	public static final String LABEL_COMMENTS = "Comments";

	public static final String LABEL_NEW_COMMENT = "New Comment";

	/** The id of the Bugzilla object that the selection was on. */
	protected String id;

	/** The server of the Bugzilla object that the selection was on. */
	protected String server;

	/** The label for this piece of data. */
	private String key;

	/** The children of this node. */
	private ArrayList<RepositoryTaskOutlineNode> nodeChildren;

	/** The parent of this node or null if it is the bug report */
	private RepositoryTaskOutlineNode parent;

	private Object data = null;

	private String bugSummary;

	private boolean fromEditor = false;

	private boolean isCommentHeader = false;

	private boolean isDescription = false;

	/**
	 * Creates a new <code>RepositoryTaskOutlineNode</code>.
	 * 
	 * @param id
	 *            The id of the bug this outline is for.
	 * @param server
	 *            The server of the bug this outline is for.
	 * @param key
	 *            The label for this node.
	 * @param image
	 *            The image that will be displayed by this node in the tree.
	 * @param data
	 *            The data, if necessary, this node represents.
	 * @param parent
	 *            The parent of this node
	 */
	public RepositoryTaskOutlineNode(String id, String server, String key, Object data, String summary) {
		this.id = id;
		this.server = server;
		this.key = key;
		this.nodeChildren = null;
		this.data = data;
		this.parent = null;
		this.bugSummary = summary;
	}

	public boolean isFromEditor() {
		return fromEditor;
	}

	/**
	 * @return The children of this node, represented as an <code>Object</code>
	 *         array.
	 */
	public RepositoryTaskOutlineNode[] getChildren() {
		return (nodeChildren == null) ? new RepositoryTaskOutlineNode[0] : nodeChildren
				.toArray(new RepositoryTaskOutlineNode[nodeChildren.size()]);
	}

	/**
	 * Adds a node to this node's list of children.
	 * 
	 * @param bugNode
	 *            The new child.
	 */
	public void addChild(RepositoryTaskOutlineNode bugNode) {
		if (nodeChildren == null) {
			nodeChildren = new ArrayList<RepositoryTaskOutlineNode>();
		}
		bugNode.setParent(this);
		nodeChildren.add(bugNode);
	}

	/**
	 * @return The label of this node.
	 */
	public String getKey() {
		return key;
	}

	/**
	 * @return <code>true</code> if the given object is another node
	 *         representing the same piece of data in the editor.
	 */
	@Override
	public boolean equals(Object arg0) {
		if (arg0 instanceof RepositoryTaskOutlineNode) {
			RepositoryTaskOutlineNode bugNode = (RepositoryTaskOutlineNode) arg0;
			return getKey().equals(bugNode.getKey());
		}
		return super.equals(arg0);
	}

	@Override
	public int hashCode() {
		return getKey().hashCode();
	}

	/**
	 * @return The name of this node.
	 */
	public String getName() {
		return getKey();
	}

	/**
	 * @return The data (where applicable) this node represents.
	 */
	public Object getData() {
		return data;
	}

	/**
	 * Sets the data that this node represents.
	 * 
	 * @param data
	 *            The new piece of data.
	 */
	public void setData(Object data) {
		this.data = data;
	}

	/**
	 * Parses the given <code>IBugzillaBug</code> into a tree of
	 * <code>RepositoryTaskOutlineNode</code>'s suitable for use in the
	 * <code>RepositoryTaskOutlinePage</code> view.
	 * 
	 * @param bug
	 *            The bug that needs parsing.
	 * @return The tree of <code>RepositoryTaskOutlineNode</code>'s.
	 */
	public static RepositoryTaskOutlineNode parseBugReport(RepositoryTaskData bug, boolean hasNewComment) {
		// Choose the appropriate parsing function based on
		// the type of IBugzillaBug.
		// if (bug instanceof NewBugzillaReport) {
		// return parseNewBugReport((NewBugzillaReport) bug);
		// } else
		if (bug instanceof RepositoryTaskData) {
			return parseExistingBugReport(bug, hasNewComment);
		} else {
			return null;
		}
	}

	public static RepositoryTaskOutlineNode parseBugReport(RepositoryTaskData bug) {
		return parseBugReport(bug, true);
	}

//	/**
//	 * Parses the given <code>NewBugModel</code> into a tree of
//	 * <code>RepositoryTaskOutlineNode</code>'s suitable for use in the
//	 * <code>RepositoryTaskOutlinePage</code> view.
//	 * 
//	 * @param bug
//	 *            The <code>NewBugModel</code> that needs parsing.
//	 * @return The tree of <code>RepositoryTaskOutlineNode</code>'s.
//	 */
//	protected static RepositoryTaskOutlineNode parseNewBugReport(NewBugzillaReport bug) {
//		int bugId = bug.getId();
//		String bugServer = bug.getRepositoryUrl();
//		Image bugImage = BugzillaImages.getImage(BugzillaImages.BUG);
//		Image defaultImage = BugzillaImages.getImage(BugzillaImages.BUG_COMMENT);
//		RepositoryTaskOutlineNode topNode = new RepositoryTaskOutlineNode(bugId, bugServer, bug.getLabel(), bugImage, bug, bug
//				.getSummary());
//
//		topNode.addChild(new RepositoryTaskOutlineNode(bugId, bugServer, "New Description", defaultImage, null, bug
//				.getSummary()));
//
//		RepositoryTaskOutlineNode titleNode = new RepositoryTaskOutlineNode(bugId, bugServer, "NewBugModel Object", defaultImage,
//				null, bug.getSummary());
//		titleNode.addChild(topNode);
//
//		return titleNode;
//	}

	/**
	 * Parses the given <code>BugReport</code> into a tree of
	 * <code>RepositoryTaskOutlineNode</code>'s suitable for use in the
	 * <code>RepositoryTaskOutlinePage</code> view.
	 * 
	 * @param bug
	 *            The <code>BugReport</code> that needs parsing.
	 * @return The tree of <code>RepositoryTaskOutlineNode</code>'s.
	 */
	protected static RepositoryTaskOutlineNode parseExistingBugReport(RepositoryTaskData bug, boolean hasNewComment) {

		String bugId = bug.getId();
		String bugServer = bug.getRepositoryUrl();
		RepositoryTaskOutlineNode topNode = new RepositoryTaskOutlineNode(bugId, bugServer, bug.getLabel(), bug, bug
				.getSummary());

		RepositoryTaskOutlineNode desc = new RepositoryTaskOutlineNode(bugId, bugServer, LABEL_DESCRIPTION, bug
				.getDescription(), bug.getSummary());
		desc.setIsDescription(true);

		topNode.addChild(desc);

		RepositoryTaskOutlineNode comments = null;
		for (Iterator<TaskComment> iter = bug.getComments().iterator(); iter.hasNext();) {
			TaskComment taskComment = iter.next();
			// first comment is the bug description
			if(taskComment.getNumber() == 0) continue;
			if (comments == null) {
				comments = new RepositoryTaskOutlineNode(bugId, bugServer, LABEL_COMMENTS, taskComment, bug
						.getSummary());
				comments.setIsCommentHeader(true);
			}
			comments.addChild(new RepositoryTaskOutlineNode(bugId, bugServer, taskComment.getCreated(),
					taskComment, bug.getSummary()));
		}
		if (comments != null) {
			topNode.addChild(comments);
		}

		if (hasNewComment) {
			topNode
					.addChild(new RepositoryTaskOutlineNode(bugId, bugServer, LABEL_NEW_COMMENT, null, bug.getSummary()));
		}
		
		RepositoryTaskOutlineNode titleNode = new RepositoryTaskOutlineNode(bugId, bugServer, "BugReport Object",
				null, bug.getSummary());
		titleNode.addChild(topNode);

		return titleNode;
	}

	public boolean hasComment() {
		// If the comment category was selected, then the comment object is
		// not the intended selection (it is just used to help find the correct
		// location in the editor).
		return (data instanceof TaskComment) && !(key.toLowerCase().equals("comments"));
	}

	public TaskComment getComment() {
		return (hasComment()) ? (TaskComment) data : null;
	}

	public void setComment(TaskComment taskComment) {
		data = taskComment;
	}

	public String getContents() {
		return key;
	}

	public void setContents(String contents) {
		key = contents;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public boolean isEmpty() {
		return (server == null) || ((getContents() == null) && (getComment() == null));
	}

	public RepositoryTaskOutlineNode getParent() {
		return parent;
	}

	public void setParent(RepositoryTaskOutlineNode parent) {
		this.parent = parent;
	}

	public boolean isCommentHeader() {
		return isCommentHeader;
	}

	public boolean isDescription() {
		return isDescription;
	}

	public void setIsCommentHeader(boolean isCommentHeader) {
		this.isCommentHeader = isCommentHeader;
	}

	public void setIsDescription(boolean isDescription) {
		this.isDescription = isDescription;
	}

	public String getBugSummary() {
		return bugSummary;
	}
}

Back to the top