View | Details | Raw Unified | Return to bug 226851 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/tasks/ui/editors/AbstractRepositoryTaskEditor.java (-1 / +1 lines)
Lines 245-251 Link Here
245
245
246
	protected static final String CONTEXT_MENU_ID = "#MylynRepositoryEditor";
246
	protected static final String CONTEXT_MENU_ID = "#MylynRepositoryEditor";
247
247
248
	private FormToolkit toolkit;
248
	protected FormToolkit toolkit;
249
249
250
	private ScrolledForm form;
250
	private ScrolledForm form;
251
251
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditor.java (-36 / +219 lines)
Lines 86-92 Link Here
86
	private static final String LABEL_TIME_TRACKING = "Bugzilla Time Tracking";
86
	private static final String LABEL_TIME_TRACKING = "Bugzilla Time Tracking";
87
87
88
	private static final String LABEL_CUSTOM_FIELD = "Custom Fields";
88
	private static final String LABEL_CUSTOM_FIELD = "Custom Fields";
89
	
89
90
	protected Text keywordsText;
90
	protected Text keywordsText;
91
91
92
	protected Text estimateText;
92
	protected Text estimateText;
Lines 120-126 Link Here
120
		// config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
120
		// config.setRightImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT));
121
		// compareInput = new BugzillaCompareInput(config);
121
		// compareInput = new BugzillaCompareInput(config);
122
	}
122
	}
123
	
123
124
	@Override
124
	@Override
