|
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 |
private 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 |
private AbstractAttributeEditor getEditorForAttribute(TaskAttribute attribute) { |
| 255 |
return attributeEditorMap.get(attribute); |
| 256 |
} |
| 257 |
|
| 258 |
// /** |
| 259 |
// * @since 3.1 |
| 260 |
// */ |
| 261 |
// public void refresh() { |
| 262 |
// try { |
| 263 |
// showEditorBusy(true); |
| 264 |
// for (AbstractAttributeEditor abstractAttributeEditor : attributeEditorMap.values()) { |
| 265 |
// try { |
| 266 |
// abstractAttributeEditor.refresh(); |
| 267 |
// } catch (UnsupportedOperationException e) { |
| 268 |
// // ignore |
| 269 |
// } |
| 270 |
// } |
| 271 |
// } finally { |
| 272 |
// showEditorBusy(false); |
| 273 |
// } |
| 274 |
// } |
| 275 |
|
| 276 |
public void refresh(TaskAttribute attributeComponent) { |
| 277 |
AbstractAttributeEditor editor = getEditorForAttribute(attributeComponent); |
| 278 |
if (editor != null) { |
| 279 |
try { |
| 280 |
editor.refresh(); |
| 281 |
} catch (UnsupportedOperationException e) { |
| 282 |
// ignore |
| 283 |
} |
| 284 |
} |
| 285 |
} |
| 286 |
|
| 287 |
private class ProductSelectionListener extends TaskDataModelListener { |
| 288 |
@Override |
| 289 |
public void attributeChanged(TaskDataModelEvent event) { |
| 290 |
TaskAttribute taskAttribute = event.getTaskAttribute(); |
| 291 |
if (taskAttribute != null) { |
| 292 |
if (taskAttribute.getId().equals(BugzillaAttribute.PRODUCT.getKey())) { |
| 293 |
RepositoryConfiguration repositoryConfiguration = null; |
| 294 |
try { |
| 295 |
repositoryConfiguration = BugzillaCorePlugin.getRepositoryConfiguration( |
| 296 |
getModel().getTaskRepository(), false, new NullProgressMonitor()); |
| 297 |
} catch (CoreException e) { |
| 298 |
StatusHandler.log(new RepositoryStatus(getTaskRepository(), IStatus.ERROR, |
| 299 |
BugzillaUiPlugin.ID_PLUGIN, 0, "Failed to obtain repository configuration", e)); //$NON-NLS-1$ |
| 300 |
getTaskEditor().setMessage("Problem occured when updating attributes", IMessageProvider.ERROR); //$NON-NLS-1$ |
| 301 |
return; |
| 302 |
} |
| 303 |
|
| 304 |
TaskAttribute attributeComponent = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 305 |
BugzillaAttribute.COMPONENT.getKey()); |
| 306 |
if (attributeComponent != null) { |
| 307 |
List<String> optionValues = repositoryConfiguration.getComponents(taskAttribute.getValue()); |
| 308 |
Collections.sort(optionValues); |
| 309 |
attributeComponent.clearOptions(); |
| 310 |
for (String option : optionValues) { |
| 311 |
attributeComponent.putOption(option, option); |
| 312 |
} |
| 313 |
if (optionValues.size() == 1) { |
| 314 |
attributeComponent.setValue(optionValues.get(0)); |
| 315 |
} else { |
| 316 |
attributeComponent.setValue(""); //$NON-NLS-1$ |
| 317 |
} |
| 318 |
refresh(attributeComponent); |
| 319 |
} |
| 320 |
|
| 321 |
TaskAttribute attributeTargetMilestone = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 322 |
BugzillaAttribute.TARGET_MILESTONE.getKey()); |
| 323 |
if (attributeTargetMilestone != null) { |
| 324 |
List<String> optionValues = repositoryConfiguration.getTargetMilestones(taskAttribute.getValue()); |
| 325 |
Collections.sort(optionValues); |
| 326 |
attributeTargetMilestone.clearOptions(); |
| 327 |
for (String option : optionValues) { |
| 328 |
attributeTargetMilestone.putOption(option, option); |
| 329 |
} |
| 330 |
if (optionValues.size() == 1) { |
| 331 |
attributeTargetMilestone.setValue(optionValues.get(0)); |
| 332 |
} else { |
| 333 |
attributeTargetMilestone.setValue("---"); //$NON-NLS-1$ |
| 334 |
} |
| 335 |
refresh(attributeTargetMilestone); |
| 336 |
} |
| 337 |
|
| 338 |
TaskAttribute attributeVersion = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 339 |
BugzillaAttribute.VERSION.getKey()); |
| 340 |
if (attributeVersion != null) { |
| 341 |
List<String> optionValues = repositoryConfiguration.getVersions(taskAttribute.getValue()); |
| 342 |
Collections.sort(optionValues); |
| 343 |
attributeVersion.clearOptions(); |
| 344 |
for (String option : optionValues) { |
| 345 |
attributeVersion.putOption(option, option); |
| 346 |
} |
| 347 |
if (optionValues.size() == 1) { |
| 348 |
attributeVersion.setValue(optionValues.get(0)); |
| 349 |
} else { |
| 350 |
attributeVersion.setValue("unspecified"); //$NON-NLS-1$ |
| 351 |
} |
| 352 |
refresh(attributeVersion); |
| 353 |
} |
| 354 |
|
| 355 |
TaskAttribute attributeDefaultAssignee = taskAttribute.getTaskData().getRoot().getMappedAttribute( |
| 356 |
BugzillaAttribute.SET_DEFAULT_ASSIGNEE.getKey()); |
| 357 |
if (attributeDefaultAssignee != null) { |
| 358 |
attributeDefaultAssignee.setValue("1"); //$NON-NLS-1$ |
| 359 |
refresh(attributeDefaultAssignee); |
| 360 |
} |
| 361 |
|
| 362 |
/* |
| 363 |
* add confirm_product_change to avoid verification page on submit |
| 364 |
*/ |
| 365 |
TaskAttribute attributeConfirmeProductChange = taskAttribute.getTaskData() |
| 366 |
.getRoot() |
| 367 |
.getMappedAttribute(BugzillaAttribute.CONFIRM_PRODUCT_CHANGE.getKey()); |
| 368 |
if (attributeConfirmeProductChange == null) { |
| 369 |
attributeConfirmeProductChange = BugzillaTaskDataHandler.createAttribute( |
| 370 |
taskAttribute.getTaskData().getRoot(), BugzillaAttribute.CONFIRM_PRODUCT_CHANGE); |
| 371 |
} |
| 372 |
if (attributeConfirmeProductChange != null) { |
| 373 |
attributeConfirmeProductChange.setValue("1"); //$NON-NLS-1$ |
| 374 |
} |
| 375 |
} |
| 376 |
} |
| 377 |
} |
| 378 |
} |
| 379 |
|
| 196 |
} |
380 |
} |