|
Lines 7-26
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* Tasktop Technologies - initial API and implementation |
9 |
* Tasktop Technologies - initial API and implementation |
|
|
10 |
* Frank Becker - enhancements for bug 166595 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
|
12 |
|
| 12 |
package org.eclipse.mylyn.internal.bugzilla.ui.editor; |
13 |
package org.eclipse.mylyn.internal.bugzilla.ui.editor; |
| 13 |
|
14 |
|
|
|
15 |
import java.util.Collections; |
| 16 |
import java.util.HashMap; |
| 17 |
import java.util.List; |
| 18 |
import java.util.Map; |
| 14 |
import java.util.Set; |
19 |
import java.util.Set; |
| 15 |
|
20 |
|
| 16 |
import org.eclipse.core.runtime.CoreException; |
21 |
import org.eclipse.core.runtime.CoreException; |
|
|
22 |
import org.eclipse.core.runtime.IStatus; |
| 23 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 17 |
import org.eclipse.jface.dialogs.IMessageProvider; |
24 |
import org.eclipse.jface.dialogs.IMessageProvider; |
|
|
25 |
import org.eclipse.mylyn.commons.core.StatusHandler; |
| 18 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; |
26 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; |
| 19 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; |
27 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; |
| 20 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; |
28 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; |
| 21 |
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; |
29 |
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; |
|
|
30 |
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; |
| 31 |
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin; |
| 32 |
import org.eclipse.mylyn.tasks.core.RepositoryStatus; |
| 22 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
33 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
| 23 |
import org.eclipse.mylyn.tasks.core.data.TaskData; |
34 |
import org.eclipse.mylyn.tasks.core.data.TaskData; |
|
|
35 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModel; |
| 36 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent; |
| 37 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener; |
| 24 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
38 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
| 25 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
39 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
| 26 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
40 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
|
Lines 28-33
Link Here
|
| 28 |
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; |
42 |
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; |
| 29 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
43 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
| 30 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
44 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
|
|
45 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput; |
| 31 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; |
46 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; |
| 32 |
|
47 |
|
| 33 |
/** |
48 |
/** |
|
Lines 38-45
Link Here
|
| 38 |
|
53 |
|
| 39 |
public static final String ID_PART_BUGZILLA_PLANNING = "org.eclipse.mylyn.bugzilla.ui.editors.part.planning"; //$NON-NLS-1$ |
54 |
public static final String ID_PART_BUGZILLA_PLANNING = "org.eclipse.mylyn.bugzilla.ui.editors.part.planning"; //$NON-NLS-1$ |
| 40 |
|
55 |
|
|
|
56 |
private final Map<TaskAttribute, AbstractAttributeEditor> attributeEditorMap; |
| 57 |
|
| 58 |
private TaskDataModelListener productListener; |
| 59 |
|
| 41 |
public BugzillaTaskEditorPage(TaskEditor editor) { |
60 |
public BugzillaTaskEditorPage(TaskEditor editor) { |
| 42 |
super(editor, BugzillaCorePlugin.CONNECTOR_KIND); |
61 |
this(editor, BugzillaCorePlugin.CONNECTOR_KIND); |
| 43 |
} |
62 |
} |
| 44 |
|
63 |
|
| 45 |
/** |
64 |
/** |
|
Lines 50-55
Link Here
|
| 50 |
*/ |
69 |
*/ |
| 51 |
public BugzillaTaskEditorPage(TaskEditor editor, String connectorKind) { |
70 |
public BugzillaTaskEditorPage(TaskEditor editor, String connectorKind) { |
| 52 |
super(editor, connectorKind); |
71 |
super(editor, connectorKind); |
|
|
72 |
this.attributeEditorMap = new HashMap<TaskAttribute, AbstractAttributeEditor>(); |
| 53 |
} |
73 |
} |
| 54 |
|
74 |
|
| 55 |
@Override |
75 |
@Override |
|
Lines 125-130
Link Here
|
| 125 |
}); |
145 |
}); |
| 126 |
} |
146 |
} |
| 127 |
|
147 |
|
|
|
148 |
BugzillaTaskEditorPage.this.addToAttributeEditorMap(taskAttribute, editor); |
| 128 |
return editor; |
149 |
return editor; |
| 129 |
} |
150 |
} |
| 130 |
}; |
151 |
}; |
|
Lines 132-142
Link Here
|
| 132 |
} |
153 |
} |
| 133 |
|
154 |
|
| 134 |
@Override |
155 |
@Override |
|
|
156 |
protected void createParts() { |
| 157 |
attributeEditorMap.clear(); |
| 158 |
super.createParts(); |
| 159 |
} |
| 160 |
|
| 161 |
@Override |
| 162 |
protected TaskDataModel createModel(TaskEditorInput input) throws CoreException { |
| 163 |
TaskDataModel model = super.createModel(input); |
| 164 |
productListener = new ProductSelectionListener(); |
| 165 |
model.addModelListener(productListener); |
| 166 |
return model; |
| 167 |
} |
| 168 |
|
| 169 |
@Override |
| 135 |
public void doSubmit() { |
170 |
public void doSubmit() { |
| 136 |
|
171 |
|
| 137 |
TaskAttribute summaryAttribute = getModel().getTaskData().getRoot().getMappedAttribute(TaskAttribute.SUMMARY); |
172 |
TaskAttribute summaryAttribute = getModel().getTaskData().getRoot().getMappedAttribute(TaskAttribute.SUMMARY); |
| 138 |
if (summaryAttribute != null && summaryAttribute.getValue().length() == 0) { |
173 |
if (summaryAttribute != null && summaryAttribute.getValue().length() == 0) { |
| 139 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_enter_a_short_summary_before_submitting, IMessageProvider.ERROR); |
174 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_enter_a_short_summary_before_submitting, |
|
|
175 |
IMessageProvider.ERROR); |
| 140 |
AbstractTaskEditorPart part = getPart(ID_PART_SUMMARY); |
176 |
AbstractTaskEditorPart part = getPart(ID_PART_SUMMARY); |
| 141 |
if (part != null) { |
177 |
if (part != null) { |
| 142 |
part.setFocus(); |
178 |
part.setFocus(); |
|
Lines 147-153
Link Here
|
| 147 |
TaskAttribute componentAttribute = getModel().getTaskData().getRoot().getMappedAttribute( |
183 |
TaskAttribute componentAttribute = getModel().getTaskData().getRoot().getMappedAttribute( |
| 148 |
BugzillaAttribute.COMPONENT.getKey()); |
184 |
BugzillaAttribute.COMPONENT.getKey()); |
| 149 |
if (componentAttribute != null && componentAttribute.getValue().length() == 0) { |
185 |
if (componentAttribute != null && componentAttribute.getValue().length() == 0) { |
| 150 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_select_a_component_before_submitting, IMessageProvider.ERROR); |
186 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_select_a_component_before_submitting, |
|
|
187 |
IMessageProvider.ERROR); |
| 151 |
AbstractTaskEditorPart part = getPart(ID_PART_ATTRIBUTES); |
188 |
AbstractTaskEditorPart part = getPart(ID_PART_ATTRIBUTES); |
| 152 |
if (part != null) { |
189 |
if (part != null) { |
| 153 |
part.setFocus(); |
190 |
part.setFocus(); |
|
Lines 158-164
Link Here
|
| 158 |
TaskAttribute descriptionAttribute = getModel().getTaskData().getRoot().getMappedAttribute( |
195 |
TaskAttribute descriptionAttribute = getModel().getTaskData().getRoot().getMappedAttribute( |
| 159 |
TaskAttribute.DESCRIPTION); |
196 |
TaskAttribute.DESCRIPTION); |
| 160 |
if (descriptionAttribute != null && descriptionAttribute.getValue().length() == 0) { |
197 |
if (descriptionAttribute != null && descriptionAttribute.getValue().length() == 0) { |
| 161 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_enter_a_description_before_submitting, IMessageProvider.ERROR); |
198 |
getTaskEditor().setMessage(Messages.BugzillaTaskEditorPage_Please_enter_a_description_before_submitting, |
|
|
199 |
IMessageProvider.ERROR); |
| 162 |
AbstractTaskEditorPart descriptionPart = getPart(ID_PART_DESCRIPTION); |
200 |
AbstractTaskEditorPart descriptionPart = getPart(ID_PART_DESCRIPTION); |
| 163 |
if (descriptionPart != null) { |
201 |
if (descriptionPart != null) { |
| 164 |
descriptionPart.setFocus(); |
202 |
descriptionPart.setFocus(); |
|
Lines 169-172
Link Here
|
| 169 |
super.doSubmit(); |
207 |
super.doSubmit(); |
| 170 |
} |
208 |
} |
| 171 |
|
209 |
|
|
|
210 |
/** |
| 211 |
* @since 3.1 |
| 212 |
*/ |
| 213 |
public void addToAttributeEditorMap(TaskAttribute attribute, AbstractAttributeEditor editor) { |
| 214 |
if (attributeEditorMap.containsKey(attribute)) { |
| 215 |
attributeEditorMap.remove(attribute); |
| 216 |
} |
| 217 |
attributeEditorMap.put(attribute, editor); |
| 218 |
} |
| 219 |
|
| 220 |
/** |
| 221 |
* @since 3.1 |
| 222 |
*/ |
| 223 |
public AbstractAttributeEditor getEditorForAttribute(TaskAttribute attribute) { |
| 224 |
return attributeEditorMap.get(attribute); |
| 225 |
} |
| 226 |
|
| 227 |
/** |
| 228 |
* @since 3.1 |
| 229 |
*/ |
| 230 |
public Map<TaskAttribute, AbstractAttributeEditor> getAttributeEditorMap() { |
| 231 |
return attributeEditorMap; |
| 232 |
} |
| 233 |
|
| 234 |
/** |
| 235 |
* @since 3.1 |
| 236 |
*/ |
| 237 |
public void refresh() { |
| 238 |
try { |
| 239 |
showEditorBusy(true); |
| 240 |
for (AbstractAttributeEditor abstractAttributeEditor : attributeEditorMap.values()) { |
| 241 |
try { |
| 242 |
abstractAttributeEditor.refresh(); |
| 243 |
} catch (UnsupportedOperationException e) { |
| 244 |
// ignore |
| 245 |
} |
| 246 |
} |
| 247 |
} finally { |
| 248 |
showEditorBusy(false); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
public void refresh(TaskAttribute attributeComponent) { |
| 253 |
AbstractAttributeEditor editor = getEditorForAttribute(attributeComponent); |
| 254 |
if (editor != null) { |
| 255 |
try { |
| 256 |
editor.refresh(); |
| 257 |
} catch (UnsupportedOperationException e) { |
| 258 |
// ignore |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
private class ProductSelectionListener extends TaskDataModelListener { |
| 264 |
@Override |
| 265 |
public void attributeChanged(TaskDataModelEvent event) { |
| 266 |
TaskAttribute taskAttribute = event.getTaskAttribute(); |
| 267 |
if (taskAttribute != null) { |
| 268 |
if (taskAttribute.getId().equals(BugzillaAttribute.PRODUCT.getKey())) { |
| 269 |
RepositoryConfiguration repositoryConfiguration = null; |
| 270 |
try { |
| 271 |
repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration( |
| 272 |
getModel().getTaskRepository(), false, new NullProgressMonitor()); |
| 273 |
} catch (CoreException e) { |
| 274 |
StatusHandler.log(new RepositoryStatus(getTaskRepository(), IStatus.ERROR, |
| 275 |
BugzillaUiPlugin.ID_PLUGIN, 0, "Failed to obtain repository configuration", e)); //$NON-NLS-1$ |
| 276 |
getTaskEditor().setMessage("Problem occured when updating attributes", IMessageProvider.ERROR); //$NON-NLS-1$ |
| 277 |
return; |
| 278 |
} |
| 279 |
|
| 280 |
TaskAttribute attributeComponent = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 281 |
BugzillaAttribute.COMPONENT.getKey()); |
| 282 |
if (attributeComponent != null) { |
| 283 |
List<String> optionValues = repositoryConfiguration.getComponents(taskAttribute.getValue()); |
| 284 |
Collections.sort(optionValues); |
| 285 |
attributeComponent.clearOptions(); |
| 286 |
for (String option : optionValues) { |
| 287 |
attributeComponent.putOption(option, option); |
| 288 |
} |
| 289 |
if (optionValues.size() == 1) { |
| 290 |
attributeComponent.setValue(optionValues.get(0)); |
| 291 |
} else { |
| 292 |
attributeComponent.setValue(""); //$NON-NLS-1$ |
| 293 |
} |
| 294 |
refresh(attributeComponent); |
| 295 |
} |
| 296 |
|
| 297 |
TaskAttribute attributeTargetMilestone = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 298 |
BugzillaAttribute.TARGET_MILESTONE.getKey()); |
| 299 |
if (attributeTargetMilestone != null) { |
| 300 |
List<String> optionValues = repositoryConfiguration.getTargetMilestones(taskAttribute.getValue()); |
| 301 |
Collections.sort(optionValues); |
| 302 |
attributeTargetMilestone.clearOptions(); |
| 303 |
for (String option : optionValues) { |
| 304 |
attributeTargetMilestone.putOption(option, option); |
| 305 |
} |
| 306 |
if (optionValues.size() == 1) { |
| 307 |
attributeTargetMilestone.setValue(optionValues.get(0)); |
| 308 |
} else { |
| 309 |
attributeTargetMilestone.setValue("---"); //$NON-NLS-1$ |
| 310 |
} |
| 311 |
refresh(attributeTargetMilestone); |
| 312 |
} |
| 313 |
|
| 314 |
TaskAttribute attributeDefaultAssignee = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 315 |
BugzillaAttribute.SET_DEFAULT_ASSIGNEE.getKey()); |
| 316 |
if (attributeDefaultAssignee != null) { |
| 317 |
attributeDefaultAssignee.setValue("1"); //$NON-NLS-1$ |
| 318 |
refresh(attributeDefaultAssignee); |
| 319 |
} |
| 320 |
} |
| 321 |
} |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 172 |
} |
325 |
} |