125
	protected boolean supportsCommentSort() {
125
	protected boolean supportsCommentSort() {
126
		return false;
126
		return false;
Lines 129-143 Link Here
129
	@Override
129
	@Override
130
	protected void createCustomAttributeLayout(Composite composite) {
130
	protected void createCustomAttributeLayout(Composite composite) {
131
		RepositoryTaskAttribute attribute = null;
131
		RepositoryTaskAttribute attribute = null;
132
		int customFieldsAnz = 0;
132
		try {
133
		try {
133
			RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(this.repository,
134
			RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(this.repository,
134
					false, new NullProgressMonitor());
135
					false, new NullProgressMonitor());
135
		
136
136
			if (configuration != null) {
137
			if (configuration != null) {
137
				List<BugzillaCustomField> customFields = configuration.getCustomFields();
138
				List<BugzillaCustomField> customFields = configuration.getCustomFields();
138
				if (!customFields.isEmpty()) {
139
				if (!customFields.isEmpty()) {
139
					for (BugzillaCustomField bugzillaCustomField : customFields) {
140
					for (BugzillaCustomField bugzillaCustomField : customFields) {
140
						List<String> optionList = bugzillaCustomField.getOptions();
141
						if (!bugzillaCustomField.isEnterBug()) {
142
							continue;
143
						}
144
						customFieldsAnz++;
141
						attribute = this.taskData.getAttribute(bugzillaCustomField.getName());
145
						attribute = this.taskData.getAttribute(bugzillaCustomField.getName());
142
						if (attribute == null) {
146
						if (attribute == null) {
143
							RepositoryTaskAttribute newattribute = new RepositoryTaskAttribute(
147
							RepositoryTaskAttribute newattribute = new RepositoryTaskAttribute(
Lines 148-195 Link Here
148
						final RepositoryTaskAttribute cfattribute = this.taskData.getAttribute(bugzillaCustomField.getName());
152
						final RepositoryTaskAttribute cfattribute = this.taskData.getAttribute(bugzillaCustomField.getName());
149
						Label label = createLabel(composite, cfattribute);
153
						Label label = createLabel(composite, cfattribute);
150
						GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
154
						GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
151
						if (optionList != null && !optionList.isEmpty()) {
155
152
							GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
156
						switch (bugzillaCustomField.getType()) {
153
							data.horizontalSpan = 1;
157
						case 1: // Free Text
154
							final CCombo attributeCombo = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY);
158
							Text freeText = createTextField(composite, cfattribute, SWT.FLAT);
155
							getManagedForm().getToolkit().adapt(attributeCombo, true, true);
159
							GridData freeTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
156
							attributeCombo.setFont(TEXT_FONT);
160
							freeTextData.horizontalSpan = 1;
157
							attributeCombo.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
161
							freeTextData.verticalSpan = 1;
162
							if (hasChanged(cfattribute)) {
163
								freeText.setBackground(getColorIncoming());
164
							}
165
							freeText.setLayoutData(freeTextData);
166
							break;
167
						case 2: // Drop Down
168
							List<String> optionList = bugzillaCustomField.getOptions();
169
							GridData dropDownData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
170
							dropDownData.horizontalSpan = 1;
171
							final CCombo dropDown = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY);
172
							getManagedForm().getToolkit().adapt(dropDown, true, true);
173
							dropDown.setFont(TEXT_FONT);
174
							dropDown.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
158
							if (hasChanged(cfattribute)) {
175
							if (hasChanged(cfattribute)) {
159
								attributeCombo.setBackground(getColorIncoming());
176
								dropDown.setBackground(getColorIncoming());
160
							}
177
							}
161
							attributeCombo.setLayoutData(data);
178
							dropDown.setLayoutData(dropDownData);
162
179
163
							for (String val : optionList) {
180
							for (String val : optionList) {
164
								if (val != null) {
181
								if (val != null) {
165
									attributeCombo.add(val);
182
									dropDown.add(val);
166
								}
183
								}
167
							}
184
							}
168
							String value = cfattribute.getValue();
185
							String value = cfattribute.getValue();
169
							if (value == null) {
186
							if (value == null) {
170
								value = "";
187
								value = "";
171
							}
188
							}
172
							if (attributeCombo.indexOf(value) != -1) {
189
							if (dropDown.indexOf(value) != -1) {
173
								attributeCombo.select(attributeCombo.indexOf(value));
190
								dropDown.select(dropDown.indexOf(value));
174
							}
191
							}
175
							attributeCombo.clearSelection();
192
							dropDown.clearSelection();
176
							attributeCombo.addSelectionListener(new SelectionAdapter() {
193
							dropDown.addSelectionListener(new SelectionAdapter() {
177
								@Override
194
								@Override
178
								public void widgetSelected(SelectionEvent event) {
195
								public void widgetSelected(SelectionEvent event) {
179
									if (attributeCombo.getSelectionIndex() > -1) {
196
									if (dropDown.getSelectionIndex() > -1) {
180
										String sel = attributeCombo.getItem(attributeCombo.getSelectionIndex());
197
										String sel = dropDown.getItem(dropDown.getSelectionIndex());
181
										cfattribute.setValue(sel);
198
										cfattribute.setValue(sel);
182
										attributeChanged(cfattribute);
199
										attributeChanged(cfattribute);
183
										attributeCombo.clearSelection();
200
										dropDown.clearSelection();
184
									}
201
									}
185
								}
202
								}
186
							});
203
							});
187
						} else {
204
							break;
188
							Text cfField = createTextField(composite, cfattribute, SWT.FLAT);
205
						case 3: // Multiple-Selection Box
189
							GridDataFactory.fillDefaults().hint(135, SWT.DEFAULT).applyTo(cfField);
206
							final org.eclipse.swt.widgets.List multiSelect;
207
							List<String> multiSelectOptionList = bugzillaCustomField.getOptions();
208
							multiSelect = new org.eclipse.swt.widgets.List(composite, SWT.MULTI | SWT.V_SCROLL);// SWT.BORDER
209
							multiSelect.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
210
							multiSelect.setFont(TEXT_FONT);
211
							GridData multiSelectData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
212
							multiSelectData.horizontalSpan = 1;
213
							multiSelectData.heightHint = 95;
214
							multiSelect.setLayoutData(multiSelectData);
215
							if (hasChanged(cfattribute)) {
216
								multiSelect.setBackground(getColorIncoming());
217
							}
218
							if (multiSelectOptionList != null) {
219
								for (String cc : multiSelectOptionList) {
220
									multiSelect.add(cc);
221
								}
222
							}
223
							java.util.List<String> multiSelectValues = cfattribute.getValues();
224
							if (multiSelectValues != null) {
225
								for (String item : multiSelectValues) {
226
									int i = multiSelect.indexOf(item);
227
									if (i != -1) {
228
										multiSelect.select(i);
229
									}
230
								}
231
							}
232
233
							multiSelect.addSelectionListener(new SelectionListener() {
234
235
								public void widgetSelected(SelectionEvent e) {
236
									for (String selected : multiSelect.getItems()) {
237
										int index = multiSelect.indexOf(selected);
238
										if (multiSelect.isSelected(index)) {
239
											List<String> remove = cfattribute.getValues();
240
											if (!remove.contains(selected)) {
241
												cfattribute.addValue(selected);
242
											}
243
										} else {
244
											cfattribute.removeValue(selected);
245
										}
246
									}
247
									attributeChanged(cfattribute);
248
								}
249
250
								public void widgetDefaultSelected(SelectionEvent e) {
251
								}
252
							});
253
							GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
254
							break;
255
						case 4: // Large Text Box
256
							Text largeText = createTextField(composite, cfattribute, SWT.FLAT);
257
							GridData largeTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
258
							largeTextData.horizontalSpan = 1;
259
							largeTextData.heightHint = 95;
260
							largeText.setLayoutData(largeTextData);
261
							break;
262
						case 5: // Date/Time
263
							Composite dateWithClear = toolkit.createComposite(composite);
264
							GridLayout layout = new GridLayout(2, false);
265
							layout.marginWidth = 1;
266
							dateWithClear.setLayout(layout);
267
268
							final DatePicker dateTimePicker = new DatePicker(dateWithClear, /* SWT.NONE */SWT.BORDER,
269
									cfattribute.getValue(), true);
270
							dateTimePicker.setFont(TEXT_FONT);
271
							dateTimePicker.setDatePattern("yyyy-MM-dd hh:mm:ss");
272
							if (hasChanged(attribute)) {
273
								dateTimePicker.setBackground(getColorIncoming());
274
							}
275
							dateTimePicker.addPickerSelectionListener(new SelectionListener() {
276
277
								public void widgetDefaultSelected(SelectionEvent e) {
278
									// ignore
279
								}
280
281
								public void widgetSelected(SelectionEvent e) {
282
									Calendar cal = dateTimePicker.getDate();
283
									if (cal != null) {
284
										Date d = cal.getTime();
285
										SimpleDateFormat f = (SimpleDateFormat) SimpleDateFormat.getDateInstance();
286
										f.applyPattern("yyyy-MM-dd hh:mm:ss");
287
288
										cfattribute.setValue(f.format(d));
289
										attributeChanged(cfattribute);
290
										// TODO goes dirty even if user presses cancel
291
										// markDirty(true);
292
									} else {
293
										cfattribute.setValue("");
294
										attributeChanged(cfattribute);
295
										dateTimePicker.setDate(null);
296
									}
297
								}
298
							});
299
300
							ImageHyperlink clearDeadlineDate = toolkit.createImageHyperlink(dateWithClear, SWT.NONE);
301
							clearDeadlineDate.setImage(TasksUiImages.getImage(TasksUiImages.REMOVE));
302
							clearDeadlineDate.setToolTipText("Clear");
303
							clearDeadlineDate.addHyperlinkListener(new HyperlinkAdapter() {
304
305
								@Override
306
								public void linkActivated(HyperlinkEvent e) {
307
									cfattribute.setValue("");
308
									attributeChanged(cfattribute);
309
									dateTimePicker.setDate(null);
310
								}
311
							});
312
313
							break;
314
						default:
315
							List<String> optionListDefault = bugzillaCustomField.getOptions();
316
							if (optionListDefault != null && !optionListDefault.isEmpty()) {
317
								GridData dropDownDefaultData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
318
								dropDownDefaultData.horizontalSpan = 1;
319
								final CCombo dropDownDefault = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY);
320
								getManagedForm().getToolkit().adapt(dropDownDefault, true, true);
321
								dropDownDefault.setFont(TEXT_FONT);
322
								dropDownDefault.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
323
								if (hasChanged(cfattribute)) {
324
									dropDownDefault.setBackground(getColorIncoming());
325
								}
326
								dropDownDefault.setLayoutData(dropDownDefaultData);
327
328
								for (String valDefault : optionListDefault) {
329
									if (valDefault != null) {
330
										dropDownDefault.add(valDefault);
331
									}
332
								}
333
								String dropDownValue = cfattribute.getValue();
334
								if (dropDownValue == null) {
335
									dropDownValue = "";
336
								}
337
								if (dropDownDefault.indexOf(dropDownValue) != -1) {
338
									dropDownDefault.select(dropDownDefault.indexOf(dropDownValue));
339
								}
340
								dropDownDefault.clearSelection();
341
								dropDownDefault.addSelectionListener(new SelectionAdapter() {
342
									@Override
343
									public void widgetSelected(SelectionEvent event) {
344
										if (dropDownDefault.getSelectionIndex() > -1) {
345
											String sel = dropDownDefault.getItem(dropDownDefault.getSelectionIndex());
346
											cfattribute.setValue(sel);
347
											attributeChanged(cfattribute);
348
											dropDownDefault.clearSelection();
349
										}
350
									}
351
								});								
352
							} else {
353
								Text freeTextDefault = createTextField(composite, cfattribute, SWT.FLAT);
354
								GridData freeTextDefaultData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
355
								freeTextDefaultData.horizontalSpan = 1;
356
								freeTextDefaultData.verticalSpan = 1;
357
								if (hasChanged(cfattribute)) {
358
									freeTextDefault.setBackground(getColorIncoming());
359
								}
360
								freeTextDefault.setLayoutData(freeTextDefaultData);
361
							}
362
							break;
190
						}
363
						}
191
					}
364
					}
192
193
					getManagedForm().getToolkit().paintBordersFor(composite);
365
					getManagedForm().getToolkit().paintBordersFor(composite);
194
				}
366
				}
195
			}
367
			}
Lines 197-211 Link Here
197
			// ignore
369
			// ignore
198
		}
370
		}
199
371
372
		if (customFieldsAnz % 2 == 1) {
373
			@SuppressWarnings("unused")
374
			Label label = new Label(composite, SWT.None);
375
			label = new Label(composite, SWT.None);
376
		}
377
200
		attribute = this.taskData.getAttribute(BugzillaReportElement.DEPENDSON.getKeyString());
378
		attribute = this.taskData.getAttribute(BugzillaReportElement.DEPENDSON.getKeyString());
201
		if (attribute != null && !attribute.isReadOnly()) {
379
		if (attribute != null && !attribute.isReadOnly()) {
202
			Label label = createLabel(composite, attribute);
380
			Label label = createLabel(composite, attribute);
203
			GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
381
			GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
204
			
382
205
			Composite textFieldComposite = getManagedForm().getToolkit().createComposite(composite);
383
			Composite textFieldComposite = getManagedForm().getToolkit().createComposite(composite);
206
			GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).applyTo(textFieldComposite);
384
			GridDataFactory.swtDefaults().align(SWT.FILL, SWT.CENTER).applyTo(textFieldComposite);
207
			GridLayoutFactory.swtDefaults().margins(1, 3).spacing(0, 3).applyTo(textFieldComposite);
385
			GridLayoutFactory.swtDefaults().margins(1, 3).spacing(0, 3).applyTo(textFieldComposite);
208
			
386
209
			GridData textData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
387
			GridData textData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL);
210
			textData.horizontalSpan = 1;
388
			textData.horizontalSpan = 1;
211
			textData.widthHint = 135;
389
			textData.widthHint = 135;
Lines 351-358 Link Here
351
			for (String bugNumber : values.split(",")) {
529
			for (String bugNumber : values.split(",")) {
352
				final String bugId = bugNumber.trim();
530
				final String bugId = bugNumber.trim();
353
				final String bugUrl = repository.getRepositoryUrl() + IBugzillaConstants.URL_GET_SHOW_BUG + bugId;
531
				final String bugUrl = repository.getRepositoryUrl() + IBugzillaConstants.URL_GET_SHOW_BUG + bugId;
354
				final AbstractTask task = TasksUi.getTaskListManager().getTaskList().getTask(repository.getRepositoryUrl(),
532
				final AbstractTask task = TasksUi.getTaskListManager().getTaskList().getTask(
355
						bugId);
533
						repository.getRepositoryUrl(), bugId);
356
				createTaskListHyperlink(hyperlinksComposite, bugId, bugUrl, task);
534
				createTaskListHyperlink(hyperlinksComposite, bugId, bugUrl, task);
357
			}
535
			}
358
		}
536
		}
Lines 414-420 Link Here
414
			operation = BUGZILLA_OPERATION.valueOf(repositoryOperation.getKnobName());
592
			operation = BUGZILLA_OPERATION.valueOf(repositoryOperation.getKnobName());
415
		} catch (RuntimeException e) {
593
		} catch (RuntimeException e) {
416
			// FIXME: ?
594
			// FIXME: ?
417
			StatusHandler.log(new Status(IStatus.INFO, BugzillaUiPlugin.PLUGIN_ID, "Unrecognized operation: " + repositoryOperation.getKnobName(), e));
595
			StatusHandler.log(new Status(IStatus.INFO, BugzillaUiPlugin.PLUGIN_ID, "Unrecognized operation: "
596
					+ repositoryOperation.getKnobName(), e));
418
			operation = null;
597
			operation = null;
419
		}
598
		}
420
599
Lines 623-629 Link Here
623
802
624
				List<String> validKeywords = new ArrayList<String>();
803
				List<String> validKeywords = new ArrayList<String>();
625
				try {
804
				try {
626
					validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(repository, false, new NullProgressMonitor()).getKeywords();
805
					validKeywords = BugzillaCorePlugin.getRepositoryConfiguration(repository, false,
806
							new NullProgressMonitor()).getKeywords();
627
				} catch (Exception ex) {
807
				} catch (Exception ex) {
628
					// ignore
808
					// ignore
629
				}
809
				}
Lines 672-678 Link Here
672
			@Override
852
			@Override
673
			public void linkActivated(HyperlinkEvent e) {
853
			public void linkActivated(HyperlinkEvent e) {
674
				if (BugzillaTaskEditor.this.getEditor() instanceof TaskEditor) {
854
				if (BugzillaTaskEditor.this.getEditor() instanceof TaskEditor) {
675
					TasksUiUtil.openUrl(repository.getRepositoryUrl() + IBugzillaConstants.URL_SHOW_VOTES + taskData.getTaskId());
855
					TasksUiUtil.openUrl(repository.getRepositoryUrl() + IBugzillaConstants.URL_SHOW_VOTES
856
							+ taskData.getTaskId());
676
				}
857
				}
677
			}
858
			}
678
		});
