Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 216557
Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/jira/core/JiraTaskAttachmentHandler.java (-13 / +4 lines)
Lines 32-37 Link Here
32
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
32
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
33
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource;
33
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentPartSource;
34
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
34
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
35
import org.eclipse.mylyn.tasks.core.data.UnsubmittedTaskAttachment;
35
36
36
/**
37
/**
37
 * @author Steffen Pingel
38
 * @author Steffen Pingel
Lines 88-109 Link Here
88
		monitor = Policy.monitorFor(monitor);
89
		monitor = Policy.monitorFor(monitor);
89
		try {
90
		try {
90
			monitor.beginTask(Messages.JiraTaskAttachmentHandler_Sending_attachment, IProgressMonitor.UNKNOWN);
91
			monitor.beginTask(Messages.JiraTaskAttachmentHandler_Sending_attachment, IProgressMonitor.UNKNOWN);
91
			String contentType = source.getContentType();
92
			UnsubmittedTaskAttachment attachment = new UnsubmittedTaskAttachment(source, attachmentAttribute);
92
			String filename = source.getName();
93
			if (attachmentAttribute != null) {
94
				TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attachmentAttribute);
95
				if (mapper.getContentType() != null) {
96
					contentType = mapper.getContentType();
97
				}
98
				if (mapper.getFileName() != null) {
99
					filename = mapper.getFileName();
100
				}
101
			}
102
			JiraClient server = JiraClientFactory.getDefault().getJiraClient(repository);
93
			JiraClient server = JiraClientFactory.getDefault().getJiraClient(repository);
103
			try {
94
			try {
104
				JiraIssue issue = server.getIssueByKey(task.getTaskKey(), monitor);
95
				JiraIssue issue = server.getIssueByKey(task.getTaskKey(), monitor);
105
				server.addAttachment(issue, comment, new TaskAttachmentPartSource(source, filename), contentType,
96
				server.addAttachment(issue, comment, new TaskAttachmentPartSource(source, attachment.getFileName()),
106
						monitor);
97
						attachment.getContentType(), monitor);
107
			} catch (JiraException e) {
98
			} catch (JiraException e) {
108
				throw new CoreException(JiraCorePlugin.toStatus(repository, e));
99
				throw new CoreException(JiraCorePlugin.toStatus(repository, e));
109
			}
100
			}
(-)src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java (+3 lines)
Lines 147-152 Link Here
147
	public static final Field ATTACHMENT_IS_PATCH = createField(TaskAttribute.ATTACHMENT_IS_PATCH,
147
	public static final Field ATTACHMENT_IS_PATCH = createField(TaskAttribute.ATTACHMENT_IS_PATCH,
148
			Messages.DefaultTaskSchema_Patch_Label, TaskAttribute.TYPE_BOOLEAN);
148
			Messages.DefaultTaskSchema_Patch_Label, TaskAttribute.TYPE_BOOLEAN);
149
149
150
	public static final Field ATTACHMENT_REPLACE_EXISTING = createField(TaskAttribute.ATTACHMENT_REPLACE_EXISTING,
151
			"Replace existing attachment of the same name", TaskAttribute.TYPE_BOOLEAN);
152
150
	public static final Field ATTACHMENT_SIZE = createField(TaskAttribute.ATTACHMENT_SIZE,
153
	public static final Field ATTACHMENT_SIZE = createField(TaskAttribute.ATTACHMENT_SIZE,
151
			Messages.DefaultTaskSchema_Size_Label, TaskAttribute.TYPE_LONG, Flag.READ_ONLY);
154
			Messages.DefaultTaskSchema_Size_Label, TaskAttribute.TYPE_LONG, Flag.READ_ONLY);
152
155
(-)src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java (-144 / +173 lines)
Lines 24-142 Link Here
24
 */
24
 */
