1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*******************************************************************************
* Copyright (c) 2004, 2007 Mylyn project committers 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
*******************************************************************************/
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.dialogs.IMessageProvider;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;
/**
* @author Rob Elves
* @since 3.0
*/
public class BugzillaTaskEditorPage extends AbstractTaskEditorPage {
private static final String LABEL_ERROR_SUBMIT = "Task Submit Error";
public static final String ID_PART_BUGZILLA_PLANNING = "org.eclipse.mylyn.bugzilla.ui.editors.part.planning";
public BugzillaTaskEditorPage(TaskEditor editor) {
super(editor, BugzillaCorePlugin.CONNECTOR_KIND);
}
@Override
protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
Set<TaskEditorPartDescriptor> descriptors = super.createPartDescriptors();
// remove unnecessary default editor parts
for (TaskEditorPartDescriptor taskEditorPartDescriptor : descriptors) {
if (taskEditorPartDescriptor.getId().equals(ID_PART_PEOPLE)) {
descriptors.remove(taskEditorPartDescriptor);
break;
}
}
// Add Bugzilla Planning part
try {
TaskData data = TasksUi.getTaskDataManager().getTaskData(getTask());
if (data != null) {
TaskAttribute attrEstimatedTime = data.getRoot().getMappedAttribute(
BugzillaAttribute.ESTIMATED_TIME.getKey());
if (attrEstimatedTime != null) {
descriptors.add(new TaskEditorPartDescriptor(ID_PART_BUGZILLA_PLANNING) {
@Override
public AbstractTaskEditorPart createPart() {
return new BugzillaPlanningEditorPart();
}
}.setPath(PATH_ATTRIBUTES));
}
}
} catch (CoreException e) {
// ignore
}
// Add the updated Bugzilla people part
descriptors.add(new TaskEditorPartDescriptor(ID_PART_PEOPLE) {
@Override
public AbstractTaskEditorPart createPart() {
return new BugzillaPeoplePart();
}
}.setPath(PATH_PEOPLE));
return descriptors;
}
@Override
protected AttributeEditorFactory createAttributeEditorFactory() {
AttributeEditorFactory factory = new AttributeEditorFactory(getModel(), getTaskRepository()) {
@Override
public AbstractAttributeEditor createEditor(String type, TaskAttribute taskAttribute) {
AbstractAttributeEditor editor;
if (IBugzillaConstants.EDITOR_TYPE_KEYWORDS.equals(type)) {
editor = new BugzillaKeywordAttributeEditor(getModel(), taskAttribute);
} else if (IBugzillaConstants.EDITOR_TYPE_REMOVECC.equals(type)) {
editor = new BugzillaCcAttributeEditor(getModel(), taskAttribute);
} else if (IBugzillaConstants.EDITOR_TYPE_VOTES.equals(type)) {
editor = new BugzillaVotesEditor(getModel(), taskAttribute);
} else {
editor = super.createEditor(type, taskAttribute);
if (TaskAttribute.TYPE_BOOLEAN.equals(type)) {
editor.setDecorationEnabled(false);
}
}
return editor;
}
};
return factory;
}
@Override
public void doSubmit() {
TaskAttribute summaryAttribute = getModel().getTaskData().getRoot().getMappedAttribute(TaskAttribute.SUMMARY);
if (summaryAttribute != null && summaryAttribute.getValue().length() == 0) {
getTaskEditor().setMessage("Please enter a short summary before submitting", IMessageProvider.ERROR);
AbstractTaskEditorPart part = getPart(ID_PART_SUMMARY);
if (part != null) {
part.setFocus();
}
return;
}
TaskAttribute componentAttribute = getModel().getTaskData().getRoot().getMappedAttribute(
BugzillaAttribute.COMPONENT.getKey());
if (componentAttribute != null && componentAttribute.getValue().length() == 0) {
getTaskEditor().setMessage("Please select a component before submitting", IMessageProvider.ERROR);
AbstractTaskEditorPart part = getPart(ID_PART_ATTRIBUTES);
if (part != null) {
part.setFocus();
}
return;
}
TaskAttribute descriptionAttribute = getModel().getTaskData().getRoot().getMappedAttribute(
TaskAttribute.DESCRIPTION);
if (descriptionAttribute != null && descriptionAttribute.getValue().length() == 0) {
getTaskEditor().setMessage("Please enter a description before submitting", IMessageProvider.ERROR);
AbstractTaskEditorPart descriptionPart = getPart(ID_PART_DESCRIPTION);
if (descriptionPart != null) {
descriptionPart.setFocus();
}
return;
}
super.doSubmit();
}
}
|