859
		});
Lines 682-688 Link Here
682
			@Override
863
			@Override
683
			public void linkActivated(HyperlinkEvent e) {
864
			public void linkActivated(HyperlinkEvent e) {
684
				if (BugzillaTaskEditor.this.getEditor() instanceof TaskEditor) {
865
				if (BugzillaTaskEditor.this.getEditor() instanceof TaskEditor) {
685
					TasksUiUtil.openUrl(repository.getRepositoryUrl() + IBugzillaConstants.URL_VOTE + taskData.getTaskId());
866
					TasksUiUtil.openUrl(repository.getRepositoryUrl() + IBugzillaConstants.URL_VOTE
867
							+ taskData.getTaskId());
686
				}
868
				}
687
			}
869
			}
688
		});
870
		});
Lines 711-717 Link Here
711
		if (assignedAttribute != null) {
893
		if (assignedAttribute != null) {
712
			String bugzillaVersion;
894
			String bugzillaVersion;
713
			try {
895
			try {
714
				bugzillaVersion = BugzillaCorePlugin.getRepositoryConfiguration(repository, false, new NullProgressMonitor()).getInstallVersion();
896
				bugzillaVersion = BugzillaCorePlugin.getRepositoryConfiguration(repository, false,
897
						new NullProgressMonitor()).getInstallVersion();
715
			} catch (CoreException e1) {
898
			} catch (CoreException e1) {
716
				// ignore
899
				// ignore
717
				bugzillaVersion = "2.18";
900
				bugzillaVersion = "2.18";
Lines 800-808 Link Here
800
			if (haveRealName) {
983
			if (haveRealName) {
801
				textField.setText(textField.getText() + " <"
984
				textField.setText(textField.getText() + " <"
802
						+ taskData.getAttributeValue(BugzillaReportElement.QA_CONTACT.getKeyString()) + ">");
985
						+ taskData.getAttributeValue(BugzillaReportElement.QA_CONTACT.getKeyString()) + ">");
803
			}			
986
			}
804
		}
987
		}
805
		
988
806
		super.addSelfToCC(composite);
989
		super.addSelfToCC(composite);
807
990
808
	}
991
	}
