View | Details | Raw Unified | Return to bug 272207 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/bugzilla/core/RepositoryConfiguration.java (+97 lines)
Lines 369-374 Link Here
369
			addMissingFlags(taskData);
369
			addMissingFlags(taskData);
370
			updateAttributeOptions(taskData);
370
			updateAttributeOptions(taskData);
371
			addValidOperations(taskData);
371
			addValidOperations(taskData);
372
			addMissingAttachmentFlags(taskData);
373
			updateAttachmentOptions(taskData);
372
		}
374
		}
373
	}
375
	}
374
376
Lines 697-700 Link Here
697
		}
699
		}
698
		return null;
700
		return null;
699
	}
701
	}
702
703
	public void updateAttachmentOptions(TaskData existingReport) {
704
		for (TaskAttribute attribute : new HashSet<TaskAttribute>(existingReport.getRoot().getAttributes().values())) {
705
706
			if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$
707
				continue;
708
			}
709
710
			for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) {
711
				if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
712
					continue;
713
				}
714
715
				TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$
716
				attachmentAttribute.clearOptions();
717
718
				String nameValue = state.getMetaData().getLabel();
719
				state.putOption("", ""); //$NON-NLS-1$ //$NON-NLS-2$
720
				for (BugzillaFlag bugzillaFlag : flags) {
721
					if (nameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
722
						if ("attachment".equals(bugzillaFlag.getType())) { //$NON-NLS-1$
723
							if (bugzillaFlag.isRequestable()) {
724
								state.putOption("?", "?"); //$NON-NLS-1$ //$NON-NLS-2$
725
							}
726
							break;
727
						}
728
					}
729
				}
730
				state.putOption("-", "-"); //$NON-NLS-1$ //$NON-NLS-2$
731
				state.putOption("+", "+"); //$NON-NLS-1$ //$NON-NLS-2$
732
				String flagNameValue = state.getMetaData().getLabel();
733
				for (BugzillaFlag bugzillaFlag : flags) {
734
					if (flagNameValue.equals(bugzillaFlag.getName()) && bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
735
						TaskAttribute requestee = attachmentAttribute.getAttribute("requestee"); //$NON-NLS-1$
736
						if (requestee == null) {
737
							requestee = attachmentAttribute.createMappedAttribute("requestee"); //$NON-NLS-1$
738
							requestee.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
739
							requestee.setValue(""); //$NON-NLS-1$
740
						}
741
						requestee.getMetaData().setReadOnly(!bugzillaFlag.isSpecifically_requestable());
742
					}
743
				}
744
745
			}
746
		}
747
	}
748
749
	private void addMissingAttachmentFlags(TaskData taskData) {
750
		List<String> existingFlags = new ArrayList<String>();
751
		List<BugzillaFlag> flags = getFlags();
752
		for (TaskAttribute attribute : new HashSet<TaskAttribute>(taskData.getRoot().getAttributes().values())) {
753
754
			if (!attribute.getId().startsWith("task.common.attachment")) { //$NON-NLS-1$
755
				continue;
756
			}
757
			existingFlags.clear();
758
			for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) {
759
				if (!attachmentAttribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
760
					continue;
761
				}
762
				TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$
763
				if (state != null) {
764
					String nameValue = state.getMetaData().getLabel();
765
					if (!existingFlags.contains(nameValue)) {
766
						existingFlags.add(nameValue);
767
					}
768
				}
769
			}
770
			TaskAttribute productAttribute = taskData.getRoot().getMappedAttribute(BugzillaAttribute.PRODUCT.getKey());
771
			TaskAttribute componentAttribute = taskData.getRoot().getMappedAttribute(
772
					BugzillaAttribute.COMPONENT.getKey());
773
			for (BugzillaFlag bugzillaFlag : flags) {
774
				if (!bugzillaFlag.getType().equals("attachment")) { //$NON-NLS-1$
775
					continue;
776
				}
777
				if (!bugzillaFlag.isUsedIn(productAttribute.getValue(), componentAttribute.getValue())) {
778
					continue;
779
				}
780
				if (existingFlags.contains(bugzillaFlag.getName()) && !bugzillaFlag.isMultiplicable()) {
781
					continue;
782
				}
783
				BugzillaFlagMapper mapper = new BugzillaFlagMapper();
784
				mapper.setRequestee(""); //$NON-NLS-1$
785
				mapper.setSetter(""); //$NON-NLS-1$
786
				mapper.setState(" "); //$NON-NLS-1$
787
				mapper.setFlagId(bugzillaFlag.getName());
788
				mapper.setNumber(0);
789
				mapper.setDescription(bugzillaFlag.getDescription());
790
				TaskAttribute newattribute = attribute.createAttribute("task.common.kind.flag_type" + bugzillaFlag.getFlagId()); //$NON-NLS-1$
791
				mapper.applyTo(newattribute);
792
			}
793
		}
794
795
	}
796
700
}
797
}
(-)src/org/eclipse/mylyn/internal/bugzilla/core/messages.properties (+10 lines)
Lines 1-3 Link Here
1
BugzillaAttachmentMapper_Author=Attachment Author:
2
BugzillaAttachmentMapper_Content_Type=Content Type:
3
BugzillaAttachmentMapper_Creation_Date=Creation Date:
4
BugzillaAttachmentMapper_Description=Description:
5
BugzillaAttachmentMapper_Filename=Filename:
6
BugzillaAttachmentMapper_obsolate=obsolete
7
BugzillaAttachmentMapper_patch=patch
8
BugzillaAttachmentMapper_Size=Size in Bytes:
9
BugzillaAttachmentMapper_Token=Token:
10
BugzillaAttachmentMapper_URL=URL:
1
BugzillaAttribute_Add=Add:
11
BugzillaAttribute_Add=Add:
2
BugzillaAttribute_Add_CC=Add CC:
12
BugzillaAttribute_Add_CC=Add CC:
3
BugzillaAttribute_Add_self_to_CC=Add self to CC
13
BugzillaAttribute_Add_self_to_CC=Add self to CC
(-)src/org/eclipse/mylyn/internal/bugzilla/core/SaxMultiBugReportContentHandler.java (-4 / +20 lines)
Lines 18-24 Link Here
18
import java.util.Map;
18
import java.util.Map;
19
19
20
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
20
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
22
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
23
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
22
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
24
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
23
import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
Lines 50-56 Link Here
50
49
51
	private int commentNum = 0;