25
public class TaskAttachmentMapper {
25
public class TaskAttachmentMapper {
26
26
27
	private IRepositoryPerson author;
28
29
	private String comment;
30
31
	private String contentType;
32
33
	private Date creationDate;
34
35
	private Boolean deprecated;
36
37
	private String description;
38
39
	private String fileName;
40
41
	private Long length;
42
43
	private Boolean patch;
44
45
	private String url;
46
47
	private String attachmentId;
48
49
	public TaskAttachmentMapper() {
50
	}
51
52
	public String getAttachmentId() {
53
		return attachmentId;
54
	}
55
56
	public IRepositoryPerson getAuthor() {
57
		return author;
58
	}
59
60
	public String getComment() {
61
		return comment;
62
	}
63
64
	public String getContentType() {
65
		return contentType;
66
	}
67
68
	public Date getCreationDate() {
69
		return creationDate;
70
	}
71
72
	public String getDescription() {
73
		return description;
74
	}
75
76
	public String getFileName() {
77
		return fileName;
78
	}
79
80
	public Long getLength() {
81
		return length;
82
	}
83
84
	public String getUrl() {
85
		return url;
86
	}
87
88
	public Boolean isDeprecated() {
89
		return deprecated;
90
	}
91
92
	public Boolean isPatch() {
93
		return patch;
94
	}
95
96
	public void setAttachmentId(String attachmentId) {
97
		this.attachmentId = attachmentId;
98
	}
99
100
	public void setAuthor(IRepositoryPerson author) {
101
		this.author = author;
102
	}
103
104
	public void setComment(String comment) {
105
		this.comment = comment;
106
	}
107
108
	public void setContentType(String contentType) {
109
		this.contentType = contentType;
110
	}
111
112
	public void setCreationDate(Date creationDate) {
113
		this.creationDate = creationDate;
114
	}
115
116
	public void setDeprecated(Boolean deprecated) {
117
		this.deprecated = deprecated;
118
	}
119
120
	public void setDescription(String description) {
121
		this.description = description;
122
	}
123
124
	public void setFileName(String fileName) {
125
		this.fileName = fileName;
126
	}
127
128
	public void setLength(Long length) {
129
		this.length = length;
130
	}
131
132
	public void setPatch(Boolean patch) {
133
		this.patch = patch;
134
	}
135
136
	public void setUrl(String url) {
137
		this.url = url;
138
	}
139
140
	public static TaskAttachmentMapper createFrom(TaskAttribute taskAttribute) {
27
	public static TaskAttachmentMapper createFrom(TaskAttribute taskAttribute) {
141
		Assert.isNotNull(taskAttribute);
28
		Assert.isNotNull(taskAttribute);
142
		TaskAttributeMapper mapper = taskAttribute.getTaskData().getAttributeMapper();
29
		TaskAttributeMapper mapper = taskAttribute.getTaskData().getAttributeMapper();
Lines 170-175 Link Here
170
		if (child != null) {
57
		if (child != null) {
171
			attachment.setPatch(mapper.getBooleanValue(child));
58
			attachment.setPatch(mapper.getBooleanValue(child));
172
		}
59
		}
60
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_REPLACE_EXISTING);
61
		if (child != null) {
62
			attachment.setReplaceExisting(mapper.getBooleanValue(child));
63
		}
173
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
64
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
174
		if (child != null) {
65
		if (child != null) {
175
			Long value = mapper.getLongValue(child);
66
			Long value = mapper.getLongValue(child);
Lines 184-189 Link Here
184
		return attachment;
75
		return attachment;
185
	}
76
	}
186
77
78
	private String attachmentId;
79
80
	private IRepositoryPerson author;
81
82
	private String comment;
83
84
	private String contentType;
85
86
	private Date creationDate;
87
88
	private Boolean deprecated;
89
90
	private String description;
91
92
	private String fileName;
93
94
	private Long length;
95
96
	private Boolean patch;
97
98
	private Boolean replaceExisting;
99
100
	private String url;
101
102
	public TaskAttachmentMapper() {
103
	}
104
105
	public void applyTo(ITaskAttachment taskAttachment) {
106
		Assert.isNotNull(taskAttachment);
107
		if (getAuthor() != null) {
108
			taskAttachment.setAuthor(getAuthor());
109
		}
110
		if (getContentType() != null) {
111
			taskAttachment.setContentType(getContentType());
112
		}
113
		if (getCreationDate() != null) {
114
			taskAttachment.setCreationDate(getCreationDate());
115
		}
116
		if (getDescription() != null) {
117
			taskAttachment.setDescription(getDescription());
118
		}
119
		if (getFileName() != null) {
120
			taskAttachment.setFileName(getFileName());
121
		}
122
		if (isDeprecated() != null) {
123
			taskAttachment.setDeprecated(isDeprecated());
124
		}
125
		if (isPatch() != null) {
126
			taskAttachment.setPatch(isPatch());
127
		}
128
		if (getLength() != null) {
129
			taskAttachment.setLength(getLength());
130
		}
131
		if (url != null) {
132
			taskAttachment.setUrl(getUrl());
133
		}
134
	}
135
187
	public void applyTo(TaskAttribute taskAttribute) {
136
	public void applyTo(TaskAttribute taskAttribute) {
188
		Assert.isNotNull(taskAttribute);
137
		Assert.isNotNull(taskAttribute);
189
		TaskData taskData = taskAttribute.getTaskData();
138
		TaskData taskData = taskAttribute.getTaskData();
Lines 217-222 Link Here
217
					taskAttribute);
166
					taskAttribute);
218
			mapper.setValue(child, getFileName());
167
			mapper.setValue(child, getFileName());
219
		}
168
		}
169
		if (getReplaceExisting() != null) {
170
			TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_REPLACE_EXISTING)
171
					.createAttribute(taskAttribute);
172
			mapper.setBooleanValue(child, getReplaceExisting());
173
		}
