Skip to main content
summaryrefslogtreecommitdiffstats
blob: bddd1155fd5f613e3755719dbd3c2821554685e0 (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
/*******************************************************************************
 * Copyright (c) 2004 - 2005 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.tasklist.report.internal;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.mylar.tasklist.ITask;
import org.eclipse.mylar.tasklist.ITaskListElement;
import org.eclipse.mylar.tasklist.internal.TaskCategory;
import org.eclipse.mylar.tasklist.internal.TaskList;

/**
 * @author Ken Sueda
 */
public class TaskReportGenerator {
	// NOTE: might want a map of tasks instead of a flattened list of tasks
	
	private List<ITasksCollector> collectors = new ArrayList<ITasksCollector>();
	private List<ITask> tasks = new ArrayList<ITask>();
	private TaskList tasklist = null;
	
	public TaskReportGenerator(TaskList tlist) {
		tasklist = tlist;		
	}
	
	public void addCollector(ITasksCollector collector) {
		collectors.add(collector);		
	}
	
	private void getTasksForReport() {
		List<ITask> roots = tasklist.getRootTasks();
		for(int i = 0; i < roots.size(); i++) {
			ITask t = (ITask) roots.get(i);
			for (ITasksCollector collector : collectors) {
				collector.consumeTask(t);
			}			
		}
		for (TaskCategory cat : tasklist.getTaskCategories()) {
			List<? extends ITaskListElement> sub = cat.getChildren();
			for (int j = 0; j < sub.size(); j++) {
				if (sub.get(j) instanceof ITaskListElement) {					
					ITaskListElement element = (ITaskListElement) sub.get(j);
					if (element.hasCorrespondingActivatableTask()) {
						for (ITasksCollector collector : collectors) {
							collector.consumeTask(element.getOrCreateCorrespondingTask());
						}
					}					
				}
			}
		}
		// TODO need to support handling things in the bugzilla registry
		for (ITasksCollector collector : collectors) {
			tasks.addAll(collector.getTasks());
		}
	}
	
	public void checkTasks() {
		getTasksForReport();
	}
	
	public List<ITask> getTasks() {		
		return tasks;
	}
}

Back to the top