(-)src/org/eclipse/mylyn/internal/bugzilla/ui/editor/NewBugzillaTaskEditor.java (-2 / +264 lines)
Lines 7-12 Link Here
7
 *******************************************************************************/
7
 *******************************************************************************/
8
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
8
package org.eclipse.mylyn.internal.bugzilla.ui.editor;
9
9
10
import java.text.SimpleDateFormat;
11
import java.util.Calendar;
12
import java.util.Date;
13
import java.util.List;
14
10
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
11
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IProgressMonitor;
12
import org.eclipse.core.runtime.NullProgressMonitor;
17
import org.eclipse.core.runtime.NullProgressMonitor;
Lines 15-29 Link Here
15
import org.eclipse.jface.layout.GridDataFactory;
20
import org.eclipse.jface.layout.GridDataFactory;
16
import org.eclipse.jface.viewers.ILabelProvider;
21
import org.eclipse.jface.viewers.ILabelProvider;
17
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
22
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin;
23
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCustomField;
18
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportElement;
24
import org.eclipse.mylyn.internal.bugzilla.core.BugzillaReportElement;
25
import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration;
19
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
26
import org.eclipse.mylyn.internal.bugzilla.ui.BugzillaUiPlugin;
27
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
20
import org.eclipse.mylyn.tasks.core.RepositoryTaskAttribute;
28
import org.eclipse.mylyn.tasks.core.RepositoryTaskAttribute;
29
import org.eclipse.mylyn.tasks.ui.DatePicker;
21
import org.eclipse.mylyn.tasks.ui.editors.AbstractNewRepositoryTaskEditor;
30
import org.eclipse.mylyn.tasks.ui.editors.AbstractNewRepositoryTaskEditor;
22
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.custom.CCombo;
23
import org.eclipse.swt.events.ModifyEvent;
33
import org.eclipse.swt.events.ModifyEvent;
24
import org.eclipse.swt.events.ModifyListener;
34
import org.eclipse.swt.events.ModifyListener;
25
import org.eclipse.swt.events.SelectionAdapter;
35
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.events.SelectionEvent;
37
import org.eclipse.swt.events.SelectionListener;
27
import org.eclipse.swt.layout.GridData;
38
import org.eclipse.swt.layout.GridData;
28
import org.eclipse.swt.layout.GridLayout;
39
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Button;
40
import org.eclipse.swt.widgets.Button;
Lines 34-40 Link Here
34
import org.eclipse.ui.IEditorSite;
45
import org.eclipse.ui.IEditorSite;
35
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
46
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
36
import org.eclipse.ui.forms.editor.FormEditor;
47
import org.eclipse.ui.forms.editor.FormEditor;
48
import org.eclipse.ui.forms.events.HyperlinkAdapter;
49
import org.eclipse.ui.forms.events.HyperlinkEvent;
37
import org.eclipse.ui.forms.widgets.FormToolkit;
50
import org.eclipse.ui.forms.widgets.FormToolkit;
51
import org.eclipse.ui.forms.widgets.ImageHyperlink;
38
import org.eclipse.ui.forms.widgets.Section;
52
import org.eclipse.ui.forms.widgets.Section;
39
53
40
/**
54
/**
Lines 112-119 Link Here
112
126
113
	@Override
127
	@Override
114
	protected void createCustomAttributeLayout(Composite composite) {
128
	protected void createCustomAttributeLayout(Composite composite) {
129
		RepositoryTaskAttribute attribute = null;
130
		int customFieldsAnz = 0;
131
		try {
132
			RepositoryConfiguration configuration = BugzillaCorePlugin.getRepositoryConfiguration(this.repository,
133
					false, new NullProgressMonitor());
134
135
			if (configuration != null) {
136
				List<BugzillaCustomField> customFields = configuration.getCustomFields();
137
				if (!customFields.isEmpty()) {
138
					for (BugzillaCustomField bugzillaCustomField : customFields) {
139
140
						if (!bugzillaCustomField.isEnterBug()) {
141
							continue;
142
						}
143
						customFieldsAnz++;
144
						attribute = this.taskData.getAttribute(bugzillaCustomField.getName());
145
						if (attribute == null) {
146
							RepositoryTaskAttribute newattribute = new RepositoryTaskAttribute(
147
									bugzillaCustomField.getName(), bugzillaCustomField.getDescription(), false);
148
							newattribute.setReadOnly(false);
149
							this.taskData.addAttribute(bugzillaCustomField.getName(), newattribute);
150
						}
151
						final RepositoryTaskAttribute cfattribute = this.taskData.getAttribute(bugzillaCustomField.getName());
152
						Label label = createLabel(composite, cfattribute);
153
						GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
154
155
						switch (bugzillaCustomField.getType()) {
156
						case 1: // Free Text
157
							Text freeText = createTextField(composite, cfattribute, SWT.FLAT);
158
							GridData freeTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
159
							freeTextData.horizontalSpan = 1;
160
							freeTextData.verticalSpan = 1;
161
							if (hasChanged(cfattribute)) {
162
								freeText.setBackground(getColorIncoming());
163
							}
164
							freeText.setLayoutData(freeTextData);
165
							break;
166
						case 2: // Drop Down
167
							List<String> optionList = bugzillaCustomField.getOptions();
168
							GridData dropDownData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
169
							dropDownData.horizontalSpan = 1;
170
							final CCombo dropDown = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY);
171
							getManagedForm().getToolkit().adapt(dropDown, true, true);
172
							dropDown.setFont(TEXT_FONT);
173
							dropDown.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
174
							if (hasChanged(cfattribute)) {
175
								dropDown.setBackground(getColorIncoming());
176
							}
177
							dropDown.setLayoutData(dropDownData);
178
179
							for (String val : optionList) {
180
								if (val != null) {
181
									dropDown.add(val);
182
								}
183
							}
184
							String value = cfattribute.getValue();
185
							if (value == null) {
186
								value = "";
187
							}
188
							if (dropDown.indexOf(value) != -1) {
189
								dropDown.select(dropDown.indexOf(value));
190
							}
191
							dropDown.clearSelection();
192
							dropDown.addSelectionListener(new SelectionAdapter() {
193
								@Override
194
								public void widgetSelected(SelectionEvent event) {
195
									if (dropDown.getSelectionIndex() > -1) {
196
										String sel = dropDown.getItem(dropDown.getSelectionIndex());
197
										cfattribute.setValue(sel);
198
										attributeChanged(cfattribute);
199
										dropDown.clearSelection();
200
									}
201
								}
202
							});
203
							break;
204
						case 3: // Multiple-Selection Box
205
							final org.eclipse.swt.widgets.List multiSelect;
206
							List<String> multiSelectOptionList = bugzillaCustomField.getOptions();
207
							multiSelect = new org.eclipse.swt.widgets.List(composite, SWT.MULTI | SWT.V_SCROLL);// SWT.BORDER
208
							multiSelect.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
209
							multiSelect.setFont(TEXT_FONT);
210
							GridData multiSelectData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
211
							multiSelectData.horizontalSpan = 1;
212
							multiSelectData.heightHint = 95;
213
							multiSelect.setLayoutData(multiSelectData);
214
							if (hasChanged(cfattribute)) {
215
								multiSelect.setBackground(getColorIncoming());
216
							}
217
							if (multiSelectOptionList != null) {
218
								for (String cc : multiSelectOptionList) {
219
									multiSelect.add(cc);
220
								}
221
							}
222
							java.util.List<String> multiSelectValues = cfattribute.getValues();
223
							if (multiSelectValues != null) {
224
								for (String item : multiSelectValues) {
225
									int i = multiSelect.indexOf(item);
226
									if (i != -1) {
227
										multiSelect.select(i);
228
									}
229
								}
230
							}
231
232
							multiSelect.addSelectionListener(new SelectionListener() {
233
234
								public void widgetSelected(SelectionEvent e) {
235
									for (String selected : multiSelect.getItems()) {
236
										int index = multiSelect.indexOf(selected);
237
										if (multiSelect.isSelected(index)) {
238
											List<String> remove = cfattribute.getValues();
239
											if (!remove.contains(selected)) {
240
												cfattribute.addValue(selected);
241
											}
242
										} else {
243
											cfattribute.removeValue(selected);
244
										}
245
									}
246
									attributeChanged(cfattribute);
247
								}
248
249
								public void widgetDefaultSelected(SelectionEvent e) {
250
								}
251
							});
252
							GridDataFactory.fillDefaults().align(SWT.CENTER, SWT.CENTER).applyTo(label);
253
							break;
254
						case 4: // Large Text Box
255
							Text largeText = createTextField(composite, cfattribute, SWT.FLAT);
256
							GridData largeTextData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
257
							largeTextData.horizontalSpan = 1;
258
							largeTextData.heightHint = 95;
259
							largeText.setLayoutData(largeTextData);
260
							break;
261
						case 5: // Date/Time
262
							Composite dateWithClear = toolkit.createComposite(composite);
263
							GridLayout layout = new GridLayout(2, false);
264
							layout.marginWidth = 1;
265
							dateWithClear.setLayout(layout);
266
267
							final DatePicker dateTimePicker = new DatePicker(dateWithClear, /* SWT.NONE */SWT.BORDER,