220
		if (isDeprecated() != null) {
174
		if (isDeprecated() != null) {
221
			TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_IS_DEPRECATED).createAttribute(
175
			TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_IS_DEPRECATED).createAttribute(
222
					taskAttribute);
176
					taskAttribute);
Lines 239-275 Link Here
239
		}
193
		}
240
	}
194
	}
241
195
242
	public void applyTo(ITaskAttachment taskAttachment) {
243
		Assert.isNotNull(taskAttachment);
244
		if (getAuthor() != null) {
245
			taskAttachment.setAuthor(getAuthor());
246
		}
247
		if (getContentType() != null) {
248
			taskAttachment.setContentType(getContentType());
249
		}
250
		if (getCreationDate() != null) {
251
			taskAttachment.setCreationDate(getCreationDate());
252
		}
253
		if (getDescription() != null) {
254
			taskAttachment.setDescription(getDescription());
255
		}
256
		if (getFileName() != null) {
257
			taskAttachment.setFileName(getFileName());
258
		}
259
		if (isDeprecated() != null) {
260
			taskAttachment.setDeprecated(isDeprecated());
261
		}
262
		if (isPatch() != null) {
263
			taskAttachment.setPatch(isPatch());
264
		}
265
		if (getLength() != null) {
266
			taskAttachment.setLength(getLength());
267
		}
268
		if (url != null) {
269
			taskAttachment.setUrl(getUrl());
270
		}
271
	}
272
273
	@Override
196
	@Override
