|
Lines 11-27
Link Here
|
| 11 |
|
11 |
|
| 12 |
package org.eclipse.mylyn.internal.bugzilla.ui.editor; |
12 |
package org.eclipse.mylyn.internal.bugzilla.ui.editor; |
| 13 |
|
13 |
|
|
|
14 |
import java.util.Collections; |
| 15 |
import java.util.HashMap; |
| 16 |
import java.util.List; |
| 17 |
import java.util.Map; |
| 14 |
import java.util.Set; |
18 |
import java.util.Set; |
| 15 |
|
19 |
|
| 16 |
import org.eclipse.core.runtime.CoreException; |
20 |
import org.eclipse.core.runtime.CoreException; |
|
|
21 |
import org.eclipse.core.runtime.IStatus; |
| 22 |
import org.eclipse.core.runtime.NullProgressMonitor; |
| 17 |
import org.eclipse.jface.dialogs.IMessageProvider; |
23 |
import org.eclipse.jface.dialogs.IMessageProvider; |
|
|
24 |
import org.eclipse.mylyn.commons.core.StatusHandler; |
| 18 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; |
25 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; |
| 19 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; |
26 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; |
| 20 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; |
27 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField; |
|
|
28 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; |
| 29 |
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; |
| 21 |
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; |
30 |
import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; |
|
|
31 |
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; |
| 32 |
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin; |
| 33 |
import org.eclipse.mylyn.tasks.core.RepositoryStatus; |
| 22 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
34 |
import org.eclipse.mylyn.tasks.core.data.TaskAttribute; |
| 23 |
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; |
35 |
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData; |
| 24 |
import org.eclipse.mylyn.tasks.core.data.TaskData; |
36 |
import org.eclipse.mylyn.tasks.core.data.TaskData; |
|
|
37 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModel; |
| 38 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModelEvent; |
| 39 |
import org.eclipse.mylyn.tasks.core.data.TaskDataModelListener; |
| 25 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
40 |
import org.eclipse.mylyn.tasks.ui.TasksUi; |
| 26 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
41 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor; |
| 27 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
42 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage; |
|
Lines 29-34
Link Here
|
| 29 |
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; |
44 |
import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory; |
| 30 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
45 |
import org.eclipse.mylyn.tasks.ui.editors.LayoutHint; |
| 31 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
46 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
|
|
47 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorInput; |
| 32 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; |
48 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor; |
| 33 |
|
49 |
|
| 34 |
/** |
50 |
/** |
|
Lines 41-48
Link Here
|
| 41 |
|
57 |
|
| 42 |
public static final String ID_PART_BUGZILLA_FLAGS = "org.eclipse.mylyn.bugzilla.ui.editors.part.flags"; //$NON-NLS-1$ |
58 |
public static final String ID_PART_BUGZILLA_FLAGS = "org.eclipse.mylyn.bugzilla.ui.editors.part.flags"; //$NON-NLS-1$ |
| 43 |
|
59 |
|
|
|
60 |
private final Map<TaskAttribute, AbstractAttributeEditor> attributeEditorMap; |
| 61 |
|
| 62 |
private TaskDataModelListener productListener; |
| 63 |
|
| 44 |
public BugzillaTaskEditorPage(TaskEditor editor) { |
64 |
public BugzillaTaskEditorPage(TaskEditor editor) { |
| 45 |
super(editor, BugzillaCorePlugin.CONNECTOR_KIND); |
65 |
this(editor, BugzillaCorePlugin.CONNECTOR_KIND); |
| 46 |
} |
66 |
} |
| 47 |
|
67 |
|
| 48 |
/** |
68 |
/** |
|
Lines 53-58
Link Here
|
| 53 |
*/ |
73 |
*/ |
| 54 |
public BugzillaTaskEditorPage(TaskEditor editor, String connectorKind) { |
74 |
public BugzillaTaskEditorPage(TaskEditor editor, String connectorKind) { |
| 55 |
super(editor, connectorKind); |
75 |
super(editor, connectorKind); |
|
|
76 |
this.attributeEditorMap = new HashMap<TaskAttribute, AbstractAttributeEditor>(); |
| 56 |
} |
77 |
} |
| 57 |
|
78 |
|
| 58 |
@Override |
79 |
@Override |
|
Lines 138-144
Link Here
|
| 138 |
} |
159 |
} |
| 139 |
}); |
160 |
}); |
| 140 |
} |
161 |
} |
| 141 |
|
162 |
BugzillaTaskEditorPage.this.addToAttributeEditorMap(taskAttribute, editor); |
| 142 |
return editor; |
163 |
return editor; |
| 143 |
} |
164 |
} |
| 144 |
}; |
165 |
}; |
|
Lines 193-196
Link Here
|
| 193 |
super.doSubmit(); |
214 |
super.doSubmit(); |
| 194 |
} |
215 |
} |
| 195 |
|
216 |
|
|
|
217 |
@Override |
| 218 |
protected void createParts() { |
| 219 |
attributeEditorMap.clear(); |
| 220 |
super.createParts(); |
| 221 |
} |
| 222 |
|
| 223 |
@Override |
| 224 |
protected TaskDataModel createModel(TaskEditorInput input) throws CoreException { |
| 225 |
TaskDataModel model = super.createModel(input); |
| 226 |
BugzillaVersion bugzillaVersion = null; |
| 227 |
RepositoryConfiguration repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration( |
| 228 |
input.getTaskRepository(), false, new NullProgressMonitor()); |
| 229 |
if (repositoryConfiguration != null) { |
| 230 |
bugzillaVersion = repositoryConfiguration.getInstallVersion(); |
| 231 |
} else { |
| 232 |
bugzillaVersion = BugzillaVersion.MIN_VERSION; |
| 233 |
} |
| 234 |
if (bugzillaVersion.compareTo(BugzillaVersion.BUGZILLA_3_0) >= 0) { |
| 235 |
productListener = new ProductSelectionListener(); |
| 236 |
model.addModelListener(productListener); |
| 237 |
} |
| 238 |
return model; |
| 239 |
} |
| 240 |
|
| 241 |
/** |
| 242 |
* @since 3.1 |
| 243 |
*/ |
| 244 |
public void addToAttributeEditorMap(TaskAttribute attribute, AbstractAttributeEditor editor) { |
| 245 |
if (attributeEditorMap.containsKey(attribute)) { |
| 246 |
attributeEditorMap.remove(attribute); |
| 247 |
} |
| 248 |
attributeEditorMap.put(attribute, editor); |
| 249 |
} |
| 250 |
|
| 251 |
/** |
| 252 |
* @since 3.1 |
| 253 |
*/ |
| 254 |
public AbstractAttributeEditor getEditorForAttribute(TaskAttribute attribute) { |
| 255 |
return attributeEditorMap.get(attribute); |
| 256 |
} |
| 257 |
|
| 258 |
/** |
| 259 |
* @since 3.1 |
| 260 |
*/ |
| 261 |
public Map<TaskAttribute, AbstractAttributeEditor> getAttributeEditorMap() { |
| 262 |
return attributeEditorMap; |
| 263 |
} |
| 264 |
|
| 265 |
/** |
| 266 |
* @since 3.1 |
| 267 |
*/ |
| 268 |
public void refresh() { |
| 269 |
try { |
| 270 |
showEditorBusy(true); |
| 271 |
for (AbstractAttributeEditor abstractAttributeEditor : attributeEditorMap.values()) { |
| 272 |
try { |
| 273 |
abstractAttributeEditor.refresh(); |
| 274 |
} catch (UnsupportedOperationException e) { |
| 275 |
// ignore |
| 276 |
} |
| 277 |
} |
| 278 |
} finally { |
| 279 |
showEditorBusy(false); |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
public void refresh(TaskAttribute attributeComponent) { |
| 284 |
AbstractAttributeEditor editor = getEditorForAttribute(attributeComponent); |
| 285 |
if (editor != null) { |
| 286 |
try { |
| 287 |
editor.refresh(); |
| 288 |
} catch (UnsupportedOperationException e) { |
| 289 |
// ignore |
| 290 |
} |
| 291 |
} |
| 292 |
} |
| 293 |
|
| 294 |
private class ProductSelectionListener extends TaskDataModelListener { |
| 295 |
@Override |
| 296 |
public void attributeChanged(TaskDataModelEvent event) { |
| 297 |
TaskAttribute taskAttribute = event.getTaskAttribute(); |
| 298 |
if (taskAttribute != null) { |
| 299 |
if (taskAttribute.getId().equals(BugzillaAttribute.PRODUCT.getKey())) { |
| 300 |
RepositoryConfiguration repositoryConfiguration = null; |
| 301 |
try { |
| 302 |
repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration( |
| 303 |
getModel().getTaskRepository(), false, new NullProgressMonitor()); |
| 304 |
} catch (CoreException e) { |
| 305 |
StatusHandler.log(new RepositoryStatus(getTaskRepository(), IStatus.ERROR, |
| 306 |
BugzillaUiPlugin.ID_PLUGIN, 0, "Failed to obtain repository configuration", e)); //$NON-NLS-1$ |
| 307 |
getTaskEditor().setMessage("Problem occured when updating attributes", IMessageProvider.ERROR); //$NON-NLS-1$ |
| 308 |
return; |
| 309 |
} |
| 310 |
|
| 311 |
TaskAttribute attributeComponent = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 312 |
BugzillaAttribute.COMPONENT.getKey()); |
| 313 |
if (attributeComponent != null) { |
| 314 |
List<String> optionValues = repositoryConfiguration.getComponents(taskAttribute.getValue()); |
| 315 |
Collections.sort(optionValues); |
| 316 |
attributeComponent.clearOptions(); |
| 317 |
for (String option : optionValues) { |
| 318 |
attributeComponent.putOption(option, option); |
| 319 |
} |
| 320 |
if (optionValues.size() == 1) { |
| 321 |
attributeComponent.setValue(optionValues.get(0)); |
| 322 |
} else { |
| 323 |
attributeComponent.setValue(""); //$NON-NLS-1$ |
| 324 |
} |
| 325 |
refresh(attributeComponent); |
| 326 |
} |
| 327 |
|
| 328 |
TaskAttribute attributeTargetMilestone = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 329 |
BugzillaAttribute.TARGET_MILESTONE.getKey()); |
| 330 |
if (attributeTargetMilestone != null) { |
| 331 |
List<String> optionValues = repositoryConfiguration.getTargetMilestones(taskAttribute.getValue()); |
| 332 |
Collections.sort(optionValues); |
| 333 |
attributeTargetMilestone.clearOptions(); |
| 334 |
for (String option : optionValues) { |
| 335 |
attributeTargetMilestone.putOption(option, option); |
| 336 |
} |
| 337 |
if (optionValues.size() == 1) { |
| 338 |
attributeTargetMilestone.setValue(optionValues.get(0)); |
| 339 |
} else { |
| 340 |
attributeTargetMilestone.setValue("---"); //$NON-NLS-1$ |
| 341 |
} |
| 342 |
refresh(attributeTargetMilestone); |
| 343 |
} |
| 344 |
|
| 345 |
TaskAttribute attributeDefaultAssignee = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 346 |
BugzillaAttribute.SET_DEFAULT_ASSIGNEE.getKey()); |
| 347 |
if (attributeDefaultAssignee != null) { |
| 348 |
attributeDefaultAssignee.setValue("1"); //$NON-NLS-1$ |
| 349 |
refresh(attributeDefaultAssignee); |
| 350 |
} |
| 351 |
|
| 352 |
/* |
| 353 |
* add confirm_product_change to avoid verification page on submit |
| 354 |
*/ |
| 355 |
TaskAttribute attributeConfirmeProductChange = taskAttribute.getTaskData() |
| 356 |
.getRoot() |
| 357 |
.getMappedAttribute(BugzillaAttribute.CONFIRM_PRODUCT_CHANGE.getKey()); |
| 358 |
if (attributeConfirmeProductChange == null) { |
| 359 |
// attributeConfirmeProductChange = taskAttribute.getTaskData().getRoot().createAttribute( |
| 360 |
// BugzillaAttribute.CONFIRM_PRODUCT_CHANGE.getKey()); |
| 361 |
BugzillaTaskDataHandler.createAttribute(taskAttribute.getTaskData().getRoot(), |
| 362 |
BugzillaAttribute.CONFIRM_PRODUCT_CHANGE); |
| 363 |
attributeConfirmeProductChange = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 364 |
BugzillaAttribute.CONFIRM_PRODUCT_CHANGE.getKey()); |
| 365 |
} |
| 366 |
if (attributeConfirmeProductChange != null) { |
| 367 |
attributeConfirmeProductChange.setValue("1"); |
| 368 |
} |
| 369 |
} |
| 370 |
} |
| 371 |
} |
| 372 |
} |
| 373 |
|
| 196 |
} |
374 |
} |