268
									cfattribute.getValue(), true);
269
							dateTimePicker.setFont(TEXT_FONT);
270
							dateTimePicker.setDatePattern("yyyy-MM-dd hh:mm:ss");
271
							if (hasChanged(attribute)) {
272
								dateTimePicker.setBackground(getColorIncoming());
273
							}
274
							dateTimePicker.addPickerSelectionListener(new SelectionListener() {
275
276
								public void widgetDefaultSelected(SelectionEvent e) {
277
									// ignore
278
								}
279
280
								public void widgetSelected(SelectionEvent e) {
281
									Calendar cal = dateTimePicker.getDate();
282
									if (cal != null) {
283
										Date d = cal.getTime();
284
										SimpleDateFormat f = (SimpleDateFormat) SimpleDateFormat.getDateInstance();
285
										f.applyPattern("yyyy-MM-dd hh:mm:ss");
286
287
										cfattribute.setValue(f.format(d));
288
										attributeChanged(cfattribute);
289
										// TODO goes dirty even if user presses cancel
290
										// markDirty(true);
291
									} else {
292
										cfattribute.setValue("");
293
										attributeChanged(cfattribute);
294
										dateTimePicker.setDate(null);
295
									}
296
								}
297
							});
298
299
							ImageHyperlink clearDeadlineDate = toolkit.createImageHyperlink(dateWithClear, SWT.NONE);