50
	private int commentNum = 0;
52
51
53
	private TaskAttachmentMapper attachment;
52
	private BugzillaAttachmentMapper attachment;
54
53
55
	private final Map<String, TaskData> taskDataMap;
54
	private final Map<String, TaskData> taskDataMap;
56
55
Lines 68-73 Link Here
68
67
69
	private boolean isPatch = false;
68
	private boolean isPatch = false;
70
69
70
	private String token;
71
71
	private TaskAttribute attachmentAttribute;
72
	private TaskAttribute attachmentAttribute;
72
73
73
	public SaxMultiBugReportContentHandler(TaskAttributeMapper mapper, TaskDataCollector collector,
74
	public SaxMultiBugReportContentHandler(TaskAttributeMapper mapper, TaskDataCollector collector,
Lines 119-124 Link Here
119
			commentNum = 0;
120
			commentNum = 0;
120
			taskComment = null;
121
			taskComment = null;
121
			longDescs = new ArrayList<TaskComment>();
122
			longDescs = new ArrayList<TaskComment>();
123
			token = null;
122
			break;
124
			break;
123
		case LONG_DESC:
125
		case LONG_DESC:
124
			taskComment = new TaskComment(commentNum++);
126
			taskComment = new TaskComment(commentNum++);
Lines 325-335 Link Here
325
		case ATTACHID:
327
		case ATTACHID:
326
			attachmentAttribute = repositoryTaskData.getRoot().createAttribute(
328
			attachmentAttribute = repositoryTaskData.getRoot().createAttribute(
327
					TaskAttribute.PREFIX_ATTACHMENT + parsedText);
329
					TaskAttribute.PREFIX_ATTACHMENT + parsedText);
328
			attachment = TaskAttachmentMapper.createFrom(attachmentAttribute);
330
			attachment = BugzillaAttachmentMapper.createFrom(attachmentAttribute);
329
			attachment.setLength(new Long(-1));
331
			attachment.setLength(new Long(-1));
330
			attachment.setAttachmentId(parsedText);
332
			attachment.setAttachmentId(parsedText);
331
			attachment.setPatch(isPatch);
333
			attachment.setPatch(isPatch);
332
			attachment.setDeprecated(isDeprecated);
334
			attachment.setDeprecated(isDeprecated);
335
			attachment.setToken(null);
333
			break;
336
			break;
334
		case DATE:
337
		case DATE:
335
			// ignore
338
			// ignore
Lines 397-402 Link Here
397
400
398
			updateCustomFields(repositoryTaskData);
401
			updateCustomFields(repositoryTaskData);
399
402
403
			if (token != null) {
404
				TaskAttribute tokenAttribute = BugzillaTaskDataHandler.createAttribute(repositoryTaskData,
405
						BugzillaAttribute.TOKEN);
406
				tokenAttribute.setValue(token);
407
			}
408
400
			// Guard against empty data sets
409
			// Guard against empty data sets
401
			if (attrCreation != null && !attrCreation.equals("")) { //$NON-NLS-1$
410
			if (attrCreation != null && !attrCreation.equals("")) { //$NON-NLS-1$
402
				collector.accept(repositoryTaskData);
411
				collector.accept(repositoryTaskData);
Lines 422-427 Link Here
422
		case FLAG:
431
		case FLAG:
423
			//ignore
432
			//ignore
424
			break;
433
			break;
434
		case TOKEN:
435
			if (attachment != null) {
436
				attachment.setToken(parsedText);
437
			} else {
438
				token = parsedText;
439
			}
440
			break;
425
		default:
441
		default:
426
			TaskAttribute defaultAttribute = repositoryTaskData.getRoot().getMappedAttribute(tag.getKey());
442
			TaskAttribute defaultAttribute = repositoryTaskData.getRoot().getMappedAttribute(tag.getKey());
427
			if (defaultAttribute == null) {
443
			if (defaultAttribute == null) {
Lines 485-491 Link Here
485
		List<TaskAttribute> taskAttachments = repositoryTaskData.getAttributeMapper().getAttributesByType(
501
		List<TaskAttribute> taskAttachments = repositoryTaskData.getAttributeMapper().getAttributesByType(
486
				repositoryTaskData, TaskAttribute.TYPE_ATTACHMENT);
502
				repositoryTaskData, TaskAttribute.TYPE_ATTACHMENT);
487
		for (TaskAttribute attachment : taskAttachments) {
503
		for (TaskAttribute attachment : taskAttachments) {
488
			TaskAttachmentMapper attachmentMapper = TaskAttachmentMapper.createFrom(attachment);
504
			BugzillaAttachmentMapper attachmentMapper = BugzillaAttachmentMapper.createFrom(attachment);
489
			TaskCommentMapper taskComment = attachIdToComment.get(attachmentMapper.getAttachmentId());
505
			TaskCommentMapper taskComment = attachIdToComment.get(attachmentMapper.getAttachmentId());
490
			if (taskComment != null) {
506
			if (taskComment != null) {
491
				attachmentMapper.setAuthor(taskComment.getAuthor());
507
				attachmentMapper.setAuthor(taskComment.getAuthor());
(-)src/org/eclipse/mylyn/internal/bugzilla/core/Messages.java (+20 lines)
Lines 25-30 Link Here
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
	}
26
	}
27
27
28
	public static String BugzillaAttachmentMapper_Author;
29
30
	public static String BugzillaAttachmentMapper_Content_Type;
31
32
	public static String BugzillaAttachmentMapper_Creation_Date;
33
34
	public static String BugzillaAttachmentMapper_Description;
35
36
	public static String BugzillaAttachmentMapper_Filename;
37
38
	public static String BugzillaAttachmentMapper_obsolate;
39
40
	public static String BugzillaAttachmentMapper_patch;
41
42
	public static String BugzillaAttachmentMapper_Size;
43
44
	public static String BugzillaAttachmentMapper_Token;
45
46
	public static String BugzillaAttachmentMapper_URL;
47
28
	public static String BugzillaAttribute_Add;
48
	public static String BugzillaAttribute_Add;
29
49
30
	public static String BugzillaAttribute_Add_CC;
50
	public static String BugzillaAttribute_Add_CC;
(-)src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttachmentMapper.java (+164 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 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.internal.bugzilla.core;
13
14
import org.eclipse.core.runtime.Assert;
15
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
16
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
17
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
18
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
19
import org.eclipse.mylyn.tasks.core.data.TaskData;
20
21
public class BugzillaAttachmentMapper extends TaskAttachmentMapper {
22
	private String token;
23
24
	public String getToken() {
25
		return token;
26
	}
27
28
	public void setToken(String token) {
29
		this.token = token;
30
	}
31
32
	@Override
33
	public void applyTo(TaskAttribute taskAttribute) {
34
		Assert.isNotNull(taskAttribute);
35
		TaskData taskData = taskAttribute.getTaskData();
36
		TaskAttributeMapper mapper = taskData.getAttributeMapper();
37
		taskAttribute.getMetaData().defaults().setType(TaskAttribute.TYPE_ATTACHMENT);
38
		if (getAttachmentId() != null) {
39
			mapper.setValue(taskAttribute, getAttachmentId());
40
		}
41
		if (getAuthor() != null) {
42
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_AUTHOR);
43
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
44
			defaults.setType(TaskAttribute.TYPE_PERSON);
45
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Author);
46
			mapper.setRepositoryPerson(child, getAuthor());
47
		}
48
		if (getContentType() != null) {
49
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE);
50
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
51
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
52
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Content_Type);
53
			mapper.setValue(child, getContentType());
54
		}
55
		if (getCreationDate() != null) {
56
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DATE);
57
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
58
			defaults.setType(TaskAttribute.TYPE_DATE);
59
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Creation_Date);
60
			mapper.setDateValue(child, getCreationDate());
61
		}
62
		if (getDescription() != null) {
63
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION);
64
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
65
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
66
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Description);
67
			mapper.setValue(child, getDescription());
68
		}
69
		if (getFileName() != null) {
70
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME);
71
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
72
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
73
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Filename);
74
			mapper.setValue(child, getFileName());
75
		}
76
		if (isDeprecated() != null) {
77
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
78
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
79
			defaults.setType(TaskAttribute.TYPE_BOOLEAN);
80
			defaults.setLabel(Messages.BugzillaAttachmentMapper_obsolate);
81
			mapper.setBooleanValue(child, isDeprecated());
82
		}
83
		if (isPatch() != null) {
84
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
85
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
86
			defaults.setType(TaskAttribute.TYPE_BOOLEAN);
87
			defaults.setLabel(Messages.BugzillaAttachmentMapper_patch);
88
			mapper.setBooleanValue(child, isPatch());
89
		}
90
		if (getLength() != null) {
91
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
92
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
93
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
94
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Size);
95
			mapper.setLongValue(child, getLength());
96
		}
