Skip to main content
summaryrefslogtreecommitdiffstats
blob: 427f2e2d1bec7e24660f232120625b67ace2bb94 (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
/*******************************************************************************
 * 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.tasks.core;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;

/**
 * @author Mik Kersten
 * @author Eugene Kuleshov
 * @author Rob Elves
 */
public abstract class AbstractRepositoryQuery extends AbstractTaskContainer {

	protected String repositoryUrl;

	protected String lastRefreshTimeStamp = "<never>";

	private boolean currentlySynchronizing = false;

	protected IStatus status = null;

	public abstract String getRepositoryKind();

	/**
	 * Query must be added to tasklist or synchronization will result in empty
	 * result set due to removeOrphanedHits(). All hits that don't have a query
	 * in the tasklist are removed.
	 */
	public AbstractRepositoryQuery(String description, TaskList taskList) {
		super(description, taskList);
	}

	public boolean isArchive() {
		return false;
	}

	public void setIsArchive(boolean isArchive) {
		// ignore
	}

	public synchronized Set<AbstractRepositoryTask> getHits() {
		Set<AbstractRepositoryTask> repositoryTasks = new HashSet<AbstractRepositoryTask>();
		for (ITask task : super.getChildren()) {
			if (task instanceof AbstractRepositoryTask) {
				repositoryTasks.add((AbstractRepositoryTask) task);
			}
		}
		return repositoryTasks;
	}

	public synchronized void updateHits(Collection<AbstractRepositoryTask> newHits) {
		clear();
		for (AbstractRepositoryTask abstractRepositoryTask : newHits) {
			addHit(abstractRepositoryTask);
		}
	}

	public synchronized void addHit(AbstractRepositoryTask hit) {
		// TODO: Move up?
		if(!taskList.getAllTasks().contains(hit)) {
			taskList.addTask(hit);
		}			
		super.add(hit);
	}

	public synchronized void removeHit(AbstractRepositoryTask hit) {
		super.remove(hit);
	}

	public synchronized String getPriority() {
		if (super.isEmpty()) {
			return Task.PriorityLevel.P1.toString();
		}
		String highestPriority = Task.PriorityLevel.P5.toString();
		for (AbstractRepositoryTask hit : getHits()) {
			if (highestPriority.compareTo(hit.getPriority()) > 0) {
				highestPriority = hit.getPriority();
			}
		}
		return highestPriority;
	}

	@Override
	public boolean isLocal() {
		return false;
	}

	@Override
	public boolean isCompleted() {
		return false;
	}

	public String getRepositoryUrl() {
		return repositoryUrl;
	}

	public void setRepositoryUrl(String newRepositoryUrl) {
		if (repositoryUrl != null && url != null) {
			// the repository url has changed, so change corresponding part of
			// query URL
			this.url = newRepositoryUrl + url.substring(repositoryUrl.length());
		}
		this.repositoryUrl = newRepositoryUrl;
	}

	public boolean isSynchronizing() {
		return currentlySynchronizing;
	}

	public void setCurrentlySynchronizing(boolean currentlySynchronizing) {
		this.currentlySynchronizing = currentlySynchronizing;
	}

	public String getLastRefreshTimeStamp() {
		return lastRefreshTimeStamp;
	}

	public void setLastRefreshTimeStamp(String lastRefreshTimeStamp) {
		this.lastRefreshTimeStamp = lastRefreshTimeStamp;
	}

	public IStatus getStatus() {
		return status;
	}

	public void setStatus(IStatus status) {
		this.status = status;
	}

}

Back to the top