diff options
author | spingel | 2010-02-03 19:46:07 +0000 |
---|---|---|
committer | spingel | 2010-02-03 19:46:07 +0000 |
commit | fce2363f372bac4d0dac48eecb332708d95f205e (patch) | |
tree | a5c11eb6b55a8bef088474e6005c4696352e25eb /org.eclipse.mylyn.tasks.core/src | |
parent | 31022318b9c4468c0f173d7bb4e29e1f11f20b6d (diff) | |
download | org.eclipse.mylyn.tasks-fce2363f372bac4d0dac48eecb332708d95f205e.tar.gz org.eclipse.mylyn.tasks-fce2363f372bac4d0dac48eecb332708d95f205e.tar.xz org.eclipse.mylyn.tasks-fce2363f372bac4d0dac48eecb332708d95f205e.zip |
NEW - bug 216557: [patch] add option to "Replace existing attachment of the same name" when attaching files
https://bugs.eclipse.org/bugs/show_bug.cgi?id=216557
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src')
6 files changed, 278 insertions, 144 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java index 2dc021352..5b628b374 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java @@ -147,6 +147,9 @@ public class DefaultTaskSchema { public static final Field ATTACHMENT_IS_PATCH = createField(TaskAttribute.ATTACHMENT_IS_PATCH, Messages.DefaultTaskSchema_Patch_Label, TaskAttribute.TYPE_BOOLEAN); + public static final Field ATTACHMENT_REPLACE_EXISTING = createField(TaskAttribute.ATTACHMENT_REPLACE_EXISTING, + Messages.DefaultTaskSchema_Replace_existing_attachment, TaskAttribute.TYPE_BOOLEAN); + public static final Field ATTACHMENT_SIZE = createField(TaskAttribute.ATTACHMENT_SIZE, Messages.DefaultTaskSchema_Size_Label, TaskAttribute.TYPE_LONG, Flag.READ_ONLY); diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java index 4e68e4f4a..66ad26b76 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/Messages.java @@ -62,6 +62,8 @@ public class Messages extends NLS { public static String DefaultTaskSchema_Rank_Label; + public static String DefaultTaskSchema_Replace_existing_attachment; + public static String DefaultTaskSchema_Reporter_Label; public static String DefaultTaskSchema_Resolution_Label; diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties index a33bae106..d85d0227a 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/messages.properties @@ -21,6 +21,7 @@ DefaultTaskSchema_Patch_Label=Patch DefaultTaskSchema_Priority_Label=Priority DefaultTaskSchema_Product_Label=Product DefaultTaskSchema_Rank_Label=Rank +DefaultTaskSchema_Replace_existing_attachment=Replace existing attachment of the same name DefaultTaskSchema_Reporter_Label=Reporter DefaultTaskSchema_Resolution_Label=Resolution DefaultTaskSchema_Severity_Label=Severity 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 935a9d431..d0f017d3a 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 @@ -24,119 +24,6 @@ import org.eclipse.mylyn.tasks.core.ITaskAttachment; */ public class TaskAttachmentMapper { - private IRepositoryPerson author; - - private String comment; - - private String contentType; - - private Date creationDate; - - private Boolean deprecated; - - private String description; - - private String fileName; - - private Long length; - - private Boolean patch; - - private String url; - - private String attachmentId; - - public TaskAttachmentMapper() { - } - - public String getAttachmentId() { - return attachmentId; - } - - public IRepositoryPerson getAuthor() { - return author; - } - - public String getComment() { - return comment; - } - - public String getContentType() { - return contentType; - } - - public Date getCreationDate() { - return creationDate; - } - - public String getDescription() { - return description; - } - - public String getFileName() { - return fileName; - } - - public Long getLength() { - return length; - } - - public String getUrl() { - return url; - } - - public Boolean isDeprecated() { - return deprecated; - } - - public Boolean isPatch() { - return patch; - } - - public void setAttachmentId(String attachmentId) { - this.attachmentId = attachmentId; - } - - public void setAuthor(IRepositoryPerson author) { - this.author = author; - } - - public void setComment(String comment) { - this.comment = comment; - } - - public void setContentType(String contentType) { - this.contentType = contentType; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public void setDeprecated(Boolean deprecated) { - this.deprecated = deprecated; - } - - public void setDescription(String description) { - this.description = description; - } - - public void setFileName(String fileName) { - this.fileName = fileName; - } - - public void setLength(Long length) { - this.length = length; - } - - public void setPatch(Boolean patch) { - this.patch = patch; - } - - public void setUrl(String url) { - this.url = url; - } - public static TaskAttachmentMapper createFrom(TaskAttribute taskAttribute) { Assert.isNotNull(taskAttribute); TaskAttributeMapper mapper = taskAttribute.getTaskData().getAttributeMapper(); @@ -170,6 +57,10 @@ public class TaskAttachmentMapper { if (child != null) { attachment.setPatch(mapper.getBooleanValue(child)); } + child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_REPLACE_EXISTING); + if (child != null) { + attachment.setReplaceExisting(mapper.getBooleanValue(child)); + } child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE); if (child != null) { Long value = mapper.getLongValue(child); @@ -184,6 +75,64 @@ public class TaskAttachmentMapper { return attachment; } + private String attachmentId; + + private IRepositoryPerson author; + + private String comment; + + private String contentType; + + private Date creationDate; + + private Boolean deprecated; + + private String description; + + private String fileName; + + private Long length; + + private Boolean patch; + + private Boolean replaceExisting; + + private String url; + + public TaskAttachmentMapper() { + } + + public void applyTo(ITaskAttachment taskAttachment) { + Assert.isNotNull(taskAttachment); + if (getAuthor() != null) { + taskAttachment.setAuthor(getAuthor()); + } + if (getContentType() != null) { + taskAttachment.setContentType(getContentType()); + } + if (getCreationDate() != null) { + taskAttachment.setCreationDate(getCreationDate()); + } + if (getDescription() != null) { + taskAttachment.setDescription(getDescription()); + } + if (getFileName() != null) { + taskAttachment.setFileName(getFileName()); + } + if (isDeprecated() != null) { + taskAttachment.setDeprecated(isDeprecated()); + } + if (isPatch() != null) { + taskAttachment.setPatch(isPatch()); + } + if (getLength() != null) { + taskAttachment.setLength(getLength()); + } + if (url != null) { + taskAttachment.setUrl(getUrl()); + } + } + public void applyTo(TaskAttribute taskAttribute) { Assert.isNotNull(taskAttribute); TaskData taskData = taskAttribute.getTaskData(); @@ -217,6 +166,11 @@ public class TaskAttachmentMapper { taskAttribute); mapper.setValue(child, getFileName()); } + if (getReplaceExisting() != null) { + TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_REPLACE_EXISTING) + .createAttribute(taskAttribute); + mapper.setBooleanValue(child, getReplaceExisting()); + } if (isDeprecated() != null) { TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_IS_DEPRECATED).createAttribute( taskAttribute); @@ -239,37 +193,6 @@ public class TaskAttachmentMapper { } } - public void applyTo(ITaskAttachment taskAttachment) { - Assert.isNotNull(taskAttachment); - if (getAuthor() != null) { - taskAttachment.setAuthor(getAuthor()); - } - if (getContentType() != null) { - taskAttachment.setContentType(getContentType()); - } - if (getCreationDate() != null) { - taskAttachment.setCreationDate(getCreationDate()); - } - if (getDescription() != null) { - taskAttachment.setDescription(getDescription()); - } - if (getFileName() != null) { - taskAttachment.setFileName(getFileName()); - } - if (isDeprecated() != null) { - taskAttachment.setDeprecated(isDeprecated()); - } - if (isPatch() != null) { - taskAttachment.setPatch(isPatch()); - } - if (getLength() != null) { - taskAttachment.setLength(getLength()); - } - if (url != null) { - taskAttachment.setUrl(getUrl()); - } - } - @Override public boolean equals(Object obj) { if (!(obj instanceof TaskAttachmentMapper)) { @@ -294,7 +217,113 @@ public class TaskAttachmentMapper { if ((other.fileName != null && this.fileName != null) && !other.fileName.equals(this.fileName)) { return false; } + if ((other.replaceExisting != null && this.replaceExisting != null) + && !other.replaceExisting.equals(this.replaceExisting)) { + return false; + } return true; } + public String getAttachmentId() { + return attachmentId; + } + + public IRepositoryPerson getAuthor() { + return author; + } + + public String getComment() { + return comment; + } + + public String getContentType() { + return contentType; + } + + public Date getCreationDate() { + return creationDate; + } + + public String getDescription() { + return description; + } + + public String getFileName() { + return fileName; + } + + public Long getLength() { + return length; + } + + /** + * @since 3.4 + */ + public Boolean getReplaceExisting() { + return replaceExisting; + } + + public String getUrl() { + return url; + } + + public Boolean isDeprecated() { + return deprecated; + } + + public Boolean isPatch() { + return patch; + } + + public void setAttachmentId(String attachmentId) { + this.attachmentId = attachmentId; + } + + public void setAuthor(IRepositoryPerson author) { + this.author = author; + } + + public void setComment(String comment) { + this.comment = comment; + } + + public void setContentType(String contentType) { + this.contentType = contentType; + } + + public void setCreationDate(Date creationDate) { + this.creationDate = creationDate; + } + + public void setDeprecated(Boolean deprecated) { + this.deprecated = deprecated; + } + + public void setDescription(String description) { + this.description = description; + } + + public void setFileName(String fileName) { + this.fileName = fileName; + } + + public void setLength(Long length) { + this.length = length; + } + + public void setPatch(Boolean patch) { + this.patch = patch; + } + + /** + * @since 3.4 + */ + public void setReplaceExisting(Boolean replaceExisting) { + this.replaceExisting = replaceExisting; + } + + public void setUrl(String url) { + this.url = url; + } + } diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java index 55bca70f7..c015bf3f2 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java @@ -49,6 +49,11 @@ public final class TaskAttribute { public static final String ATTACHMENT_IS_PATCH = "task.common.attachment.patch"; //$NON-NLS-1$ + /** + * @since 3.4 + */ + public static final String ATTACHMENT_REPLACE_EXISTING = "task.common.attachment.replaceExisting"; //$NON-NLS-1$ + public static final String ATTACHMENT_SIZE = "task.common.attachment.size"; //$NON-NLS-1$ public static final String ATTACHMENT_URL = "task.common.attachment.url"; //$NON-NLS-1$ diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/UnsubmittedTaskAttachment.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/UnsubmittedTaskAttachment.java new file mode 100644 index 000000000..61640608f --- /dev/null +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/UnsubmittedTaskAttachment.java @@ -0,0 +1,94 @@ +/******************************************************************************* + * Copyright (c) 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 java.io.InputStream; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; + +/** + * @author Steffen Pingel + * @since 3.4 + */ +public class UnsubmittedTaskAttachment { + + private final TaskAttribute attribute; + + private String contentType; + + private String description; + + private String fileName; + + private boolean replaceExisting; + + private final AbstractTaskAttachmentSource source; + + public UnsubmittedTaskAttachment(AbstractTaskAttachmentSource source, TaskAttribute attribute) { + Assert.isNotNull(source); + this.source = source; + this.attribute = attribute; + + contentType = source.getContentType(); + fileName = source.getName(); + description = source.getDescription(); + if (attribute != null) { + TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attribute); + if (mapper.getContentType() != null) { + contentType = mapper.getContentType(); + } + if (mapper.getFileName() != null) { + fileName = mapper.getFileName(); + } + if (mapper.getDescription() != null) { + description = mapper.getDescription(); + } + if (mapper.getReplaceExisting() != null) { + replaceExisting = mapper.getReplaceExisting(); + } + } + if (description == null) { + description = ""; //$NON-NLS-1$ + } + } + + public InputStream createInputStream(IProgressMonitor monitor) throws CoreException { + return source.createInputStream(monitor); + } + + public TaskAttribute getAttribute() { + return attribute; + } + + public String getContentType() { + return contentType; + } + + public String getDescription() { + return description; + } + + public String getFileName() { + return fileName; + } + + public boolean getReplaceExisting() { + return replaceExisting; + } + + public AbstractTaskAttachmentSource getSource() { + return source; + } + +} |