300
							clearDeadlineDate.setImage(TasksUiImages.getImage(TasksUiImages.REMOVE));
301
							clearDeadlineDate.setToolTipText("Clear");
302
							clearDeadlineDate.addHyperlinkListener(new HyperlinkAdapter() {
303
304
								@Override
305
								public void linkActivated(HyperlinkEvent e) {
306
									cfattribute.setValue("");
307
									attributeChanged(cfattribute);
308
									dateTimePicker.setDate(null);
309
								}
310
							});
311
312
							break;
313
						default:
314
							List<String> optionListDefault = bugzillaCustomField.getOptions();
315
							if (optionListDefault != null && !optionListDefault.isEmpty()) {
316
								GridData dropDownDefaultData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
317
								dropDownDefaultData.horizontalSpan = 1;
318
								final CCombo dropDownDefault = new CCombo(composite, SWT.FLAT | SWT.READ_ONLY);
319
								getManagedForm().getToolkit().adapt(dropDownDefault, true, true);
320
								dropDownDefault.setFont(TEXT_FONT);
321
								dropDownDefault.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER);
322
								if (hasChanged(cfattribute)) {
323
									dropDownDefault.setBackground(getColorIncoming());
324
								}
325
								dropDownDefault.setLayoutData(dropDownDefaultData);