97
		if (getUrl() != null) {
98
			TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_URL);
99
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
100
			defaults.setType(TaskAttribute.TYPE_URL);
101
			defaults.setLabel(Messages.BugzillaAttachmentMapper_URL);
102
			mapper.setValue(child, getUrl());
103
		}
104
		if (getToken() != null) {
105
			TaskAttribute child = taskAttribute.createMappedAttribute(BugzillaAttribute.TOKEN.getKey());
106
			TaskAttributeMetaData defaults = child.getMetaData().defaults();
107
			defaults.setType(TaskAttribute.TYPE_SHORT_TEXT);
108
			defaults.setLabel(Messages.BugzillaAttachmentMapper_Token);
109
			mapper.setValue(child, getToken());
110
		}
111
	}
112
113
	public static BugzillaAttachmentMapper createFrom(TaskAttribute taskAttribute) {
114
		Assert.isNotNull(taskAttribute);
115
		TaskAttributeMapper mapper = taskAttribute.getTaskData().getAttributeMapper();
116
		BugzillaAttachmentMapper attachment = new BugzillaAttachmentMapper();
117
		attachment.setAttachmentId(mapper.getValue(taskAttribute));
118
		TaskAttribute child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_AUTHOR);
119
		if (child != null) {
120
			attachment.setAuthor(mapper.getRepositoryPerson(child));
121
		}
122
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE);
123
		if (child != null) {
124
			attachment.setContentType(mapper.getValue(child));
125
		}
126
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_DATE);
127
		if (child != null) {
128
			attachment.setCreationDate(mapper.getDateValue(child));
129
		}
130
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION);
131
		if (child != null) {
132
			attachment.setDescription(mapper.getValue(child));
133
		}
134
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME);
135
		if (child != null) {
136
			attachment.setFileName(mapper.getValue(child));
137
		}
138
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
139
		if (child != null) {
140
			attachment.setDeprecated(mapper.getBooleanValue(child));
141
		}
142
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
143
		if (child != null) {
144
			attachment.setPatch(mapper.getBooleanValue(child));
145
		}
146
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
147
		if (child != null) {
148
			Long value = mapper.getLongValue(child);
149
			if (value != null) {
150
				attachment.setLength(value);
151
			}
152
		}
153
		child = taskAttribute.getMappedAttribute(TaskAttribute.ATTACHMENT_URL);
154
		if (child != null) {
155
			attachment.setUrl(mapper.getValue(child));
156
		}
157
		child = taskAttribute.getMappedAttribute(BugzillaAttribute.TOKEN.getKey());
158
		if (child != null) {
159
			attachment.setToken(mapper.getValue(child));
160
		}
161
		return attachment;
162
	}
163
164
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/BugzillaTaskAttachmentPage.java (-1 / +1 lines)
Lines 157-163 Link Here
157
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
157
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
158
		flagExpandComposite.setFont(container.getFont());
158
		flagExpandComposite.setFont(container.getFont());
159
		flagExpandComposite.setBackground(container.getBackground());
