Skip to main content
summaryrefslogtreecommitdiffstats
blob: fd87c71eff9d1f6e7f27bf24df956c92039436cf (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
/*******************************************************************************
 * 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.tasklist;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Mik Kersten
 * @author Rob Elves
 */
public abstract class AbstractRepositoryReport extends AttributeContainer implements Serializable {

	private int reportID;

	private String repositoryURL;

	private List<Comment> comments = new ArrayList<Comment>();

	private List<ReportAttachment> attachments = new ArrayList<ReportAttachment>();

	private boolean hasChanges = false;

	public AbstractRepositoryReport(int id, String repositoryURL) {
		super();
		this.reportID = id;
		this.repositoryURL = repositoryURL;
	}

	public void addComment(Comment comment) {
		Comment preceding = null;
		if (comments.size() > 0) {
			// if there are some comments, get the last comment and set the next
			// value to be the new comment
			preceding = comments.get(comments.size() - 1);
			preceding.setNext(comment);
		}
		// set the comments previous value to the preceeding one
		comment.setPrevious(preceding);

		// comment.setText(decodeStringFromCharset(comment.getText()));
		// add the comment to the comment list
		comments.add(comment);
	}

	public List<Comment> getComments() {
		return comments;
	}

	public void addAttachment(ReportAttachment attachment) {
		attachments.add(attachment);
	}

	public List<ReportAttachment> getAttachments() {
		return attachments;
	}

	public int getId() {
		return reportID;
	}

	/**
	 * @return the server for this report
	 */
	public String getRepositoryUrl() {
		return repositoryURL;
	}
	

	public boolean hasChanges() {
		return hasChanges ;
	}

	public void setHasChanged(boolean b) {
		hasChanges = b;
	}
	
	/**
	 * @return <code>true</code> if this report was created locally, and does not
	 *         yet exist on a server.
	 */
	public abstract boolean isLocallyCreated();
	
	/**
	 * @return <code>true</code> if this report is saved offline.
	 */
	public abstract boolean isSavedOffline();

	/**
	 * Sets whether or not this report is saved offline.
	 * 
	 * @param newOfflineState
	 *            <code>true</code> if this bug is saved offline
	 */
	public abstract void setOfflineState(boolean newOfflineState);

//	public String getAttributeValue(Object key) {
//		AbstractRepositoryTaskAttribute attribute = getAttribute(key);
//		if(attribute != null) {
//			return attribute.getValue();
//		}
//		return "";
//	}
	
	public List<String> getAttributeValues(Object key) {
		AbstractRepositoryTaskAttribute attribute = getAttribute(key);
		if(attribute != null) {
			return attribute.getValues();
		}
		return new ArrayList<String>();
	}

	/** 
	 * sets a value on an attribute, if attribute doesn't exist,
	 * appropriate attribute is created
	 */
	public void setAttributeValue(Object key, String value) {
		AbstractRepositoryTaskAttribute attrib = getAttribute(key);
		if(attrib == null) {
			attrib = getAttributeFactory().createAttribute(key);
			this.addAttribute(key, attrib);
		}
		attrib.setValue(value);		
	}
	
	public void addAttributeValue(Object key, String value) {
		AbstractRepositoryTaskAttribute attrib = getAttribute(key);
		if (attrib != null) {
			attrib.addValue(value);
		} else {
			attrib = getAttributeFactory().createAttribute(key);
			attrib.addValue(value);
			this.addAttribute(key, attrib);
		}
	}
	
	public void removeAttributeValue(Object key, String value) {
		AbstractRepositoryTaskAttribute attrib = getAttribute(key);
		if (attrib != null) {
			attrib.removeValue(value);
		} 
	}

	public abstract AbstractTaskAttributeFactory getAttributeFactory();
}

Back to the top