Skip to main content
summaryrefslogtreecommitdiffstats
blob: ef2efb78d79595c61248f6192aa700d24fc9a8fe (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
/*******************************************************************************
 * Copyright (c) 2004, 2008 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.tasks.core.data;

import org.eclipse.core.runtime.Assert;

/**
 * @author Rob Elves
 * @author Steffen Pingel
 * @since 3.0
 */
public class TaskOperation {

	/**
	 * @since 3.0
	 */
	public static void applyTo(TaskAttribute taskAttribute, String operationId, String label) {
		TaskData taskData = taskAttribute.getTaskData();
		taskData.getAttributeMapper().setValue(taskAttribute, operationId);
		taskAttribute.getMetaData().defaults().setType(TaskAttribute.TYPE_OPERATION).setLabel(label).setDisabled(false);
	}

	/**
	 * @since 3.0
	 */
	public static TaskOperation createFrom(TaskAttribute taskAttribute) {
		Assert.isNotNull(taskAttribute);
		TaskData taskData = taskAttribute.getTaskData();
		TaskOperation operation = new TaskOperation(taskData.getConnectorKind(), taskData.getRepositoryUrl(),
				taskData.getTaskId(), taskAttribute.getValue());
		operation.setLabel(taskAttribute.getMetaData().getLabel());
		operation.setTaskAttribute(taskAttribute);
		return operation;
	}

	private final String connectorKind;

	private String label;

	private final String operationId;

	private final String repositoryUrl;

	private TaskAttribute taskAttribute;

	private final String taskId;

	/**
	 * @since 3.0
	 */
	public TaskOperation(String connectorKind, String repositoryUrl, String taskId, String operationId) {
		Assert.isNotNull(connectorKind);
		Assert.isNotNull(repositoryUrl);
		Assert.isNotNull(taskId);
		Assert.isNotNull(operationId);
		this.connectorKind = connectorKind;
		this.repositoryUrl = repositoryUrl;
		this.taskId = taskId;
		this.operationId = operationId;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		TaskOperation other = (TaskOperation) obj;
		if (!connectorKind.equals(other.connectorKind)) {
			return false;
		}
		if (!operationId.equals(other.operationId)) {
			return false;
		}
		if (!repositoryUrl.equals(other.repositoryUrl)) {
			return false;
		}
		if (!taskId.equals(other.taskId)) {
			return false;
		}
		return true;
	}

	/**
	 * @since 3.0
	 */
	public String getConnectorKind() {
		return connectorKind;
	}

	/**
	 * @since 3.0
	 */
	public String getLabel() {
		return label;
	}

	/**
	 * @since 3.0
	 */
	public String getOperationId() {
		return operationId;
	}

	public String getRepositoryUrl() {
		return repositoryUrl;
	}

	/**
	 * @since 3.0
	 */
	public TaskAttribute getTaskAttribute() {
		return taskAttribute;
	}

	/**
	 * @since 3.0
	 */
	public String getTaskId() {
		return taskId;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + connectorKind.hashCode();
		result = prime * result + operationId.hashCode();
		result = prime * result + repositoryUrl.hashCode();
		result = prime * result + taskId.hashCode();
		return result;
	}

	/**
	 * @since 3.0
	 */
	public void setLabel(String label) {
		this.label = label;
	}

	/**
	 * @since 3.0
	 */
	public void setTaskAttribute(TaskAttribute taskAttribute) {
		this.taskAttribute = taskAttribute;
	}

}

Back to the top