159
		flagExpandComposite.setBackground(container.getBackground());
160
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_flags);
160
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced);
161
		flagExpandComposite.setLayout(new GridLayout(3, false));
161
		flagExpandComposite.setLayout(new GridLayout(3, false));
162
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
162
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
163
		g.horizontalSpan = 3;
163
		g.horizontalSpan = 3;
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/messages.properties (-1 / +3 lines)
Lines 1-3 Link Here
1
BugzillaAttachmentDialog_DetailTitle=Attachment Detail of {0}
2
BugzillaAttachmentDialog_UpdateTitle=Update of Attachment {0}
1
BugzillaConnectorUi__In_reply_to_comment_X_=(In reply to comment \#{0})
3
BugzillaConnectorUi__In_reply_to_comment_X_=(In reply to comment \#{0})
2
BugzillaConnectorUi__In_reply_to_X_comment_X_=(In reply to {0} comment \#{1})
4
BugzillaConnectorUi__In_reply_to_X_comment_X_=(In reply to {0} comment \#{1})
3
BugzillaConnectorUi__In_reply_to_comment_0_=(In reply to comment \#0)
5
BugzillaConnectorUi__In_reply_to_comment_0_=(In reply to comment \#0)
Lines 28-31 Link Here
28
BugzillaRepositorySettingsPage_Server_URL_is_invalid=Server URL is invalid.
30
BugzillaRepositorySettingsPage_Server_URL_is_invalid=Server URL is invalid.
29
BugzillaRepositorySettingsPage_supports_bugzilla_X=Supports Bugzilla {0}
31
BugzillaRepositorySettingsPage_supports_bugzilla_X=Supports Bugzilla {0}
30
BugzillaRepositorySettingsPage_Validating_server_settings=Validating server settings
32
BugzillaRepositorySettingsPage_Validating_server_settings=Validating server settings
31
BugzillaTaskAttachmentPage_flags=Flags
33
BugzillaTaskAttachmentPage_Advanced=Advanced
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/tasklist/Messages.java (-1 / +5 lines)
Lines 25-30 Link Here
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
	}
26
	}
27
27
28
	public static String BugzillaAttachmentDialog_DetailTitle;
29
30
	public static String BugzillaAttachmentDialog_UpdateTitle;
31
28
	public static String BugzillaConnectorUi__In_reply_to_comment_X_;
32
	public static String BugzillaConnectorUi__In_reply_to_comment_X_;
29
33
30
	public static String BugzillaConnectorUi__In_reply_to_X_comment_X_;
34
	public static String BugzillaConnectorUi__In_reply_to_X_comment_X_;
Lines 79-83 Link Here
79
83
80
	public static String BugzillaRepositorySettingsPage_Validating_server_settings;
84
	public static String BugzillaRepositorySettingsPage_Validating_server_settings;
81
85
82
	public static String BugzillaTaskAttachmentPage_flags;
86
	public static String BugzillaTaskAttachmentPage_Advanced;
83
}
87
}
(-)plugin.xml (+16 lines)
Lines 94-99 Link Here
94
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
94
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark/markadditions"
95
               tooltip="Mark attachment as obsolete">
95
               tooltip="Mark attachment as obsolete">
96
         </action>
96
         </action>
97
           <action
98
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaAttachmentDetailAction"
99
               enablesFor="*"
100
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.detail"
101
               label="Detail..."
102
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
103
               tooltip="Show Details">
104
         </action>
105
           <action
106
               class="org.eclipse.mylyn.internal.bugzilla.ui.action.BugzillaAttachmentUpdateAction"
107
               enablesFor="*"
108
               id="org.eclipse.mylyn.bugzilla.ui.contribution.attachment.update"
109
               label="Update..."
110
               menubarPath="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
111
               tooltip="Update Attachment">
112
         </action>
97
          <menu
113
          <menu
98
                id="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
114
                id="org.eclipse.mylyn.bugzilla.ui.attachments.mark"
99
                label="Mark as"
115
                label="Mark as"
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/messages.properties (+1 lines)
Lines 1-3 Link Here
1
BugzillaAttachmentUpdateAction_Comment=Comment :
1
BugzillaUpdateAttachmentAction_mark_not_obsolete=Mark not obsolete
2
BugzillaUpdateAttachmentAction_mark_not_obsolete=Mark not obsolete
2
BugzillaUpdateAttachmentAction_mark_obsolete=Mark obsolete
3
BugzillaUpdateAttachmentAction_mark_obsolete=Mark obsolete
3
UpdateAttachmentJob_obsolete_not_toggled=Obsolete not toggled successful
4
UpdateAttachmentJob_obsolete_not_toggled=Obsolete not toggled successful
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/Messages.java (+2 lines)
Lines 25-30 Link Here
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
25
		NLS.initializeMessages(BUNDLE_NAME, Messages.class);
26
	}
26
	}
27
27
28
	public static String BugzillaAttachmentUpdateAction_Comment;
29
28
	public static String BugzillaUpdateAttachmentAction_mark_not_obsolete;
30
	public static String BugzillaUpdateAttachmentAction_mark_not_obsolete;
29
31
30
	public static String BugzillaUpdateAttachmentAction_mark_obsolete;
