Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0b24fa1d74e6088a1fe55be3a7489a767303af08 (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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies 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:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.core;

import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.mylyn.tasks.core.IRepositoryElement;
import org.eclipse.mylyn.tasks.core.ITask;

/**
 * Encapsulates tasks that reside on a repository or local computer and participate in synchronization with the source
 * that contains their data.
 * 
 * @author Mik Kersten
 * @author Rob Elves
 * @since 2.0
 */
public abstract class AbstractTask extends AbstractTaskContainer implements ITask, ITaskRepositoryElement {

	public static final String DEFAULT_TASK_KIND = "task"; //$NON-NLS-1$

	private String repositoryUrl;

	private String taskKind = DEFAULT_TASK_KIND;

	private final String taskId;

	private String owner;

	private boolean active = false;

	private String summary;

	private String priority = PriorityLevel.getDefault().toString();

	private boolean isNotifiedIncoming = false;

	private boolean reminded = false;

	private final Set<AbstractTaskContainer> containers = new HashSet<AbstractTaskContainer>();

	// ************ Synch ****************

	/** The last time this task's bug report was in a synchronized (read?) state. */
	private String lastReadTimeStamp;

	private boolean synchronizing;

	private boolean submitting;

	private SynchronizationState synchronizationState = SynchronizationState.SYNCHRONIZED;

	// transient
	private IStatus status = null;

	private boolean stale = false;

	private Date completionDate = null;

	private Date creationDate = null;

	private Date modificationDate = null;

	private DateRange scheduledForDate = null;

	private Date dueDate = null;

	private String notes = ""; //$NON-NLS-1$

	private int estimatedTimeHours = 1;

	private boolean markReadPending;

	// TODO 4.0 make private
	protected String taskKey;

	private AttributeMap attributeMap;

	private boolean changed;

	public AbstractTask(String repositoryUrl, String taskId, String summary) {
		super(RepositoryTaskHandleUtil.getHandle(repositoryUrl, taskId));
		this.repositoryUrl = repositoryUrl;
		this.taskId = taskId;
		this.summary = summary;
	}

	/**
	 * Final to preserve the handle identifier format required by the framework.
	 */
	@Override
	public final String getHandleIdentifier() {
		return super.getHandleIdentifier();
	}

	/**
	 * True for tasks that can be modified without a round-trip to a server. For example, such a task can be marked
	 * completed via the Task List.
	 * 
	 * @deprecated use <code>task instanceof LocalTask</code> instead
	 */
	@Deprecated
	public abstract boolean isLocal();

	public abstract String getConnectorKind();

	@Deprecated
	public String getLastReadTimeStamp() {
		return lastReadTimeStamp;
	}

	@Deprecated
	public void setLastReadTimeStamp(String lastReadTimeStamp) {
		this.lastReadTimeStamp = lastReadTimeStamp;
	}

	/**
	 * @since 3.0
	 */
	public void setSynchronizationState(SynchronizationState syncState) {
		Assert.isNotNull(syncState);
		this.synchronizationState = syncState;
	}

	/**
	 * @since 3.0
	 */
	public SynchronizationState getSynchronizationState() {
		return synchronizationState;
	}

	public boolean isSynchronizing() {
		return synchronizing;
	}

	public void setSynchronizing(boolean sychronizing) {
		this.synchronizing = sychronizing;
	}

	public boolean isNotified() {
		return isNotifiedIncoming;
	}

	public void setNotified(boolean notified) {
		isNotifiedIncoming = notified;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		if (!areEqual(this.owner, owner)) {
			String oldValue = this.owner;
			this.owner = owner;
			firePropertyChange("owner", oldValue, owner); //$NON-NLS-1$
		}
	}

	/**
	 * Return the status, such as an error or warning, associated with this task.
	 */
	public IStatus getStatus() {
		return status;
	}

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

	public final String getTaskId() {
		return taskId;
	}

	public final String getRepositoryUrl() {
		return repositoryUrl;
	}

	@Override
	public final void setHandleIdentifier(String handleIdentifier) {
		throw new RuntimeException("Cannot set the handle identifier of a task, set repository URL instead."); //$NON-NLS-1$
	}

	public final void setRepositoryUrl(String repositoryUrl) {
		this.repositoryUrl = repositoryUrl;
		super.setHandleIdentifier(RepositoryTaskHandleUtil.getHandle(repositoryUrl, taskId));
	}

	/**
	 * User identifiable key for the task to be used in UI facilities such as label displays and hyperlinked references.
	 * Can return the same as the ID (e.g. in the case of Bugzilla). Can return null if no such label exists.
	 */
	public String getTaskKey() {
		return (taskKey == null) ? taskId : taskKey;
	}

	@Deprecated
	public boolean isSubmitting() {
		return submitting;
	}

	@Deprecated
	public void setSubmitting(boolean submitting) {
		this.submitting = submitting;
	}

	@Override
	public String toString() {
		return summary;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public boolean isActive() {
		return active;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof AbstractTask) {
			return this.getHandleIdentifier().equals(((ITask) obj).getHandleIdentifier());
		} else {
			return false;
		}
	}

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

	public boolean isCompleted() {
		return completionDate != null;
	}

	/**
	 * @deprecated use setCompletionDate()
	 */
	@Deprecated
	public void setCompleted(boolean completed) {
		if (completed) {
			completionDate = new Date();
		} else {
			completionDate = null;
		}
	}

	@Override
	public String getPriority() {
		return priority;
	}

	public void setPriority(String priority) {
		if (!areEqual(this.priority, priority)) {
			String oldValue = this.priority;
			this.priority = priority;
			firePropertyChange("priority", oldValue, priority); //$NON-NLS-1$
		}
	}

	public String getNotes() {
		// TODO: removed check for null once xml updated.
		if (notes == null) {
			notes = ""; //$NON-NLS-1$
		}
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	/**
	 * @deprecated Use {@link #getEstimatedTimeHours()} instead
	 */
	@Deprecated
	public int getEstimateTimeHours() {
		return getEstimatedTimeHours();
	}

	public int getEstimatedTimeHours() {
		return estimatedTimeHours;
	}

	public void setEstimatedTimeHours(int estimated) {
		this.estimatedTimeHours = estimated;
	}

	void addParentContainer(AbstractTaskContainer container) {
		containers.add(container);
	}

	void removeParentContainer(AbstractTaskContainer container) {
		containers.remove(container);
	}

	public Set<AbstractTaskContainer> getParentContainers() {
		return new HashSet<AbstractTaskContainer>(containers);
	}

	@Override
	public String getSummary() {
		return summary;
	}

	public Date getCompletionDate() {
		return completionDate;
	}

	public void setScheduledForDate(DateRange reminderDate) {
		scheduledForDate = reminderDate;
	}

	public DateRange getScheduledForDate() {
		return scheduledForDate;
	}

	public boolean isReminded() {
		return reminded;
	}

	public void setReminded(boolean reminded) {
		this.reminded = reminded;
	}

	public Date getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(Date creationDate) {
		if (!areEqual(this.creationDate, creationDate)) {
			Date oldValue = this.creationDate;
			this.creationDate = creationDate;
			firePropertyChange("creationDate", oldValue, creationDate); //$NON-NLS-1$
		}
	}

	public void setSummary(String summary) {
		Assert.isNotNull(summary);
		if (!areEqual(this.summary, summary)) {
			String oldValue = this.summary;
			this.summary = summary;
			firePropertyChange("summary", oldValue, summary); //$NON-NLS-1$
		}
	}

	public void setCompletionDate(Date completionDate) {
		if (!areEqual(this.completionDate, completionDate)) {
			Date oldValue = this.completionDate;
			this.completionDate = completionDate;
			firePropertyChange("completionDate", oldValue, completionDate); //$NON-NLS-1$
		}
	}

	private boolean areEqual(Object oldValue, Object newValue) {
		return (oldValue != null) ? oldValue.equals(newValue) : oldValue == newValue;
	}

	private void firePropertyChange(String key, Object oldValue, Object newValue) {
//			PropertyChangeEvent event = new PropertyChangeEvent(this, key, oldValue, newValue);
//			for (PropertyChangeListener listener : propertyChangeListeners) {
//				listener.propertyChange(event);
//			}
		changed = true;
	}

	public boolean isChanged() {
		return changed;
	}

	public void setChanged(boolean changed) {
		this.changed = changed;
	}

	/**
	 * @deprecated use {@link TaskActivityManager#isPastReminder(AbstractTask)} instead
	 */
	@Deprecated
	public boolean isPastReminder() {
		if (isCompleted() || scheduledForDate == null || !(getScheduledForDate() instanceof DayDateRange)) {
			return false;
		} else {
			if (/*!internalIsFloatingScheduledDate() && */scheduledForDate.getEndDate().compareTo(
					TaskActivityUtil.getCalendar()) < 0) {
				return true;
			} else {
				return false;
			}
		}
	}

	public String getTaskKind() {
		return taskKind;
	}

	public void setTaskKind(String taskKind) {
		if (!areEqual(this.taskKind, taskKind)) {
			String oldValue = this.taskKind;
			this.taskKind = taskKind;
			firePropertyChange("taskKind", oldValue, taskKind); //$NON-NLS-1$
		}
	}

	@Override
	public int compareTo(IRepositoryElement taskListElement) {
		return summary.compareTo(((AbstractTask) taskListElement).summary);
	}

	public Date getDueDate() {
		return dueDate;
	}

	public void setDueDate(Date date) {
		if (!areEqual(this.dueDate, date)) {
			Date oldValue = this.dueDate;
			this.dueDate = date;
			firePropertyChange("dueDate", oldValue, date); //$NON-NLS-1$
		}
	}

	@Deprecated
	public boolean isStale() {
		return stale;
	}

	@Deprecated
	public void setStale(boolean stale) {
		this.stale = stale;
	}

	public Date getModificationDate() {
		return modificationDate;
	}

	public void setModificationDate(Date modificationDate) {
		if (!areEqual(this.modificationDate, modificationDate)) {
			Date oldValue = this.modificationDate;
			this.modificationDate = modificationDate;
			firePropertyChange("modificationDate", oldValue, modificationDate); //$NON-NLS-1$
		}
	}

	public boolean isMarkReadPending() {
		return markReadPending;
	}

	public void setMarkReadPending(boolean markReadPending) {
		this.markReadPending = markReadPending;
	}

	public void setTaskKey(String taskKey) {
		if (!areEqual(this.taskKey, taskKey)) {
			String oldValue = this.taskKey;
			this.taskKey = taskKey;
			firePropertyChange("taskKey", oldValue, taskKey); //$NON-NLS-1$
		}
	}

	public synchronized String getAttribute(String key) {
		return (attributeMap != null) ? attributeMap.getAttribute(key) : null;
	}

	public synchronized Map<String, String> getAttributes() {
		if (attributeMap != null) {
			return attributeMap.getAttributes();
		} else {
			return Collections.emptyMap();
		}
	}

	public void setAttribute(String key, String value) {
		String oldValue;
		synchronized (this) {
			if (attributeMap == null) {
				attributeMap = new AttributeMap();
			}
			oldValue = attributeMap.getAttribute(key);
			if (!areEqual(oldValue, value)) {
				attributeMap.setAttribute(key, value);
			} else {
				return;
			}
		}
		firePropertyChange(key, oldValue, value);
	}

	@Override
	public void setUrl(String url) {
		String oldValue = getUrl();
		if (!areEqual(oldValue, url)) {
			super.setUrl(url);
			firePropertyChange("url", oldValue, url); //$NON-NLS-1$
		}
	}

}

Back to the top