326
327
								for (String valDefault : optionListDefault) {
328
									if (valDefault != null) {
329
										dropDownDefault.add(valDefault);
330
									}
331
								}
332
								String dropDownValue = cfattribute.getValue();
333
								if (dropDownValue == null) {
334
									dropDownValue = "";
335
								}
336
								if (dropDownDefault.indexOf(dropDownValue) != -1) {
337
									dropDownDefault.select(dropDownDefault.indexOf(dropDownValue));
338
								}
339
								dropDownDefault.clearSelection();
340
								dropDownDefault.addSelectionListener(new SelectionAdapter() {
341
									@Override
342
									public void widgetSelected(SelectionEvent event) {
343
										if (dropDownDefault.getSelectionIndex() > -1) {
344
											String sel = dropDownDefault.getItem(dropDownDefault.getSelectionIndex());
345
											cfattribute.setValue(sel);
346
											attributeChanged(cfattribute);
347
											dropDownDefault.clearSelection();
348
										}
349
									}
350
								});								
351
							} else {
352
								Text freeTextDefault = createTextField(composite, cfattribute, SWT.FLAT);
353
								GridData freeTextDefaultData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
354
								freeTextDefaultData.horizontalSpan = 1;
355
								freeTextDefaultData.verticalSpan = 1;
356
								if (hasChanged(cfattribute)) {
357
									freeTextDefault.setBackground(getColorIncoming());
358
								}
359
								freeTextDefault.setLayoutData(freeTextDefaultData);
360
							}
361
							break;
362
						}
363
					}
364
					getManagedForm().getToolkit().paintBordersFor(composite);
365
				}
366
			}
367
		} catch (CoreException e) {
368
			// ignore
369
		}
370
371
		if (customFieldsAnz % 2 == 1) {
372
			@SuppressWarnings("unused")
373
			Label label = new Label(composite, SWT.None);
374
			label = new Label(composite, SWT.None);
375
		}
115
376
116
		RepositoryTaskAttribute attribute = this.taskData.getAttribute(BugzillaReportElement.DEPENDSON.getKeyString());
377
		attribute = this.taskData.getAttribute(BugzillaReportElement.DEPENDSON.getKeyString());