274
	public boolean equals(Object obj) {
197
	public boolean equals(Object obj) {
275
		if (!(obj instanceof TaskAttachmentMapper)) {
198
		if (!(obj instanceof TaskAttachmentMapper)) {
Lines 294-300 Link Here
294
		if ((other.fileName != null && this.fileName != null) && !other.fileName.equals(this.fileName)) {
217
		if ((other.fileName != null && this.fileName != null) && !other.fileName.equals(this.fileName)) {
295
			return false;
218
			return false;
296
		}
219
		}
220
		if ((other.replaceExisting != null && this.replaceExisting != null)
221
				&& !other.replaceExisting.equals(this.replaceExisting)) {
222
			return false;
223
		}
297
		return true;
224
		return true;
298
	}
225
	}
299
226
227
	public String getAttachmentId() {
228
		return attachmentId;
229
	}
230
231
	public IRepositoryPerson getAuthor() {
232
		return author;
233
	}
234
235
	public String getComment() {
236
		return comment;
237
	}
238
239
	public String getContentType() {
240
		return contentType;
241
	}
242
243
	public Date getCreationDate() {
244
		return creationDate;
245
	}
246
247
	public String getDescription() {
248
		return description;
249
	}
250
251
	public String getFileName() {
252
		return fileName;
253
	}
254
255
	public Long getLength() {
256
		return length;
257
	}
258
259
	/**
260
	 * @since 3.4
261
	 */
262
	public Boolean getReplaceExisting() {
263
		return replaceExisting;
264
	}
265
266
	public String getUrl() {
267
		return url;
268
	}
269
270
	public Boolean isDeprecated() {
271
		return deprecated;
272
	}
273
274
	public Boolean isPatch() {
275
		return patch;
276
	}
277
278
	public void setAttachmentId(String attachmentId) {
279
		this.attachmentId = attachmentId;
280
	}
281
282
	public void setAuthor(IRepositoryPerson author) {
283
		this.author = author;
284
	}
285
286
	public void setComment(String comment) {
287
		this.comment = comment;
288
	}
289
290
	public void setContentType(String contentType) {
291
		this.contentType = contentType;
292
	}
293
294
	public void setCreationDate(Date creationDate) {
295
		this.creationDate = creationDate;
296
	}
297
298
	public void setDeprecated(Boolean deprecated) {
299
		this.deprecated = deprecated;
300
	}
301
302
	public void setDescription(String description) {
303
		this.description = description;
304
	}
305
306
	public void setFileName(String fileName) {
307
		this.fileName = fileName;
308
	}
309
310
	public void setLength(Long length) {
311
		this.length = length;
312
	}
313
314
	public void setPatch(Boolean patch) {
315
		this.patch = patch;
316
	}
317
318
	/**
319
	 * @since 3.4
320
	 */
321
	public void setReplaceExisting(Boolean replaceExisting) {
322
		this.replaceExisting = replaceExisting;
323
	}
324
325
	public void setUrl(String url) {
326
		this.url = url;
327
	}
328
300
}
329
}
(-)src/org/eclipse/mylyn/tasks/core/data/TaskAttribute.java (+2 lines)
Lines 49-54 Link Here
49
49
50
	public static final String ATTACHMENT_IS_PATCH = "task.common.attachment.patch"; //$NON-NLS-1$
50
	public static final String ATTACHMENT_IS_PATCH = "task.common.attachment.patch"; //$NON-NLS-1$
51
51
52
	public static final String ATTACHMENT_REPLACE_EXISTING = "task.common.attachment.replaceExisting"; //$NON-NLS-1$
53
52
	public static final String ATTACHMENT_SIZE = "task.common.attachment.size"; //$NON-NLS-1$
54
	public static final String ATTACHMENT_SIZE = "task.common.attachment.size"; //$NON-NLS-1$
53
55
54
	public static final String ATTACHMENT_URL = "task.common.attachment.url"; //$NON-NLS-1$
56
	public static final String ATTACHMENT_URL = "task.common.attachment.url"; //$NON-NLS-1$
(-)src/org/eclipse/mylyn/tasks/core/data/UnsubmittedTaskAttachment.java (+90 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Tasktop Technologies and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Tasktop Technologies - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylyn.tasks.core.data;
13
14
import java.io.InputStream;
15
16
import org.eclipse.core.runtime.Assert;
17
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.IProgressMonitor;
19
20
/**
21
 * @author Steffen Pingel
22
 * @since 3.4
23
 */
24
public class UnsubmittedTaskAttachment {
25
26
	private final TaskAttribute attribute;
27
28
	private String contentType;
29
30
	private String description;
31
32
	private String fileName;
33
34
	private boolean replaceExisting;
35
36
	private final AbstractTaskAttachmentSource source;
37
38
	public UnsubmittedTaskAttachment(AbstractTaskAttachmentSource source, TaskAttribute attribute) {
39
		Assert.isNotNull(source);
40
		this.source = source;
41
		this.attribute = attribute;
42
43
		contentType = source.getContentType();
44
		fileName = source.getName();
45
		description = source.getDescription();
46
		if (attribute != null) {
47
			TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attribute);
48
			if (mapper.getContentType() != null) {
49
				contentType = mapper.getContentType();
50
			}
51
			if (mapper.getFileName() != null) {
52
				fileName = mapper.getFileName();
53
			}
54
			if (mapper.getDescription() != null) {
55
				description = mapper.getDescription();
56
			}
57
			if (mapper.getReplaceExisting() != null) {
58
				replaceExisting = mapper.getReplaceExisting();
59
			}
60
		}
61
		if (description == null) {
62
			description = ""; //$NON-NLS-1$
63
		}
64
	}
65
66
	public InputStream createInputStream(IProgressMonitor monitor) throws CoreException {
67
		return source.createInputStream(monitor);
68
	}
69
70
	public String getContentType() {
71
		return contentType;
72
	}
73
74
	public String getDescription() {
75
		return description;
76
	}
77
78
	public String getFileName() {
79
		return fileName;
80
	}
81
82
	public boolean getReplaceExisting() {
83
		return replaceExisting;
84
	}
85
86
	public AbstractTaskAttachmentSource getSource() {
87
		return source;
88
	}
89
90
}
(-)src/org/eclipse/mylyn/tasks/ui/wizards/TaskAttachmentPage.java (-1 / +56 lines)
Lines 80-85 Link Here
80
80
81
	private CommonTextSupport textSupport;
