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

import java.util.Collections;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.mylar.internal.tasklist.ui.views.TaskListView;
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryClient;
import org.eclipse.mylar.provisional.tasklist.AbstractRepositoryQuery;
import org.eclipse.mylar.provisional.tasklist.MylarTaskListPlugin;
import org.eclipse.mylar.provisional.tasklist.TaskList;
import org.eclipse.mylar.provisional.tasklist.TaskListManager;

/**
 * @author Robert Elves
 */
public class ScheduledTaskListRefreshJob extends Job {

	private static final String JOB_NAME = "Scheduled Tasklist Refresh Job";

	private long scheduleDelay = 1000 * 60 * 20;// 20 minutes default

	private TaskList taskList = null;

	private long count = 0;

	private TaskListManager taskManager;

	public ScheduledTaskListRefreshJob(long schedule, TaskListManager manager) {
		super(JOB_NAME);
		this.scheduleDelay = schedule;
		this.taskManager = manager;

	}

	public IStatus run(IProgressMonitor monitor) {
		if (TaskListView.getDefault() != null) {
			try {

				taskList = taskManager.getTaskList();
				List<AbstractRepositoryQuery> queries = Collections.unmodifiableList(taskList.getQueries());

				for (AbstractRepositoryQuery query : queries) {
					AbstractRepositoryClient client = MylarTaskListPlugin.getRepositoryManager().getRepositoryClient(
							query.getRepositoryKind());
					client.synchronize(query);
					if (monitor.isCanceled())
						return Status.CANCEL_STATUS;
				}

			} finally {
				count++;
				if (count == Long.MAX_VALUE)
					count = 0;
				schedule(scheduleDelay);
			}
		}
		return Status.OK_STATUS;
	}

	public void setSchedule(long schedule) {
		this.scheduleDelay = schedule;
	}

	/**
	 * for testing purposes
	 * 
	 * @return
	 */
	public long getCount() {
		return count;
	}

}

Back to the top