32
	public static String BugzillaUpdateAttachmentAction_mark_obsolete;
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/ChangeAttachmentJob.java (+131 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 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.internal.bugzilla.ui.action;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.OperationCanceledException;
18
import org.eclipse.core.runtime.Status;
19
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
20
import org.eclipse.core.runtime.jobs.Job;
21
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
22
import org.eclipse.mylyn.commons.core.StatusHandler;
23
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
24
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler;
25
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
26
import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
27
import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
28
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
29
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
30
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
32
import org.eclipse.mylyn.tasks.ui.TasksUi;
33
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
34
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
35
import org.eclipse.swt.widgets.Control;
36
import org.eclipse.ui.PlatformUI;
37
import org.eclipse.ui.forms.editor.IFormPage;
38
import org.eclipse.ui.forms.widgets.Section;
39
40
/**
41
 * @author Frank Becker
42
 */
43
@SuppressWarnings("restriction")
44
public class ChangeAttachmentJob extends Job {
45
46
	private final ITaskAttachment attachment;
47
48
	private final TaskEditor editor;
49
50
	private IStatus error;
51
52
	public ChangeAttachmentJob(ITaskAttachment attachment, TaskEditor editor) {
53
		super(Messages.UpdateAttachmentJob_update_attachment);
54
		this.attachment = attachment;
55
		this.editor = editor;
56
	}
57
58
	public IStatus getError() {
59
		return error;
60
	}
61
62
	@Override
63
	protected IStatus run(IProgressMonitor monitor) {
64
		final ITask task;
65
		task = editor.getTaskEditorInput().getTask();
66
67
		if (!task.getConnectorKind().equals(BugzillaCorePlugin.CONNECTOR_KIND)) {
68
			return Status.OK_STATUS;
69
		}
70
		AbstractRepositoryConnector connector = TasksUi.getRepositoryManager().getRepositoryConnector(
71
				task.getConnectorKind());
72
		monitor.beginTask(Messages.UpdateAttachmentJob_update_attachments, 20);
73
		try {
74
			((BugzillaTaskDataHandler) connector.getTaskDataHandler()).postUpdateAttachment(
75
					attachment.getTaskRepository(), attachment.getTaskAttribute(), "update", monitor); //$NON-NLS-1$
76
			monitor.worked(10);
77
78
			if (attachment != null) {
79
				if (connector != null) {
80
					TasksUiInternal.synchronizeTask(connector, task, true, new JobChangeAdapter() {
81
						@Override
82
						public void done(IJobChangeEvent event) {
83
							PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
84
								public void run() {
85
									try {
86
										if (editor != null) {
87
											editor.refreshPages();
88
											editor.getEditorSite().getPage().activate(editor);
89
											IFormPage formPage = editor.getActivePageInstance();
90
											if (formPage instanceof BugzillaTaskEditorPage) {
91
												BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage;
92
												Control control = bugzillaPage.getPart(
93
														AbstractTaskEditorPage.ID_PART_ATTACHMENTS).getControl();
94
												if (control instanceof Section) {
95
													Section section = (Section) control;
96
													EditorUtil.toggleExpandableComposite(true, section);
97
												}
98
											}
99
100
										}
101
									} finally {
102
										if (editor != null) {
103
											editor.showBusy(false);
104
										}
105
									}
106
								}
107
							});
108
						}
109
					});
110
				}
111
				monitor.worked(10);
112
				PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
113
					public void run() {
114
						if (editor != null) {
115
							editor.showBusy(true);
116
						}
117
					}
118
				});
119
			}
120
		} catch (OperationCanceledException e) {
121
			return Status.CANCEL_STATUS;
122
		} catch (CoreException e) {
123
			StatusHandler.log(new Status(IStatus.ERROR, ITasksCoreConstants.ID_PLUGIN,
124
					"Update of an Attachment failed", e)); //$NON-NLS-1$
125
			e.printStackTrace();
126
		} finally {
127
			monitor.done();
128
		}
129
		return Status.OK_STATUS;
130
	}
