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