/******************************************************************************* * 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.tasks.core; import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * Class representing a report attribute * * @author Rob Elves */ public class RepositoryTaskAttribute implements Serializable { private static final long serialVersionUID = 6383803576644618720L; /** * Key for the author of a comment. * * TODO remove this key: Trac uses owner to denote the assignee of a ticket * and AbstractRepository has a getOwner() method which is confusing */ public static final String USER_OWNER = "task.common.user.owner"; public static final String USER_CC = "task.common.user.cc"; public static final String COMMENT_TEXT = "task.common.comment.text"; public static final String COMMENT_DATE = "task.common.comment.date"; // THIS IS NOT BEING USED BUT RATHER "USER_OWNER" for comments // TODO: use this id instead public static final String COMMENT_AUTHOR = "task.common.comment.author"; public static final String DESCRIPTION = "task.common.description"; public static final String ATTACHMENT_ID = "task.common.attachment.id"; public static final String ATTACHMENT_TYPE = "task.common.attachment.type"; public static final String ATTACHMENT_CTYPE = "task.common.attachment.ctype"; public static final String ATTACHMENT_DATE = "task.common.attachment.date"; public static final String ATTACHMENT_URL = "task.common.attachment.url"; public static final String ATTACHMENT_FILENAME = "filename"; public static final String USER_ASSIGNED = "task.common.user.assigned"; public static final String RESOLUTION = "task.common.resolution"; public static final String STATUS = "task.common.status"; public static final String PRIORITY = "task.common.priority"; public static final String DATE_MODIFIED = "task.common.date.modified"; public static final String USER_REPORTER = "task.common.user.reporter"; public static final String SUMMARY = "task.common.summary"; public static final String PRODUCT = "task.common.product"; public static final String DATE_CREATION = "task.common.date.created"; public static final String KEYWORDS = "task.common.keywords"; /** * Boolean attribute. If true, repository user needs to be added to the cc * list. */ public static final String ADD_SELF_CC = "task.common.addselfcc"; public static final String NEW_CC = "task.common.newcc"; public static final String REMOVE_CC = "task.common.removecc"; /** * String constant used to represent true for boolean attributes. */ public static final String TRUE = "1"; /** * String constant used to represent false for boolean attributes. */ public static final String FALSE = "0"; private boolean hidden = false; private boolean isReadOnly = false; /** Attribute pretty printing name */ private String name; /** Name of the option used when updating the attribute on the server */ private String key; /** Option parameters */ private Map optionParameters; /** Ordered list of legal attribute values */ private List options; /** * Attribute's values (selected or added) */ private List values = new ArrayList(); public RepositoryTaskAttribute(String key, String name, boolean hidden) { this.key = key; this.name = name; this.hidden = hidden; this.options = new ArrayList(); optionParameters = new HashMap(); } public String getName() { return name; } public String getID() { return key; } public boolean isReadOnly() { return isReadOnly; } public void setReadOnly(boolean readonly) { this.isReadOnly = readonly; } public String getOptionParameter(String option) { return optionParameters.get(option); } public List getOptions() { return options; } public String getValue() { if (values.size() > 0) { return values.get(0); } else { return ""; } } public List getValues() { return values; } public void setValue(String value) { if (values.size() > 0) { values.set(0, value); } else { values.add(value); } } public void setValues(List values) { this.values.clear(); this.values.addAll(values); } public void addValue(String value) { values.add(value); } public void removeValue(String value) { if (values.contains(value)) { values.remove(values.indexOf(value)); } } public void clearValues() { values.clear(); } /** * Adds an attribute option value * * @param readableValue * The value displayed on the screen * @param parameterValue * The option value used when sending the form to the server */ public void addOption(String readableValue, String parameterValue) { options.add(readableValue); optionParameters.put(readableValue, parameterValue); } public boolean hasOptions() { return options.size() > 0; } public void clearOptions() { options.clear(); optionParameters.clear(); } /** * Determine if the field was hidden or not * * @return True if the field was hidden */ public boolean isHidden() { return hidden; } /** * Set whether the field was hidden in the bug * * @param b * Whether the field was hidden or not */ public void setHidden(boolean b) { hidden = b; } @Override public String toString() { return getValue(); } }