131
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentUpdateAction.java (+194 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 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.internal.bugzilla.ui.action;
13
14
import java.util.List;
15
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
18
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
19
import org.eclipse.jface.action.IAction;
20
import org.eclipse.jface.dialogs.IMessageProvider;
21
import org.eclipse.jface.viewers.ISelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
23
import org.eclipse.jface.window.Window;
24
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
25
import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog;
26
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
27
import org.eclipse.mylyn.internal.bugzilla.ui.editor.FlagAttributeEditor;
28
import org.eclipse.mylyn.internal.tasks.core.TaskTask;
29
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
30
import org.eclipse.mylyn.tasks.core.ITask;
31
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
32
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.data.ITaskDataWorkingCopy;
34
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
35
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
36
import org.eclipse.mylyn.tasks.core.data.TaskData;
37
import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
38
import org.eclipse.mylyn.tasks.ui.TasksUi;
39
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
40
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
41
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
42
import org.eclipse.swt.widgets.Shell;
43
import org.eclipse.ui.IEditorPart;
44
import org.eclipse.ui.IViewActionDelegate;
45
import org.eclipse.ui.IViewPart;
46
import org.eclipse.ui.IWorkbenchPage;
47
import org.eclipse.ui.IWorkbenchPartSite;
48
import org.eclipse.ui.IWorkbenchWindow;
49
import org.eclipse.ui.PlatformUI;
50
import org.eclipse.ui.actions.BaseSelectionListenerAction;
51
import org.eclipse.ui.forms.editor.IFormPage;
52
53
@SuppressWarnings("restriction")
54
public class BugzillaAttachmentUpdateAction extends BaseSelectionListenerAction implements IViewActionDelegate {
55
56
	private ISelection currentSelection;
57
58
	public BugzillaAttachmentUpdateAction() {
59
		super("BugzillaAttachmentDetailAction"); //$NON-NLS-1$
60
	}
61
62
	public void init(IViewPart view) {
63
		// ignore
64
65
	}
66
67
	public void run(IAction action) {
68
		IStructuredSelection selection = null;
69
		if (currentSelection instanceof IStructuredSelection) {
70
			selection = (IStructuredSelection) currentSelection;
71
		}
72
		if (selection == null || selection.isEmpty() || selection.size() != 1) {
73
			return;
74
		}
75
		ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
76
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
77
		IWorkbenchPage page = window.getActivePage();
78
		IEditorPart activeEditor = page.getActiveEditor();
79
		IWorkbenchPartSite site = activeEditor.getSite();
80
		Shell shell = site.getShell();
81
		if (activeEditor instanceof TaskEditor) {
82
			final TaskEditor taskEditor = (TaskEditor) activeEditor;
83
			IFormPage taskEditorPage = taskEditor.findPage("id"); //$NON-NLS-1$
84
			if (taskEditorPage instanceof BugzillaTaskEditorPage) {
85
				BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
86
87
				ITask attachmentTask = attachment.getTask();
88
				ITask nTask = new TaskTask(attachmentTask.getConnectorKind(), attachmentTask.getRepositoryUrl(),
89
						attachmentTask.getTaskId() + "attachment"); //$NON-NLS-1$
90
91
				TaskData editTaskData = new TaskData(attachment.getTaskAttribute().getTaskData().getAttributeMapper(),
92
						attachment.getTaskAttribute().getTaskData().getConnectorKind(), attachment.getTaskAttribute()
93
								.getTaskData()
94
								.getRepositoryUrl(), attachment.getTaskAttribute().getTaskData().getTaskId());
95
				editTaskData.setVersion(attachment.getTaskAttribute().getTaskData().getVersion());
96
				TaskAttribute target0 = editTaskData.getRoot();
97
				TaskAttribute temp = attachment.getTaskAttribute();
98
				target0.setValues(temp.getValues());
99
				for (TaskAttribute child : temp.getAttributes().values()) {
100
					target0.deepAddCopy(child);
101
				}
102
103
				TaskAttribute comment = target0.createAttribute("comment"); //$NON-NLS-1$
104
				TaskAttributeMetaData commentMeta = comment.getMetaData();
105
				commentMeta.setType(TaskAttribute.TYPE_LONG_RICH_TEXT);
106
				commentMeta.setLabel(Messages.BugzillaAttachmentUpdateAction_Comment);
107
108
				ITaskDataWorkingCopy workingCopy = TasksUi.getTaskDataManager().createWorkingCopy(nTask, editTaskData);
109
				try {
110
					workingCopy.save(null, null);
111
				} catch (CoreException e) {
112
					// TODO Auto-generated catch block
113
					e.printStackTrace();
114
				}
115
				TaskRepository repository = TasksUiPlugin.getRepositoryManager().getRepository(
116
						attachment.getTaskAttribute().getTaskData().getRepositoryUrl());
117
				final TaskDataModel model = new TaskDataModel(repository, nTask, workingCopy);
118
				AttributeEditorFactory factory = new AttributeEditorFactory(model, repository,
119
						bugzillaTaskEditorPage.getEditorSite()) {
120
					@Override
121
					public AbstractAttributeEditor createEditor(String type, final TaskAttribute taskAttribute) {
122
						AbstractAttributeEditor editor;
123
						if (IBugzillaConstants.EDITOR_TYPE_FLAG.equals(type)) {
124
							editor = new FlagAttributeEditor(model, taskAttribute);
125
						} else {
126
							editor = super.createEditor(type, taskAttribute);
127
							if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
128
								editor.setDecorationEnabled(false);
129
							}
130
						}
131
						return editor;
132
					}
133
				};
134
135
				TaskAttribute target = workingCopy.getLocalData().getRoot();
136
				BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, bugzillaTaskEditorPage, factory,
137
						target, false);
138
				if (dialog.open() == Window.OK) {
139
					TaskAttribute attachmentAttribute = attachment.getTaskAttribute();
140
					for (TaskAttribute child : target.getAttributes().values()) {
141
						attachmentAttribute.deepAddCopy(child);
142
					}
143
					final ChangeAttachmentJob job = new ChangeAttachmentJob(attachment, taskEditor);
144
					job.setUser(true);
145
					job.addJobChangeListener(new JobChangeAdapter() {
146
147
						@Override
148
						public void done(IJobChangeEvent event) {
149
							IFormPage formPage = taskEditor.getActivePageInstance();
150
							if (formPage instanceof BugzillaTaskEditorPage) {
151
								final BugzillaTaskEditorPage bugzillaPage = (BugzillaTaskEditorPage) formPage;
152
								if (job.getError() != null) {
153
									PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
154
										public void run() {
155
											bugzillaPage.getTaskEditor().setMessage(job.getError().getMessage(),
156
													IMessageProvider.ERROR);
157
										}
158
									});
159
								} else {
160
									PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
161
										public void run() {
162
											bugzillaPage.refreshFormContent();
163
										}
164
									});
165
								}
166
							}
167
						}
168
					});
169
					job.schedule();
170
				}
171
			}
172
		}
173
	}
174
175
	@SuppressWarnings("unchecked")
176
	public void selectionChanged(IAction action, ISelection selection) {
177
		this.currentSelection = selection;
178
		IStructuredSelection sructuredSelection = null;
179
		if (selection instanceof IStructuredSelection) {
180
			sructuredSelection = (IStructuredSelection) currentSelection;
181
		}
182
		if (sructuredSelection == null || sructuredSelection.isEmpty()) {
183
			return;
184
		}
185
		List<ITaskAttachment> attachmentList = sructuredSelection.toList();
186
		if (attachmentList != null && attachmentList.size() == 1) {
187
			action.setEnabled(true);
188
		} else {
189
			action.setEnabled(false);
190
		}
191
192
	}
