Skip to main content
summaryrefslogtreecommitdiffstats
blob: 2b81431235d111995a53448df8092f43f85a1467 (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
/*******************************************************************************
 * 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.trac.core;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.mylar.internal.trac.core.model.TracTicket.Key;
import org.eclipse.mylar.tasks.core.AbstractAttributeFactory;
import org.eclipse.mylar.tasks.core.RepositoryTaskAttribute;

/**
 * Provides a mapping from Mylar task keys to Trac ticket keys. 
 *
 * @author Steffen Pingel
 */
public class TracAttributeFactory extends AbstractAttributeFactory {

	private static final long serialVersionUID = 5333211422546115138L;

	private static Map<String, Attribute> attributeByTracKey = new HashMap<String, Attribute>();

	private static Map<String, String> tracKeyByTaskKey = new HashMap<String, String>();
	
	public enum Attribute {
		CC(Key.CC, "CC:", RepositoryTaskAttribute.USER_CC, true, false), 
		CHANGE_TIME(Key.CHANGE_TIME, "Last Modification:", RepositoryTaskAttribute.DATE_MODIFIED, true, true),
		COMPONENT(Key.COMPONENT, "Component:", null),
		DESCRIPTION(Key.DESCRIPTION, "Description:", RepositoryTaskAttribute.DESCRIPTION, true, false),
		ID(Key.ID, "<used by search engine>", null, true),
		KEYWORDS(Key.KEYWORDS, "Keywords:", RepositoryTaskAttribute.KEYWORDS),
		MILESTONE(Key.MILESTONE, "Milestone:", null),
		OWNER(Key.OWNER, "Assigned to:", RepositoryTaskAttribute.USER_ASSIGNED, true, true),
		PRIORITY(Key.PRIORITY, "Priority:", null),
		REPORTER(Key.REPORTER, "Reporter:", RepositoryTaskAttribute.USER_REPORTER, true, true),
		RESOLUTION(Key.RESOLUTION, "Resolution:", RepositoryTaskAttribute.RESOLUTION, false, true),
		SEVERITY(Key.SEVERITY, "Severity:", null),
		STATUS(Key.STATUS, "Status:", RepositoryTaskAttribute.STATUS, false, true),
		SUMMARY(Key.SUMMARY, "Summary:", RepositoryTaskAttribute.SUMMARY, true),
		TIME(Key.TIME, "Created:", RepositoryTaskAttribute.DATE_CREATION, true, true), 
		TYPE(Key.TYPE, "Type:", null), 
		VERSION(Key.VERSION, "Version:", null);		
		
		private final boolean isHidden;
		
		private final boolean isReadOnly;
		
		private final String tracKey;
		
		private final String prettyName;

		private final String taskKey;

		Attribute(Key key, String prettyName, String taskKey, boolean hidden, boolean readonly) {		
			this.tracKey = key.getKey();
			this.taskKey = taskKey;
			this.prettyName = prettyName;
			this.isHidden = hidden;
			this.isReadOnly = readonly;
			
			attributeByTracKey.put(tracKey, this);
			if (taskKey != null) {
				tracKeyByTaskKey.put(taskKey, tracKey);
			}
		}

		Attribute(Key key, String prettyName, String taskKey, boolean hidden) {		
			this(key, prettyName, taskKey, hidden, false);
		}
		
		Attribute(Key key, String prettyName, String taskKey) {		
			this(key, prettyName, taskKey, false, false);
		}

		public String getTaskKey() {
			return taskKey;
		}

		public String getTracKey() {
			return tracKey;
		}

		public boolean isHidden() {
			return isHidden;
		}	
		
		public boolean isReadOnly() {
			return isReadOnly;
		}
		
		public String toString() {
			return prettyName;
		}
	}

	static {
		// make sure hash maps get initialized when class is loaded
		Attribute.values();
	}

	@Override
	public boolean getIsHidden(String key) {
		Attribute attribute = attributeByTracKey.get(key);
		return (attribute != null) ? attribute.isHidden() : isInternalAttribute(key);
	}

	@Override
	public String getName(String key) {
		Attribute attribute = attributeByTracKey.get(key);
		// TODO if attribute == null it is probably a custom field: need 
		// to query custom field information from repoository
		return (attribute != null) ? attribute.toString() : key;
	}

	@Override
	public boolean isReadOnly(String key) {
		Attribute attribute = attributeByTracKey.get(key);
		return (attribute != null) ? attribute.isReadOnly() : false;
	}

	@Override
	public String mapCommonAttributeKey(String key) {
		String tracKey = tracKeyByTaskKey.get(key);
		return (tracKey != null) ? tracKey : key;
	}

	static boolean isInternalAttribute(String id) {
		return RepositoryTaskAttribute.REMOVE_CC.equals(id) || RepositoryTaskAttribute.NEW_CC.equals(id) || RepositoryTaskAttribute.ADD_SELF_CC.equals(id);
	}

}

Back to the top