Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5149c08dd186adc5f8e79352319ba561f656ad93 (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
/*******************************************************************************
 * 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 org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.TaskRepository;
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;

/**
 * @author Mik Kersten
 * @author Rob Elves
 */
public class RepositoryTaskEditorInput extends AbstractTaskEditorInput {

	protected String taskId;

	protected String url;

	protected AbstractRepositoryTask repositoryTask = null;

	public RepositoryTaskEditorInput(TaskRepository repository, String handle, String taskUrl, String taskId) {
		super(repository, handle);
		this.taskId = taskId;
		this.url = taskUrl;
		ITask task = TasksUiPlugin.getTaskListManager().getTaskList().getTask(handle);
		if (task != null && task instanceof AbstractRepositoryTask) {
			this.repositoryTask = (AbstractRepositoryTask) task;
		}
	}

	public AbstractRepositoryTask getRepositoryTask() {
		return repositoryTask;
	}

	public String getName() {
		if (repositoryTask != null) {
			String idLabel = repositoryTask.getTaskKey();

			String label = "";
			if (idLabel != null) {
				label += idLabel + ": ";
			}
			label += repositoryTask.getSummary();
			return label;
		} else if (getTaskData() != null && getTaskData().getLabel() != null) {
			return getTaskData().getTaskKey() + ": " + getTaskData().getLabel();
		} else if (taskId != null) {
			return taskId;
		} else {
			return "<unknown>";
		}
	}

	/**
	 * @return The taskId of the bug for this editor input.
	 */
	public String getId() {
		return taskId;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((repositoryTask == null) ? 0 : repositoryTask.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final RepositoryTaskEditorInput other = (RepositoryTaskEditorInput) obj;
		if (repositoryTask == null) {
			if (other.repositoryTask != null) {
				return false;
			} else if (!other.getId().equals(this.getId())) {
				return false;
			}
		} else if (!repositoryTask.equals(other.repositoryTask))
			return false;
		return true;
	}

	/**
	 * @return url for the repositoryTask/hit. Used by TaskEditor when opening
	 *         browser
	 */
	public String getUrl() {
		return url;
	}

}

Back to the top