193
194
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/action/BugzillaAttachmentDetailAction.java (+92 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 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.internal.bugzilla.ui.action;
13
14
import java.util.List;
15
16
import org.eclipse.jface.action.IAction;
17
import org.eclipse.jface.viewers.ISelection;
18
import org.eclipse.jface.viewers.IStructuredSelection;
19
import org.eclipse.mylyn.internal.bugzilla.ui.dialogs.BugzillaAttachmentDialog;
20
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
21
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
22
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.IEditorPart;
25
import org.eclipse.ui.IViewActionDelegate;
26
import org.eclipse.ui.IViewPart;
27
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchPartSite;
29
import org.eclipse.ui.IWorkbenchWindow;
30
import org.eclipse.ui.PlatformUI;
31
import org.eclipse.ui.actions.BaseSelectionListenerAction;
32
import org.eclipse.ui.forms.editor.IFormPage;
33
34
public class BugzillaAttachmentDetailAction extends BaseSelectionListenerAction implements IViewActionDelegate {
35
36
	private ISelection currentSelection;
37
38
	public BugzillaAttachmentDetailAction() {
39
		super("BugzillaAttachmentDetailAction"); //$NON-NLS-1$
40
	}
41
42
	public void init(IViewPart view) {
43
		// ignore
44
45
	}
46
47
	public void run(IAction action) {
48
		IStructuredSelection selection = null;
49
		if (currentSelection instanceof IStructuredSelection) {
50
			selection = (IStructuredSelection) currentSelection;
51
		}
52
		if (selection == null || selection.isEmpty() || selection.size() != 1) {
53
			return;
54
		}
55
		ITaskAttachment attachment = (ITaskAttachment) selection.getFirstElement();
56
		IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
57
		IWorkbenchPage page = window.getActivePage();
58
		IEditorPart activeEditor = page.getActiveEditor();
59
		IWorkbenchPartSite site = activeEditor.getSite();
60
		Shell shell = site.getShell();
61
		if (activeEditor instanceof TaskEditor) {
62
			final TaskEditor taskEditor = (TaskEditor) activeEditor;
63
			IFormPage taskEditorPage = taskEditor.findPage("id"); //$NON-NLS-1$
64
			if (taskEditorPage instanceof BugzillaTaskEditorPage) {
65
				BugzillaTaskEditorPage bugzillaTaskEditorPage = (BugzillaTaskEditorPage) taskEditorPage;
66
				BugzillaAttachmentDialog dialog = new BugzillaAttachmentDialog(shell, bugzillaTaskEditorPage,
67
						bugzillaTaskEditorPage.getAttributeEditorFactory(), attachment.getTaskAttribute(), true);
68
				dialog.open();
69
			}
70
		}
71
	}
72
73
	@SuppressWarnings("unchecked")
74
	public void selectionChanged(IAction action, ISelection selection) {
75
		this.currentSelection = selection;
76
		IStructuredSelection sructuredSelection = null;
77
		if (selection instanceof IStructuredSelection) {
78
			sructuredSelection = (IStructuredSelection) currentSelection;
79
		}
80
		if (sructuredSelection == null || sructuredSelection.isEmpty()) {
81
			return;
82
		}
83
		List<ITaskAttachment> attachmentList = sructuredSelection.toList();
84
		if (attachmentList != null && attachmentList.size() == 1) {
85
			action.setEnabled(true);
86
		} else {
87
			action.setEnabled(false);
88
		}
89
90
	}
91
92
}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/dialogs/BugzillaAttachmentDialog.java (+250 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2008 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.internal.bugzilla.ui.dialogs;
13
14
import java.text.MessageFormat;
15
16
import org.eclipse.jface.dialogs.Dialog;
17
import org.eclipse.jface.layout.GridDataFactory;
18
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
19
import org.eclipse.mylyn.internal.bugzilla.ui.editor.BugzillaTaskEditorPage;
20
import org.eclipse.mylyn.internal.bugzilla.ui.tasklist.Messages;
21
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
22
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
23
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.layout.GridData;
26
import org.eclipse.swt.layout.GridLayout;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Control;
29
import org.eclipse.swt.widgets.Display;
30
import org.eclipse.swt.widgets.Label;
31
import org.eclipse.swt.widgets.Shell;
32
import org.eclipse.ui.dialogs.SelectionDialog;
33
import org.eclipse.ui.forms.events.ExpansionAdapter;
34
import org.eclipse.ui.forms.events.ExpansionEvent;
35
import org.eclipse.ui.forms.widgets.ExpandableComposite;
36
import org.eclipse.ui.forms.widgets.FormToolkit;
37
38
/**
39
 * 
40
 * @author Frank Becker
41
 */
42
public class BugzillaAttachmentDialog extends SelectionDialog {
43
44
	private final FormToolkit toolkit;
45
46
	private Composite scrollComposite;
47
48
	private ExpandableComposite flagExpandComposite = null;
49
50
	private final TaskAttribute attachment;
51
52
	private final Shell parentShell;
53
54
	private final boolean readOnly;
55
56
	private final AttributeEditorFactory attributeEditorFactory;
57
58
	private static final int LABEL_WIDTH = 120;
59
60
	private static final int COLUMN_GAP = 5;
61
62
	private static final int MULTI_ROW_HEIGHT = 55;
63
64
	private static final int COLUMN_WIDTH = 200;
65
66
	private static final int MULTI_COLUMN_WIDTH = COLUMN_WIDTH + 5 + COLUMN_GAP + LABEL_WIDTH + 5 + COLUMN_WIDTH;
67
68
	public BugzillaAttachmentDialog(Shell parentShell, BugzillaTaskEditorPage editor, AttributeEditorFactory factory,
69
			TaskAttribute attachment, boolean readonly) {
70
		super(parentShell);
71
		this.attachment = attachment;
72
		this.parentShell = parentShell;
73
		this.readOnly = readonly;
74
		attributeEditorFactory = factory;
75
		toolkit = new FormToolkit(Display.getCurrent());
76
		this.setTitle(MessageFormat.format(readonly ? Messages.BugzillaAttachmentDialog_DetailTitle
77
				: Messages.BugzillaAttachmentDialog_UpdateTitle, attachment.getValue()));
78
	}
79
80
	@Override
81
	protected Control createDialogArea(Composite parent) {
82
		int currentColumn = 1;
83
		int columnCount = 4;
84
		Composite composite = (Composite) super.createDialogArea(parent);
85
86
		initializeDialogUnits(composite);
87
88
		Composite attributeArea = new Composite(composite, SWT.FLAT);
89
		attributeArea.setLayout(new GridLayout(4, false));
90
		createAttributeEditors(currentColumn, columnCount, attributeArea);
91
		Composite advancedComposite = createFlagSection(attributeArea);
92
		createFlagEditors(columnCount, advancedComposite);
93
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_URL), currentColumn, columnCount,
94
				advancedComposite);
95
		createCommntEditor(currentColumn, columnCount, attributeArea);
96
		Dialog.applyDialogFont(composite);
97
		return composite;
98
	}
99
100
	private void createAttributeEditor(TaskAttribute attribute, int currentColumn, int columnCount,
101
			Composite attributeArea) {
102
		String type = attribute.getMetaData().getType();
103
		if (type != null) {
104
			AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute);
105
			if (attribute.getId().equals(BugzillaAttribute.TOKEN.getKey())
106
					|| attribute.getId().equals("size") || attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) { //$NON-NLS-1$
107
				editor.setReadOnly(true);
108
			} else {
109
				editor.setReadOnly(readOnly);
110
			}
111
			if (editor.hasLabel()) {
112
				editor.createLabelControl(attributeArea, toolkit);
113
				Label label = editor.getLabelControl();
114
				label.setBackground(attributeArea.getBackground());
115
				String labelString = editor.getLabel();
116
				if (labelString != null && !labelString.equals("")) { //$NON-NLS-1$
117
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
118
							SWT.DEFAULT).create();
119
					if (currentColumn > 1) {
120
						gd.horizontalIndent = COLUMN_GAP;
121
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
122
					}
123
					label.setLayoutData(gd);
124
					currentColumn++;
125
				}
126
			}
127
			editor.createControl(attributeArea, toolkit);
128
			GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
129
			if (type.equals("shortText") || type.equals("url")) { //$NON-NLS-1$//$NON-NLS-2$
130
				gd.horizontalSpan = 3;
131
			} else {
132
				gd.horizontalSpan = 1;
133
			}
134
			editor.getControl().setLayoutData(gd);
135
			if (attribute.getId().equals(TaskAttribute.ATTACHMENT_URL)) {
136
				editor.getControl().setEnabled(false);
137
			}
138
139
			currentColumn += gd.horizontalSpan;
140
			currentColumn %= columnCount;
141
		}