81
	private CommonTextSupport textSupport;
82
82
83
	private boolean needsReplaceExisting;
84
85
	private Button replaceExistingButton;
86
83
	public TaskAttachmentPage(TaskAttachmentModel model) {
87
	public TaskAttachmentPage(TaskAttachmentModel model) {
84
		super("AttachmentDetails"); //$NON-NLS-1$
88
		super("AttachmentDetails"); //$NON-NLS-1$
85
		this.model = model;
89
		this.model = model;
Lines 102-107 Link Here
102
		fileNameText = new Text(composite, SWT.BORDER);
106
		fileNameText = new Text(composite, SWT.BORDER);
103
		fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
107
		fileNameText.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1));
104
108
109
		if (needsReplaceExisting) {
110
			new Label(composite, SWT.NONE);
111
			replaceExistingButton = new Button(composite, SWT.CHECK);
112
			replaceExistingButton.setLayoutData(new GridData(SWT.DEFAULT, SWT.DEFAULT, false, false, 2, 1));
113
			replaceExistingButton.setText("Replace existing attachment of the same name");
114
			replaceExistingButton.addSelectionListener(new SelectionAdapter() {
115
				@Override
116
				public void widgetSelected(SelectionEvent e) {
117
					taskAttachment.setReplaceExisting(replaceExistingButton.getSelection());
118
					validate();
119
				}
120
			});
121
		}
122
105
		if (needsDescription) {
123
		if (needsDescription) {
106
			new Label(composite, SWT.NONE).setText(Messages.TaskAttachmentPage_Description);
124
			new Label(composite, SWT.NONE).setText(Messages.TaskAttachmentPage_Description);
107
			descriptionText = new Text(composite, SWT.BORDER);
125
			descriptionText = new Text(composite, SWT.BORDER);
Lines 111-117 Link Here
111
					taskAttachment.setDescription(descriptionText.getText().trim());
129
					taskAttachment.setDescription(descriptionText.getText().trim());
112
					validate();
130
					validate();
113
				}
131
				}
114
115
			});
132
			});
116
		}
133
		}
117
134
Lines 302-308 Link Here
302
		this.needsDescription = supportsDescription;
319
		this.needsDescription = supportsDescription;
303
	}
320
	}
304
321
322
	/**
323
	 * @deprecated Use {@link #needsDescription()} instead
324
	 */
325
	@Deprecated
305
	public boolean supportsDescription() {
326
	public boolean supportsDescription() {
327
		return needsDescription();
328
	}
329
330
	/**
331
	 * Returns true if the page has a description field.
332
	 * 
333
	 * @since 3.4
334
	 * @see #setDescription(String)
335
	 */
336
	public boolean needsDescription() {
306
		return needsDescription;
337
		return needsDescription;
307
	}
338
	}
308
339
Lines 338-341 Link Here
338
		}
369
		}
339
	}
370
	}
340
371
372
	/**
373
	 * Set to true if the page needs a check box for replacing existing attachments. Must be called before the page is
374
	 * constructed, it has no effect otherwise.
375
	 * <p>
376
	 * This flag is set to false by default.
377
	 * </p>
378
	 * 
379
	 * @since 3.4
380
	 * @see #needsReplaceExisting()
381
	 */
382
	public void setNeedsReplaceExisting(boolean needsReplaceExisting) {
383
		this.needsReplaceExisting = needsReplaceExisting;
384
	}