117
		if (attribute != null && !attribute.isReadOnly()) {
378
		if (attribute != null && !attribute.isReadOnly()) {
118
			Label label = createLabel(composite, attribute);
379
			Label label = createLabel(composite, attribute);
119
			GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
380
			GridDataFactory.fillDefaults().align(SWT.RIGHT, SWT.CENTER).applyTo(label);
Lines 165-171 Link Here
165
		if (assignedAttribute != null) {
426
		if (assignedAttribute != null) {
166
			String bugzillaVersion;
427
			String bugzillaVersion;
167
			try {
428
			try {
168
				bugzillaVersion = BugzillaCorePlugin.getRepositoryConfiguration(repository, false, new NullProgressMonitor()).getInstallVersion();
429
				bugzillaVersion = BugzillaCorePlugin.getRepositoryConfiguration(repository, false,
430
						new NullProgressMonitor()).getInstallVersion();
169
			} catch (CoreException e1) {
431
			} catch (CoreException e1) {
170
				// ignore
432
				// ignore
171
				bugzillaVersion = "2.18";
433
				bugzillaVersion = "2.18";
(-)src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaCustomField.java (-2 / +31 lines)
Lines 8-13 Link Here
8
8
9
package org.eclipse.mylyn.internal.bugzilla.core;
9
package org.eclipse.mylyn.internal.bugzilla.core;
10
10
11
import java.io.IOException;
11
import java.io.Serializable;
12
import java.io.Serializable;
12
import java.util.ArrayList;
13
import java.util.ArrayList;
13
import java.util.List;
14
import java.util.List;
Lines 20-26 Link Here
20
 */
21
 */
21
public class BugzillaCustomField implements Serializable {
22
public class BugzillaCustomField implements Serializable {
22
23
23
	private static final long serialVersionUID = 5703683576871326128L;
24
// old Version	private static final long serialVersionUID = 5703683576871326128L;
25
	private static final long serialVersionUID = 7486595630521536136L;
24
26
25
	public static final String CUSTOM_FIELD_PREFIX = "cf_";
27
	public static final String CUSTOM_FIELD_PREFIX = "cf_";
26
28
Lines 30-38 Link Here
30
32
31
	private List<String> options = new ArrayList<String>();
33
	private List<String> options = new ArrayList<String>();
32
34
33
	public BugzillaCustomField(String description, String name) {
35
	private int type = -1;
36
37
	private String typeDesc = null;
38
39
	private boolean enterBug = false;
40
41
	public BugzillaCustomField(String description, String name, String type, String typeDesc, String enterBug) {
34
		this.description = description;
42
		this.description = description;
35
		this.name = name;
43
		this.name = name;
44
		if (type != null && !type.equals("")) {
45
			this.type = Integer.parseInt(type);
46
		}
47
		if (typeDesc != null && !typeDesc.equals("")) {
48
			this.typeDesc = typeDesc;
49
		}
50
		if (enterBug != null && !enterBug.equals("")) {
51
			this.enterBug = enterBug.equals("1");
52
		}
36
	}
53
	}
37
54
38
	public String getName() {
55
	public String getName() {
Lines 54-57 Link Here
54
	public void addOption(String option) {
71
	public void addOption(String option) {
55
		this.options.add(option);
72
		this.options.add(option);
56
	}
73
	}
74
75
	public int getType() {
76
		return type;
77
	}
78
79
	public String getTypeDesc() {
80
		return typeDesc;
81
	}
82
83
	public boolean isEnterBug() {
84
		return enterBug;
85
	}
57
}
86
}
(-)src/org/eclipse/mylyn/internal/bugzilla/core/SaxConfigurationContentHandler.java (-3 / +29 lines)
Lines 62-67 Link Here
62
62
63
	private static final String ELEMENT_FIELD = "field";
63
	private static final String ELEMENT_FIELD = "field";
64
64
65
	private static final String ELEMENT_TYPE = "type";
66
67
	private static final String ELEMENT_TYPE_DESC = "type_desc";
68
69
	private static final String ELEMENT_ENTER_BUG = "enter_bug";
70
65
	private static final String ELEMENT_SEVERITY = "severity";
71
	private static final String ELEMENT_SEVERITY = "severity";
66
72
67
	private static final String ELEMENT_PRIORITY = "priority";
73
	private static final String ELEMENT_PRIORITY = "priority";
Lines 127-135 Link Here
127
	private int state = EXPECTING_ROOT;
133
	private int state = EXPECTING_ROOT;
128
134
129
	private String currentProduct = "";
135
	private String currentProduct = "";
130
	
136
131
	private String currentName = "";
137
	private String currentName = "";
132
138
139
	private String currentDescription = "";
140
	
141
	private String currentType = "";
142
	
143
	private String currentTypeDesc = "";
144
	
145
	private String currentEnterBug = "";
146
133
	private StringBuffer characters = new StringBuffer();
147
	private StringBuffer characters = new StringBuffer();
134
148
135
	private String about;
149
	private String about;
Lines 213-218 Link Here
213
		} else if (localName.equals(ELEMENT_FIELD)) {
227
		} else if (localName.equals(ELEMENT_FIELD)) {
214
			state = state | IN_FIELD;
228
			state = state | IN_FIELD;
215
			parseResource(attributes);
229
			parseResource(attributes);
230
			currentName = "";
231
			currentDescription = "";
232
			currentType = "";
233
			currentTypeDesc = "";
234
			currentEnterBug = "";
216
		} else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
235
		} else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
217
			state = state | IN_CUSTOM_OPTION;
236
			state = state | IN_CUSTOM_OPTION;
218
			currentCustomOptionName = localName;
237
			currentCustomOptionName = localName;
Lines 331-344 Link Here
331
			state = state & ~IN_FIELDS;
350
			state = state & ~IN_FIELDS;
332
		} else if (localName.equals(ELEMENT_FIELD)) {
351
		} else if (localName.equals(ELEMENT_FIELD)) {
333
			state = state & ~IN_FIELD;
352
			state = state & ~IN_FIELD;
334
		} else if (localName.equals(ELEMENT_DESCRIPTION)) {
335
			if (currentName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
353
			if (currentName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
336
				BugzillaCustomField newField = new BugzillaCustomField(characters.toString(), currentName);
354
				BugzillaCustomField newField = new BugzillaCustomField(currentDescription, currentName, currentType, currentTypeDesc, currentEnterBug);
337
				List<String> customOptionList = customOption.get(currentName);
355
				List<String> customOptionList = customOption.get(currentName);
338
				if (customOptionList != null && !customOptionList.isEmpty())
356
				if (customOptionList != null && !customOptionList.isEmpty())
339
					newField.setOptions(customOptionList);
357
					newField.setOptions(customOptionList);
340
				configuration.addCustomField(newField);
358
				configuration.addCustomField(newField);
341
			}
359
			}
360
		} else if (localName.equals(ELEMENT_DESCRIPTION)) {
361
			currentDescription = characters.toString();
362
		} else if (localName.equals(ELEMENT_TYPE)) {
363
			currentType = characters.toString();
364
		} else if (localName.equals(ELEMENT_TYPE_DESC)) {
365
			currentTypeDesc = characters.toString();
366
		} else if (localName.equals(ELEMENT_ENTER_BUG)) {
367
			currentEnterBug = characters.toString();
342
		} else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
368
		} else if (localName.startsWith(BugzillaCustomField.CUSTOM_FIELD_PREFIX)) {
343
			state = state & ~IN_CUSTOM_OPTION;
369
			state = state & ~IN_CUSTOM_OPTION;
344
			currentCustomOptionName = "";
370
			currentCustomOptionName = "";

Return to bug 226851