142
	}
143
144
	private void createAttributeEditors(int currentColumn, int columnCount, Composite attributeArea) {
145
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION), currentColumn,
146
				columnCount, attributeArea);
147
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME), currentColumn,
148
				columnCount, attributeArea);
149
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_SIZE), currentColumn, columnCount,
150
				attributeArea);
151
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE), currentColumn,
152
				columnCount, attributeArea);
153
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH), currentColumn,
154
				columnCount, attributeArea);
155
		createAttributeEditor(attachment.getMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED), currentColumn,
156
				columnCount, attributeArea);
157
	}
158
159
	private void createFlagEditors(int columnCount, Composite advancedComposite) {
160
		int currentFlagColumn = 1;
161
162
		for (TaskAttribute attribute : attachment.getAttributes().values()) {
163
			if (!attribute.getId().startsWith("task.common.kind.flag")) { //$NON-NLS-1$
164
				continue;
165
			}
166
			String type = attribute.getMetaData().getType();
167
			if (type != null) {
168
				AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, attribute);
169
				editor.setReadOnly(readOnly);
170
171
				if (editor.hasLabel()) {
172
					editor.createLabelControl(advancedComposite, toolkit);
173
					Label label = editor.getLabelControl();
174
					label.setBackground(advancedComposite.getBackground());
175
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
176
							SWT.DEFAULT).create();
177
					if (currentFlagColumn > 1) {
178
						gd.horizontalIndent = COLUMN_GAP;
179
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
180
					}
181
					label.setLayoutData(gd);
182
					currentFlagColumn++;
183
				}
184
				editor.createControl(advancedComposite, toolkit);
185
				GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
186
				gd.widthHint = 150;//COLUMN_WIDTH;
187
				gd.horizontalSpan = 3;
188
				editor.getControl().setLayoutData(gd);
189
				currentFlagColumn += gd.horizontalSpan;
190
				currentFlagColumn %= columnCount;
191
			}
192
		}
193
	}
194
195
	private void createCommntEditor(int currentColumn, int columnCount, Composite attributeArea) {
196
		TaskAttribute commentAttribute = attachment.getAttribute("comment"); //$NON-NLS-1$
197
		if (commentAttribute == null || readOnly) {
198
			return;
199
		}
200
		String type = commentAttribute.getMetaData().getType();
201
		if (type != null) {
202
			AbstractAttributeEditor editor = attributeEditorFactory.createEditor(type, commentAttribute);
203
			String labelString = editor.getLabel();
204
			if (editor.hasLabel()) {
205
				editor.createLabelControl(attributeArea, toolkit);
206
				if (!labelString.equals("")) { //$NON-NLS-1$
207
					Label label = editor.getLabelControl();
208
					label.setBackground(attributeArea.getBackground());
209
					GridData gd = GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).hint(LABEL_WIDTH,
210
							SWT.DEFAULT).create();
211
					if (currentColumn > 1) {
212
						gd.horizontalIndent = COLUMN_GAP;
213
						gd.widthHint = LABEL_WIDTH + COLUMN_GAP;
214
					}
215
					label.setLayoutData(gd);
216
				}
217
			}
218
			editor.createControl(attributeArea, toolkit);
219
			GridData gd = new GridData(SWT.FILL, SWT.CENTER, false, false);
220
			gd.heightHint = MULTI_ROW_HEIGHT;
221
			gd.widthHint = MULTI_COLUMN_WIDTH;
222
			gd.horizontalSpan = columnCount - currentColumn + 1;
223
			editor.getControl().setLayoutData(gd);
224
		}
225
	}
226
227
	private Composite createFlagSection(Composite container) {
228
		flagExpandComposite = toolkit.createExpandableComposite(container, ExpandableComposite.COMPACT
229
				| ExpandableComposite.TWISTIE | ExpandableComposite.TITLE_BAR);
230
		flagExpandComposite.setFont(container.getFont());
231
		flagExpandComposite.setBackground(container.getBackground());
232
		flagExpandComposite.setText(Messages.BugzillaTaskAttachmentPage_Advanced);
233
		flagExpandComposite.setLayout(new GridLayout(4, false));
234
		GridData g = new GridData(GridData.FILL_HORIZONTAL);
235
		g.horizontalSpan = 4;
236
		flagExpandComposite.setLayoutData(g);
237
		flagExpandComposite.addExpansionListener(new ExpansionAdapter() {
238
			@Override
239
			public void expansionStateChanged(ExpansionEvent e) {
240
				parentShell.getDisplay().getActiveShell().pack();
241
			}
242
		});
243
244
		scrollComposite = new Composite(flagExpandComposite, SWT.NONE);
245
		scrollComposite.setLayout(new GridLayout(4, false));
246
		flagExpandComposite.setClient(scrollComposite);
247
		return scrollComposite;
248
	}
249
250
}

Return to bug 272207