385
386
	/**
387
	 * Returns true, if the page has a check box to replace existing attachments.
388
	 * 
389
	 * @since 3.4
390
	 * @see #setNeedsReplaceExisting(boolean)
391
	 */
392
	public boolean needsReplaceExisting() {
393
		return needsReplaceExisting;
394
	}
395
341
}
396
}
(-)src/org/eclipse/mylyn/internal/trac/core/TracAttachmentHandler.java (-16 / +4 lines)
Lines 27-32 Link Here
27
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
27
import org.eclipse.mylyn.tasks.core.data.AbstractTaskAttachmentSource;
28
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
28
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
29
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
29
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
30
import org.eclipse.mylyn.tasks.core.data.UnsubmittedTaskAttachment;
30
31
31
/**
32
/**
32
 * @author Steffen Pingel
33
 * @author Steffen Pingel
Lines 70-97 Link Here
70
					"Attachments are not supported by this repository access type")); //$NON-NLS-1$
71
					"Attachments are not supported by this repository access type")); //$NON-NLS-1$
71
		}
72
		}
72
73
73
		String filename = source.getName();
74
		UnsubmittedTaskAttachment attachment = new UnsubmittedTaskAttachment(source, attachmentAttribute);
74
		String description = source.getDescription();
75
		if (attachmentAttribute != null) {
76
			TaskAttachmentMapper mapper = TaskAttachmentMapper.createFrom(attachmentAttribute);
77
			if (mapper.getFileName() != null) {
78
				filename = mapper.getFileName();
79
			}
80
			if (mapper.getDescription() != null) {
81
				description = mapper.getDescription();
82
			}
83
		}
84
		if (description == null) {
85
			description = ""; //$NON-NLS-1$
86
		}
87
88
		monitor = Policy.monitorFor(monitor);
75
		monitor = Policy.monitorFor(monitor);
89
		try {
76
		try {
90
			monitor.beginTask(Messages.TracAttachmentHandler_Uploading_attachment, IProgressMonitor.UNKNOWN);
77
			monitor.beginTask(Messages.TracAttachmentHandler_Uploading_attachment, IProgressMonitor.UNKNOWN);
91
			try {
78
			try {
92
				ITracClient client = connector.getClientManager().getTracClient(repository);
79
				ITracClient client = connector.getClientManager().getTracClient(repository);
93
				int id = Integer.parseInt(task.getTaskId());
80
				int id = Integer.parseInt(task.getTaskId());
94
				client.putAttachmentData(id, filename, description, source.createInputStream(monitor), monitor);
81
				client.putAttachmentData(id, attachment.getFileName(), attachment.getDescription(),
82
						attachment.createInputStream(monitor), monitor, attachment.getReplaceExisting());
95
				if (comment != null && comment.length() > 0) {
83
				if (comment != null && comment.length() > 0) {
96
					TracTicket ticket = new TracTicket(id);
84
					TracTicket ticket = new TracTicket(id);
97
					client.updateTicket(ticket, comment, monitor);
85
					client.updateTicket(ticket, comment, monitor);
(-)src/org/eclipse/mylyn/internal/trac/core/client/ITracClient.java (-1 / +1 lines)
Lines 188-194 Link Here
188
188
189
	InputStream getAttachmentData(int ticketId, String filename, IProgressMonitor monitor) throws TracException;
189
	InputStream getAttachmentData(int ticketId, String filename, IProgressMonitor monitor) throws TracException;
190
190
191
	void putAttachmentData(int ticketId, String name, String description, InputStream source, IProgressMonitor monitor)
191
	void putAttachmentData(int ticketId, String name, String description, InputStream source, IProgressMonitor monitor, boolean replace)
192
			throws TracException;
192
			throws TracException;
193
193
194
	void deleteAttachment(int ticketId, String filename, IProgressMonitor monitor) throws TracException;
194
	void deleteAttachment(int ticketId, String filename, IProgressMonitor monitor) throws TracException;
(-)src/org/eclipse/mylyn/internal/trac/core/client/TracWebClient.java (-1 / +1 lines)
Lines 738-744 Link Here
738
		}
738
		}
739
	}
739
	}
740
740
741
	public void putAttachmentData(int id, String name, String description, InputStream in, IProgressMonitor monitor)
741
	public void putAttachmentData(int id, String name, String description, InputStream in, IProgressMonitor monitor, boolean replace)
742
			throws TracException {
742
			throws TracException {
743
		throw new TracException("Unsupported operation"); //$NON-NLS-1$
743
		throw new TracException("Unsupported operation"); //$NON-NLS-1$
744
	}
744
	}
(-)src/org/eclipse/mylyn/internal/trac/core/client/TracXmlRpcClient.java (-2 / +2 lines)
Lines 820-833 Link Here
820
	}
820
	}
821
821
822
	public void putAttachmentData(int ticketId, String filename, String description, InputStream in,
822
	public void putAttachmentData(int ticketId, String filename, String description, InputStream in,
823
			IProgressMonitor monitor) throws TracException {
823
			IProgressMonitor monitor, boolean replace) throws TracException {
824
		byte[] data;
824
		byte[] data;
825
		try {
825
		try {
826
			data = readData(in, new NullProgressMonitor());
826
			data = readData(in, new NullProgressMonitor());
827
		} catch (IOException e) {
827
		} catch (IOException e) {
828
			throw new TracException(e);
828
			throw new TracException(e);
829
		}
829
		}
830
		call(monitor, "ticket.putAttachment", ticketId, filename, description, data, false); //$NON-NLS-1$
830
		call(monitor, "ticket.putAttachment", ticketId, filename, description, data, replace); //$NON-NLS-1$
831
	}
831
	}
832
832
833
	private byte[] readData(InputStream in, IProgressMonitor monitor) throws IOException {
833
	private byte[] readData(InputStream in, IProgressMonitor monitor) throws IOException {
(-)src/org/eclipse/mylyn/internal/trac/ui/TracConnectorUi.java (+11 lines)
Lines 18-23 Link Here
18
import org.eclipse.jface.text.hyperlink.IHyperlink;
18
import org.eclipse.jface.text.hyperlink.IHyperlink;
19
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.jface.viewers.IStructuredSelection;
20
import org.eclipse.jface.wizard.IWizard;
20
import org.eclipse.jface.wizard.IWizard;
21
import org.eclipse.jface.wizard.IWizardPage;
21
import org.eclipse.mylyn.internal.trac.core.TracCorePlugin;
22
import org.eclipse.mylyn.internal.trac.core.TracCorePlugin;
22
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
23
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector;
23
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector.TaskKind;
24
import org.eclipse.mylyn.internal.trac.core.TracRepositoryConnector.TaskKind;
Lines 29-34 Link Here
29
import org.eclipse.mylyn.tasks.core.ITaskComment;
30
import org.eclipse.mylyn.tasks.core.ITaskComment;
30
import org.eclipse.mylyn.tasks.core.ITaskMapping;
31
import org.eclipse.mylyn.tasks.core.ITaskMapping;
31
import org.eclipse.mylyn.tasks.core.TaskRepository;
32
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentModel;
32
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
34
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
33
import org.eclipse.mylyn.tasks.ui.LegendElement;
35
import org.eclipse.mylyn.tasks.ui.LegendElement;
34
import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage;
36
import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage;
Lines 36-41 Link Here
36
import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard;
38
import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard;
37
import org.eclipse.mylyn.tasks.ui.wizards.NewWebTaskWizard;
39
import org.eclipse.mylyn.tasks.ui.wizards.NewWebTaskWizard;
38
import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard;
40
import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard;
41
import org.eclipse.mylyn.tasks.ui.wizards.TaskAttachmentPage;
39
import org.eclipse.osgi.util.NLS;
42
import org.eclipse.osgi.util.NLS;
40
43
41
/**
44
/**
Lines 130-133 Link Here
130
					taskComment.getAuthor().getPersonId());
133
					taskComment.getAuthor().getPersonId());
131
		}
134
		}
132
	}
135
	}
136
137
	@Override
138
	public IWizardPage getTaskAttachmentPage(TaskAttachmentModel model) {
139
		TaskAttachmentPage page = new TaskAttachmentPage(model);
140
		page.setNeedsReplaceExisting(true);
141
		return page;
142
	}
143
133
}
144
}

Return to bug 216557