Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2011-03-05 02:14:09 -0500
committerspingel2011-03-05 02:14:09 -0500
commit0b0c8257804f12431e6499d0c8c634040aa25ef9 (patch)
tree720329c1af83c44c7d479487e26cb7e806b1459c /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data
parentd97421adca44d14f2264549b6a6ae2903efd0be7 (diff)
downloadorg.eclipse.mylyn.tasks-0b0c8257804f12431e6499d0c8c634040aa25ef9.tar.gz
org.eclipse.mylyn.tasks-0b0c8257804f12431e6499d0c8c634040aa25ef9.tar.xz
org.eclipse.mylyn.tasks-0b0c8257804f12431e6499d0c8c634040aa25ef9.zip
REOPENED - bug 337083: provide an extensible task schema implementation
https://bugs.eclipse.org/bugs/show_bug.cgi?id=337083
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java198
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/DefaultTaskSchema.java151
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java1
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java1
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java3
5 files changed, 350 insertions, 4 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java
new file mode 100644
index 000000000..42bff0760
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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 java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.Assert;
+
+/**
+ * Base class for task schemas. Clients should subclass to define a specific schema.
+ *
+ * @author Steffen Pingel
+ * @since 3.5
+ */
+public abstract class AbstractTaskSchema {
+
+ public static class Field {
+
+ private EnumSet<Flag> flags;
+
+ private final String key;
+
+ private final String label;
+
+ private final String type;
+
+ protected Field(String key, String label, String type) {
+ this(key, label, type, (Flag[]) null);
+ }
+
+ protected Field(String key, String label, String type, Flag... flags) {
+ Assert.isNotNull(key);
+ Assert.isNotNull(label);
+ Assert.isNotNull(type);
+ this.key = key;
+ this.label = label;
+ this.type = type;
+ if (flags == null) {
+ this.flags = EnumSet.noneOf(Flag.class);
+ } else {
+ this.flags = EnumSet.copyOf(Arrays.asList(flags));
+ }
+ }
+
+ public TaskAttribute createAttribute(TaskAttribute parent) {
+ TaskAttribute attribute = parent.createMappedAttribute(getKey());
+ // meta data
+ TaskAttributeMetaData metaData = attribute.getMetaData();
+ metaData.setLabel(getLabel());
+ metaData.setType(getType());
+ metaData.setReadOnly(isReadOnly());
+ metaData.setKind(getKind());
+ // options
+ Map<String, String> options = getDefaultOptions();
+ if (options != null) {
+ for (Entry<String, String> option : options.entrySet()) {
+ attribute.putOption(option.getKey(), option.getValue());
+ }
+ }
+ return attribute;
+ }
+
+ public Map<String, String> getDefaultOptions() {
+ return Collections.emptyMap();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getKind() {
+ if (flags.contains(Flag.ATTRIBUTE)) {
+ return TaskAttribute.KIND_DEFAULT;
+ } else if (flags.contains(Flag.PEOPLE)) {
+ return TaskAttribute.KIND_PEOPLE;
+ } else if (flags.contains(Flag.OPERATION)) {
+ return TaskAttribute.KIND_OPERATION;
+ }
+ return null;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public boolean isReadOnly() {
+ return flags.contains(Flag.READ_ONLY);
+ }
+
+ @Override
+ public String toString() {
+ return getLabel();
+ }
+
+ }
+
+ public enum Flag {
+ ATTRIBUTE, OPERATION, PEOPLE, READ_ONLY
+ };
+
+ protected class FieldFactory {
+
+ private EnumSet<Flag> flags;
+
+ private String key;
+
+ private String label;
+
+ private String type;
+
+ public FieldFactory(Field source) {
+ this.flags = EnumSet.copyOf(source.flags);
+ this.key = source.key;
+ this.label = source.label;
+ this.type = source.type;
+ }
+
+ public FieldFactory addFlags(Flag... flags) {
+ this.flags.addAll(Arrays.asList(flags));
+ return this;
+ }
+
+ public Field create() {
+ return createField(key, label, type, (!flags.isEmpty()) ? flags.toArray(new Flag[0]) : null);
+ }
+
+ public FieldFactory flags(Flag... flags) {
+ this.flags = EnumSet.copyOf(Arrays.asList(flags));
+ return this;
+ }
+
+ public FieldFactory key(String key) {
+ this.key = key;
+ return this;
+ }
+
+ public FieldFactory label(String label) {
+ this.label = label;
+ return this;
+ }
+
+ public FieldFactory removeFlags(Flag... flags) {
+ this.flags.removeAll(Arrays.asList(flags));
+ return this;
+ }
+
+ public FieldFactory type(String type) {
+ this.type = type;
+ return this;
+ }
+
+ }
+
+ private final Map<String, Field> fieldByKey = new LinkedHashMap<String, Field>();
+
+ public Field getFieldByKey(String taskKey) {
+ return fieldByKey.get(taskKey);
+ }
+
+ public void initialize(TaskData taskData) {
+ for (Field field : fieldByKey.values()) {
+ field.createAttribute(taskData.getRoot());
+ }
+ }
+
+ protected Field createField(String key, String label, String type) {
+ return createField(key, label, type, (Flag[]) null);
+ }
+
+ protected Field createField(String key, String label, String type, Flag... flags) {
+ Field field = new Field(key, label, type, flags);
+ fieldByKey.put(key, field);
+ return field;
+ }
+
+ protected FieldFactory inheritFrom(Field source) {
+ return new FieldFactory(source);
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/DefaultTaskSchema.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/DefaultTaskSchema.java
new file mode 100644
index 000000000..88fb3f62c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/DefaultTaskSchema.java
@@ -0,0 +1,151 @@
+/*******************************************************************************
+ * Copyright (c) 2009, 2010 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.mylyn.internal.tasks.core.data.Messages;
+
+/**
+ * Specifies types and other properties for commonly used task fields.
+ *
+ * @author Steffen Pingel
+ * @since 3.5
+ */
+public final class DefaultTaskSchema extends AbstractTaskSchema {
+
+ private static final DefaultTaskSchema instance = new DefaultTaskSchema();
+
+ public static Field getField(String taskKey) {
+ return instance.getFieldByKey(taskKey);
+ }
+
+ public static DefaultTaskSchema getInstance() {
+ return instance;
+ }
+
+ public final Field ADD_SELF_CC = createField(TaskAttribute.ADD_SELF_CC,
+ Messages.DefaultTaskSchema_Add_Self_to_CC_Label, TaskAttribute.TYPE_BOOLEAN);
+
+ public final Field ATTACHMENT_AUTHOR = createField(TaskAttribute.ATTACHMENT_AUTHOR,
+ Messages.DefaultTaskSchema_Author_Label, TaskAttribute.TYPE_PERSON);
+
+ public final Field ATTACHMENT_CONTENT_TYPE = createField(TaskAttribute.ATTACHMENT_CONTENT_TYPE,
+ Messages.DefaultTaskSchema_Content_Type_Label, TaskAttribute.TYPE_SHORT_TEXT);
+
+ public final Field ATTACHMENT_DATE = createField(TaskAttribute.ATTACHMENT_DATE,
+ Messages.DefaultTaskSchema_Created_Label, TaskAttribute.TYPE_DATETIME, Flag.READ_ONLY);
+
+ public final Field ATTACHMENT_DESCRIPTION = createField(TaskAttribute.ATTACHMENT_DESCRIPTION,
+ Messages.DefaultTaskSchema_Description_Label, TaskAttribute.TYPE_SHORT_RICH_TEXT);
+
+ public final Field ATTACHMENT_FILENAME = createField(TaskAttribute.ATTACHMENT_FILENAME,
+ Messages.DefaultTaskSchema_Filename_Label, TaskAttribute.TYPE_SHORT_TEXT);
+
+ public final Field ATTACHMENT_ID = createField(TaskAttribute.ATTACHMENT_ID, Messages.DefaultTaskSchema_ID_Label,
+ TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public final Field ATTACHMENT_IS_DEPRECATED = createField(TaskAttribute.ATTACHMENT_IS_DEPRECATED,
+ Messages.DefaultTaskSchema_Deprecated_Label, TaskAttribute.TYPE_BOOLEAN);
+
+ public final Field ATTACHMENT_IS_PATCH = createField(TaskAttribute.ATTACHMENT_IS_PATCH,
+ Messages.DefaultTaskSchema_Patch_Label, TaskAttribute.TYPE_BOOLEAN);
+
+ public final Field ATTACHMENT_REPLACE_EXISTING = createField(TaskAttribute.ATTACHMENT_REPLACE_EXISTING,
+ Messages.DefaultTaskSchema_Replace_existing_attachment, TaskAttribute.TYPE_BOOLEAN);
+
+ public final Field ATTACHMENT_SIZE = createField(TaskAttribute.ATTACHMENT_SIZE,
+ Messages.DefaultTaskSchema_Size_Label, TaskAttribute.TYPE_LONG, Flag.READ_ONLY);
+
+ public final Field ATTACHMENT_URL = createField(TaskAttribute.ATTACHMENT_URL, Messages.DefaultTaskSchema_URL_Label,
+ TaskAttribute.TYPE_URL);
+
+ public final Field COMMENT_ATTACHMENT_ID = createField(TaskAttribute.COMMENT_ATTACHMENT_ID,
+ Messages.DefaultTaskSchema_Attachment_ID_Label, TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public final Field COMMENT_AUTHOR = createField(TaskAttribute.COMMENT_AUTHOR,
+ Messages.DefaultTaskSchema_Author_Label, TaskAttribute.TYPE_PERSON, Flag.READ_ONLY);
+
+ public final Field COMMENT_DATE = createField(TaskAttribute.COMMENT_DATE, Messages.DefaultTaskSchema_Created_Label,
+ TaskAttribute.TYPE_DATETIME, Flag.READ_ONLY);
+
+ public final Field COMMENT_HAS_ATTACHMENT = createField(TaskAttribute.COMMENT_HAS_ATTACHMENT,
+ Messages.DefaultTaskSchema_Attachment_Label, TaskAttribute.TYPE_BOOLEAN, Flag.READ_ONLY);
+
+ public final Field COMMENT_NUMBER = createField(TaskAttribute.COMMENT_NUMBER,
+ Messages.DefaultTaskSchema_Number_Label, TaskAttribute.TYPE_INTEGER, Flag.READ_ONLY);
+
+ public final Field COMMENT_TEXT = createField(TaskAttribute.COMMENT_TEXT,
+ Messages.DefaultTaskSchema_Description_Label, TaskAttribute.TYPE_LONG_RICH_TEXT, Flag.READ_ONLY);
+
+ public final Field COMMENT_URL = createField(TaskAttribute.COMMENT_URL, Messages.DefaultTaskSchema_URL_Label,
+ TaskAttribute.TYPE_URL, Flag.READ_ONLY);
+
+ public final Field COMPONENT = createField(TaskAttribute.COMPONENT, Messages.DefaultTaskSchema_Component_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public final Field DATE_COMPLETION = createField(TaskAttribute.DATE_COMPLETION,
+ Messages.DefaultTaskSchema_Completion_Label, TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public final Field DATE_CREATION = createField(TaskAttribute.DATE_CREATION,
+ Messages.DefaultTaskSchema_Created_Label, TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public final Field DATE_DUE = createField(TaskAttribute.DATE_DUE, Messages.DefaultTaskSchema_Due_Label,
+ TaskAttribute.TYPE_DATE);
+
+ public final Field DATE_MODIFICATION = createField(TaskAttribute.DATE_MODIFICATION,
+ Messages.DefaultTaskSchema_Modified_Label, TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public final Field DESCRIPTION = createField(TaskAttribute.DESCRIPTION,
+ Messages.DefaultTaskSchema_Description_Label, TaskAttribute.TYPE_LONG_RICH_TEXT);
+
+ public final Field KEYWORDS = createField(TaskAttribute.KEYWORDS, Messages.DefaultTaskSchema_Keywords_Label,
+ TaskAttribute.TYPE_MULTI_SELECT, Flag.ATTRIBUTE);
+
+ public final Field NEW_COMMENT = createField(TaskAttribute.COMMENT_NEW, Messages.DefaultTaskSchema_Rank_Label,
+ TaskAttribute.TYPE_LONG_RICH_TEXT);
+
+ public final Field PRIORITY = createField(TaskAttribute.PRIORITY, Messages.DefaultTaskSchema_Priority_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public final Field PRODUCT = createField(TaskAttribute.PRODUCT, Messages.DefaultTaskSchema_Product_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public final Field RANK = createField(TaskAttribute.RANK, Messages.DefaultTaskSchema_Rank_Label,
+ TaskAttribute.TYPE_INTEGER, Flag.READ_ONLY);
+
+ public final Field RESOLUTION = createField(TaskAttribute.RESOLUTION, Messages.DefaultTaskSchema_Resolution_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.READ_ONLY);
+
+ public final Field SEVERITY = createField(TaskAttribute.SEVERITY, Messages.DefaultTaskSchema_Severity_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public final Field STATUS = createField(TaskAttribute.STATUS, Messages.DefaultTaskSchema_Status_Label,
+ TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public final Field SUMMARY = createField(TaskAttribute.SUMMARY, Messages.DefaultTaskSchema_Summary_Label,
+ TaskAttribute.TYPE_SHORT_RICH_TEXT);
+
+ public final Field TASK_KEY = createField(TaskAttribute.TASK_KEY, Messages.DefaultTaskSchema_Key_Label,
+ TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public final Field TASK_KIND = createField(TaskAttribute.TASK_KIND, Messages.DefaultTaskSchema_Kind_Label,
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public final Field USER_ASSIGNED = createField(TaskAttribute.USER_ASSIGNED, Messages.DefaultTaskSchema_Owner_Label,
+ TaskAttribute.TYPE_PERSON, Flag.PEOPLE);
+
+ public final Field USER_REPORTER = createField(TaskAttribute.USER_REPORTER,
+ Messages.DefaultTaskSchema_Reporter_Label, TaskAttribute.TYPE_PERSON, Flag.PEOPLE, Flag.READ_ONLY);
+
+ public final Field TASK_URL = createField(TaskAttribute.TASK_URL, Messages.DefaultTaskSchema_URL_Label,
+ TaskAttribute.TYPE_URL, Flag.READ_ONLY);
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
index 2e90618ba..470058530 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
@@ -14,7 +14,6 @@ package org.eclipse.mylyn.tasks.core.data;
import java.util.Date;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
index 0fcea3c61..764b70a24 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
@@ -14,7 +14,6 @@ package org.eclipse.mylyn.tasks.core.data;
import java.util.Date;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
import org.eclipse.mylyn.tasks.core.ITaskComment;
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
index becc56e25..a8de952f9 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
@@ -15,10 +15,9 @@ import java.util.Date;
import java.util.List;
import org.eclipse.core.runtime.Assert;
-import org.eclipse.mylyn.internal.tasks.core.data.AbstractTaskSchema.Field;
-import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
/**

Back to the top