Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 143567 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/AbstractDuplicateDetectingReportWizard.java (-62 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylar.internal.tasks.ui.wizards;
10
11
import java.util.Iterator;
12
import java.util.LinkedList;
13
import java.util.List;
14
import java.util.Queue;
15
16
import org.eclipse.jface.wizard.IWizardPage;
17
import org.eclipse.jface.wizard.Wizard;
18
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
19
20
/**
21
 * 
22
 * @author Jeff Pound
23
 */
24
public abstract class AbstractDuplicateDetectingReportWizard extends Wizard {
25
26
	private Queue<IWizardPage> queue = new LinkedList<IWizardPage>();
27
28
	public AbstractDuplicateDetectingReportWizard() {
29
		setNeedsProgressMonitor(true);
30
	}
31
32
	public void queuePage(IWizardPage page) {
33
		queue.add(page);
34
	}
35
36
	public void addQueuedPages() {
37
		Iterator<IWizardPage> iter = queue.iterator();
38
		while (iter.hasNext()) {
39
			addPage(iter.next());
40
		}
41
	}
42
43
	public boolean canFinish() {
44
		IWizardPage findDups = getPage(FindRelatedReportsPage.PAGE_NAME);
45
		if (findDups == null) {
46
			return super.canFinish();
47
		}
48
49
		return !findDups.equals(getContainer().getCurrentPage()) && super.canFinish();
50
	}
51
52
	public List<AbstractRepositoryTask> getSelectedDuplicates() {
53
		DisplayRelatedReportsPage displayDups = (DisplayRelatedReportsPage) getPage(DisplayRelatedReportsPage.PAGE_NAME);
54
		if (displayDups == null) {
55
			return null;
56
		}
57
58
		return displayDups.getSelectedReports();
59
	}
60
61
	public abstract List<AbstractRepositoryTask> searchForDuplicates(DuplicateDetectionData data);
62
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/DisplayRelatedReportsPage.java (-358 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylar.internal.tasks.ui.wizards;
10
11
import java.util.Iterator;
12
import java.util.LinkedList;
13
import java.util.List;
14
import java.util.StringTokenizer;
15
16
import org.eclipse.jface.wizard.WizardPage;
17
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
18
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.events.SelectionEvent;
22
import org.eclipse.swt.events.SelectionListener;
23
import org.eclipse.swt.events.TreeEvent;
24
import org.eclipse.swt.events.TreeListener;
25
import org.eclipse.swt.graphics.GC;
26
import org.eclipse.swt.graphics.Point;
27
import org.eclipse.swt.graphics.Rectangle;
28
import org.eclipse.swt.layout.FillLayout;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.layout.RowLayout;
32
import org.eclipse.swt.widgets.Composite;
33
import org.eclipse.swt.widgets.Display;
34
import org.eclipse.swt.widgets.Event;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Listener;
37
import org.eclipse.swt.widgets.Shell;
38
import org.eclipse.swt.widgets.TableItem;
39
import org.eclipse.swt.widgets.Tree;
40
import org.eclipse.swt.widgets.TreeColumn;
41
import org.eclipse.swt.widgets.TreeItem;
42
43
/**
44
 * 
45
 * @author Jeff Pound
46
 */
47
public class DisplayRelatedReportsPage extends WizardPage {
48
49
	private static final String PAGE_DESCRIPTION = "Select duplicate report candidates to open and comment on them.  Otherwise press finish to create new one.";
50
51
	static final String PAGE_NAME = "DisplayRelatedReportsPage";
52
53
	private static final String PAGE_TITLE = "Related Reports";
54
55
	private static final int LINES_PER_ITEM = 3;
56
57
	private List<AbstractRepositoryTask> relatedTasks;
58
59
	private String[] columnHeaders = { "Related Reports" };
60
61
	private Tree duplicatesTree;
62
63
	private int[] columnWidths = { 550 };
64
65
	protected DisplayRelatedReportsPage() {
66
		super(PAGE_NAME);
67
		setTitle(PAGE_TITLE);
68
		setDescription(PAGE_DESCRIPTION);
69
		// Description doesn't show up without an image present TODO: proper
70
		// image.
71
		setImageDescriptor(TasksUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui",
72
				"icons/wizban/bug-wizard.gif"));
73
	}
74
75
	public void createControl(Composite parent) {
76
		Composite composite = new Composite(parent, SWT.NONE);
77
		composite.setLayout(new GridLayout());
78
		setControl(composite);
79
80
		duplicatesTree = new Tree(composite, SWT.MULTI | SWT.CHECK | SWT.FULL_SELECTION);
81
		duplicatesTree.setLayoutData(new GridData(GridData.FILL_BOTH));
82
83
		RowLayout gl = new RowLayout();
84
		gl.spacing = 30;
85
		duplicatesTree.setLayout(gl);
86
87
		duplicatesTree.setHeaderVisible(true);
88
		duplicatesTree.setLinesVisible(true);
89
90
		for (int i = 0; i < columnHeaders.length; i++) {
91
			TreeColumn column = new TreeColumn(duplicatesTree, SWT.NONE);
92
			column.setText(columnHeaders[i]);
93
		}
94
95
		/*
96
		 * Adapted from snippet 227
97
		 * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet227.java?rev=HEAD&content-type=text/vnd.viewcvs-markup
98
		 */
99
		Listener paintListener = new Listener() {
100
			public void handleEvent(Event event) {
101
				switch (event.type) {
102
				case SWT.MeasureItem: {
103
					String text = ((TreeItem) event.item).getText();
104
					Point size = event.gc.textExtent(text);
105
					event.width = size.x;
106
					event.height = Math.max(event.height, size.y);
107
					break;
108
				}
109
				case SWT.PaintItem: {
110
					String text = ((TreeItem) event.item).getText();
111
					Point size = event.gc.textExtent(text);
112
					int offset2 = event.index == 0 ? Math.max(0, (event.height - size.y) / 2) : 0;
113
					event.gc.drawText(text, event.x, event.y + offset2, true);
114
					break;
115
				}
116
				case SWT.EraseItem: {
117
					event.detail &= ~SWT.FOREGROUND;
118
					break;
119
				}
120
				}
121
			}
122
		};
123
		duplicatesTree.addListener(SWT.MeasureItem, paintListener);
124
		duplicatesTree.addListener(SWT.PaintItem, paintListener);
125
		duplicatesTree.addListener(SWT.EraseItem, paintListener);
126
		duplicatesTree.addTreeListener(new TreeListener() {
127
			public void treeCollapsed(TreeEvent arg0) {
128
				// packTable();
129
			}
130
131
			public void treeExpanded(TreeEvent arg0) {
132
				// packTable();
133
			}
134
		});
135
136
		registerToolTipListeners();
137
	}
138
139
	/*
140
	 * Adapted from SWT snippet 125
141
	 * http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet125.java?rev=HEAD&content-type=text/vnd.viewcvs-markup
142
	 */
143
	private void registerToolTipListeners() {
144
		final Shell shell = duplicatesTree.getShell();
145
		final Display display = duplicatesTree.getDisplay();
146
147
		// Disable native tooltip
148
		duplicatesTree.setToolTipText("");
149
150
		// Implement a "fake" tooltip
151
		final Listener labelListener = new Listener() {
152
			public void handleEvent(Event event) {
153
				Label label = (Label) event.widget;
154
				Shell shell = label.getShell();
155
				switch (event.type) {
156
				case SWT.MouseDown:
157
					Event e = new Event();
158
					e.item = (TableItem) label.getData("_TABLEITEM");
159
					// Assuming table is single select, set the selection as if
160
					// the mouse down event went through to the table
161
					duplicatesTree.setSelection(new TreeItem[] { (TreeItem) e.item });
162
					duplicatesTree.notifyListeners(SWT.Selection, e);
163
					// fall through
164
				case SWT.MouseExit:
165
					shell.dispose();
166
					break;
167
				}
168
			}
169
		};
170
171
		Listener tableListener = new Listener() {
172
			Shell tip = null;
173
174
			Label label = null;
175
176
			public void handleEvent(Event event) {
177
				switch (event.type) {
178
				case SWT.Dispose:
179
				case SWT.KeyDown:
180
				case SWT.MouseMove: {
181
					if (tip == null)
182
						break;
183
					tip.dispose();
184
					tip = null;
185
					label = null;
186
					break;
187
				}
188
				case SWT.MouseHover: {
189
					TreeItem item = duplicatesTree.getItem(new Point(event.x, event.y));
190
					if (item != null) {
191
						if (tip != null && !tip.isDisposed())
192
							tip.dispose();
193
						tip = new Shell(shell, SWT.ON_TOP | SWT.TOOL);
194
						tip.setLayout(new FillLayout());
195
						label = new Label(tip, SWT.NONE);
196
						label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
197
						label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
198
						label.setData("_TABLEITEM", item);
199
						label.setText((String) item.getData());
200
						label.addListener(SWT.MouseExit, labelListener);
201
						label.addListener(SWT.MouseDown, labelListener);
202
						Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT);
203
						Rectangle rect = item.getBounds(0);
204
						Point pt = duplicatesTree.toDisplay(rect.x, rect.y);
205
						tip.setBounds(pt.x, pt.y, size.x, size.y);
206
						tip.setVisible(true);
207
					}
208
				}
209
				}
210
			}
211
		};
212
		duplicatesTree.addListener(SWT.Dispose, tableListener);
213
		duplicatesTree.addListener(SWT.KeyDown, tableListener);
214
		duplicatesTree.addListener(SWT.MouseMove, tableListener);
215
		duplicatesTree.addListener(SWT.MouseHover, tableListener);
216
217
	}
218
219
	private void packTable() {
220
		for (int i = 0; i < columnHeaders.length; i++) {
221
			// duplicatesTree.getColumn(i).pack();
222
			duplicatesTree.getColumn(i).setWidth(columnWidths[i]);
223
		}
224
		duplicatesTree.redraw();
225
	}
226
227
	public List<AbstractRepositoryTask> getRelatedTasks() {
228
		return relatedTasks;
229
	}
230
231
	public void setRelatedTasks(List<AbstractRepositoryTask> relatedTasks) {
232
		duplicatesTree.removeAll();
233
		this.relatedTasks = relatedTasks;
234
		if (duplicatesTree == null || this.relatedTasks == null) {
235
			return;
236
		}
237
238
		SelectionListener selectAllListener = new SelectionListener() {
239
			public void widgetDefaultSelected(SelectionEvent arg0) {
240
				// ignore
241
			}
242
243
			public void widgetSelected(SelectionEvent event) {
244
				TreeItem item = (TreeItem) event.item;
245
				if (item.getParentItem() != null) {
246
					item.getParentItem().setChecked(item.getChecked());
247
				}
248
				if (item.getItems() != null && item.getItems().length > 0) {
249
					item.getItems()[0].setChecked(item.getChecked());
250
				}
251
			}
252
		};
253
		duplicatesTree.addSelectionListener(selectAllListener);
254
255
		// update the table
256
		Iterator<AbstractRepositoryTask> iter = this.relatedTasks.iterator();
257
		while (iter.hasNext()) {
258
			AbstractRepositoryTask task = iter.next();
259
			RepositoryTaskData taskData = task.getTaskData();
260
			if (taskData == null) {
261
				iter.remove();
262
				continue;
263
			}
264
			TreeItem item = new TreeItem(duplicatesTree, SWT.NONE);
265
			item.setText(new String[] { formatTreeText(taskData.getSummary(), LINES_PER_ITEM - 1) });
266
			TreeItem descItem = new TreeItem(item, SWT.NONE);
267
			descItem.setText(formatTreeText(taskData.getDescription()));
268
			descItem.setGrayed(true);
269
270
			String toolTip = "Report Id: " + taskData.getId() + "\nCreated on: " + taskData.getCreated()
271
					+ "\nCreated by: " + taskData.getReporter() + "\nAssigned to: " + taskData.getAssignedTo();
272
			item.setData(toolTip);
273
			descItem.setData(toolTip);
274
		}
275
		packTable();
276
	}
277
278
	private String formatTreeText(String text) {
279
		return formatTreeText(text, LINES_PER_ITEM);
280
	}
281
282
	private String formatTreeText(String text, int maxLines) {
283
		GC gc = new GC(duplicatesTree);
284
		int avgCharWidth = gc.getFontMetrics().getAverageCharWidth();
285
		gc.dispose();
286
287
		text = text.replace("\n", " ");
288
		StringTokenizer strtok = new StringTokenizer(text);
289
		StringBuffer formatText = new StringBuffer();
290
		int charsPerLine = columnWidths[0] / avgCharWidth;
291
		int lines = 0;
292
293
		// character wrap
294
		// while (strtok.hasMoreTokens() && lines < maxLines) {
295
		// String line = strtok.nextToken();
296
		// while (line.length() > charsPerLine && lines < maxLines) {
297
		// String trimmedLine = line.substring(0, charsPerLine);
298
		// formatText.append(trimmedLine + "\n");
299
		// lines++;
300
		// line = line.substring(charsPerLine);
301
		// }
302
		// formatText.append(line + "\n");
303
		// lines++;
304
		// }
305
306
		// word wrap
307
		StringBuffer line = new StringBuffer();
308
		while (strtok.hasMoreTokens() && lines < maxLines) {
309
			String word = strtok.nextToken();
310
			while (strtok.hasMoreTokens() && line.length() + word.length() < charsPerLine) {
311
				line.append(word + ((line.length() + word.length() + 1 > charsPerLine) ? "" : " "));
312
				word = strtok.nextToken();
313
			}
314
			if (!strtok.hasMoreTokens()) {
315
				line.append(word);
316
			}
317
			formatText.append(((formatText.length() == 0) ? "" : "\n") + line.toString());
318
			lines++;
319
			line.delete(0, line.length());
320
			line.append(word + " ");
321
		}
322
323
		// pad elements to ensure no weird repaint artifacts
324
		// this also centres text in the element (aligned with tree arrow)
325
		if (lines < LINES_PER_ITEM) {
326
			int diff = LINES_PER_ITEM - lines;
327
			for (int i = 0; i < diff / 2; i++) {
328
				formatText.append("\n ");
329
				lines++;
330
			}
331
			while (lines < LINES_PER_ITEM) {
332
				formatText.insert(0, " \n");
333
				lines++;
334
			}
335
			lines++;
336
		}
337
338
		// add "..." if we're cutting off the text
339
		if (strtok.hasMoreTokens()) {
340
			formatText.replace(formatText.length() - 4, formatText.length(), "...");
341
		}
342
343
		return formatText.toString();
344
	}
345
346
	public List<AbstractRepositoryTask> getSelectedReports() {
347
		List<AbstractRepositoryTask> selected = new LinkedList<AbstractRepositoryTask>();
348
		TreeItem[] items = duplicatesTree.getItems();
349
350
		for (int i = 0; i < items.length; i++) {
351
			if (items[i].getChecked()) {
352
				selected.add(relatedTasks.get(i));
353
			}
354
		}
355
356
		return selected;
357
	}
358
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/DuplicateDetectionData.java (-27 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 Mylar committers and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *******************************************************************************/
8
9
package org.eclipse.mylar.internal.tasks.ui.wizards;
10
11
/**
12
 * 
13
 * @author Jeff Pound
14
 */
15
public class DuplicateDetectionData {
16
17
	// TODO add more fields to detect duplicates against
18
	private String stackTrace = "";
19
20
	public String getStackTrace() {
21
		return stackTrace;
22
	}
23
24
	public void setStackTrace(String stackTrace) {
25
		this.stackTrace = stackTrace;
26
	}
27
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/NewRepositoryTaskWizard.java (-5 lines)
Lines 45-53 Link Here
45
		}
45
		}
46
		return connectorKinds;
46
		return connectorKinds;
47
	}
47
	}
48
	
49
	public void setDuplicateData(DuplicateDetectionData duplicateData) {
50
		((NewRepositoryTaskPage)getSelectRepositoryPage()).setDuplicateData(duplicateData);
51
		((NewRepositoryTaskPage)getSelectRepositoryPage()).setUseStackTrace(true);
52
	}
53
}
48
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/FindRelatedReportsPage.java (-112 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.internal.tasks.ui.wizards;
13
14
import org.eclipse.jface.wizard.IWizardPage;
15
import org.eclipse.jface.wizard.WizardPage;
16
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.events.ModifyEvent;
19
import org.eclipse.swt.events.ModifyListener;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Label;
24
import org.eclipse.swt.widgets.Text;
25
26
/**
27
 * 
28
 * @author Jeff Pound
29
 */
30
public class FindRelatedReportsPage extends WizardPage implements IWizardPage {
31
32
	private static final String PAGE_DESCRIPTION = "Enter the stack trace to search for, you can trim the stack trace to make your search more general";
33
34
	private static final String PAGE_TITLE = "Find Related Reports";
35
36
	static final String PAGE_NAME = "FindRelatedReportsPage";
37
38
	private Text stackTraceBox;
39
40
	private Text searchTermsText;
41
42
	private DuplicateDetectionData duplicateData;
43
44
	public FindRelatedReportsPage(DuplicateDetectionData duplicateData) {
45
		super(PAGE_NAME);
46
		setTitle(PAGE_TITLE);
47
		setDescription(PAGE_DESCRIPTION);
48
		
49
		// Description doesn't show up without an image present TODO: proper image.
50
		setImageDescriptor(TasksUiPlugin.imageDescriptorFromPlugin("org.eclipse.mylar.bugzilla.ui",
51
				"icons/wizban/bug-wizard.gif"));
52
		this.duplicateData = duplicateData;
53
		if (this.duplicateData == null) {
54
			this.duplicateData = new DuplicateDetectionData();
55
		}
56
	}
57
58
	public void createControl(Composite parent) {
59
		Composite composite = new Composite(parent, SWT.NONE);
60
		composite.setLayout(new GridLayout(2, false));
61
		setControl(composite);
62
63
		Label searchLabel = new Label(composite, SWT.LEFT);
64
		searchLabel.setText("Search Terms ");
65
		searchTermsText = new Text(composite, SWT.SINGLE);
66
		searchTermsText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
67
		searchTermsText.setText("");
68
		searchTermsText.setEnabled(false);
69
70
		Label stackLabel = new Label(composite, SWT.LEFT);
71
		stackLabel.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false, 2, 1));
72
		stackLabel.setText("Stack trace");
73
		stackTraceBox = new Text(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
74
		stackTraceBox.setText(duplicateData.getStackTrace());
75
		GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1);
76
		// prevent the box from oversizing the wizard dialog
77
		if (!"".equals(duplicateData.getStackTrace())) {
78
			gd.heightHint = 200;
79
			gd.widthHint = 600;
80
		}
81
		stackTraceBox.setLayoutData(gd);
82
		stackTraceBox.addModifyListener(new ModifyListener() {
83
			public void modifyText(ModifyEvent arg0) {
84
				if ("".equals(stackTraceBox.getText().trim())) {
85
					setPageComplete(false);
86
				} else {
87
					setPageComplete(true);
88
				}
89
			}
90
		});
91
	}
92
93
	public DuplicateDetectionData getDuplicateData() {
94
		if (stackTraceBox != null) {
95
			// in case stack trace is user modified
96
			duplicateData.setStackTrace(stackTraceBox.getText());
97
		}
98
		return duplicateData;
99
	}
100
101
	public IWizardPage getNextPage() {
102
		DisplayRelatedReportsPage nextPage = (DisplayRelatedReportsPage) super.getNextPage();
103
		nextPage.setRelatedTasks(((AbstractDuplicateDetectingReportWizard) getWizard())
104
				.searchForDuplicates(getDuplicateData()));
105
106
		return super.getNextPage();
107
	}
108
109
	public boolean canFlipToNextPage() {
110
		return !"".equals(stackTraceBox.getText());
111
	}
112
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/NewRepositoryTaskPage.java (-77 / +16 lines)
Lines 14-31 Link Here
14
import java.util.List;
14
import java.util.List;
15
15
16
import org.eclipse.jface.wizard.IWizard;
16
import org.eclipse.jface.wizard.IWizard;
17
import org.eclipse.jface.wizard.IWizardPage;
18
import org.eclipse.mylar.tasks.core.TaskRepository;
17
import org.eclipse.mylar.tasks.core.TaskRepository;
19
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector;
18
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector;
20
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
19
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
21
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.events.SelectionEvent;
23
import org.eclipse.swt.events.SelectionListener;
24
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.layout.GridData;
25
import org.eclipse.swt.layout.GridLayout;
22
import org.eclipse.swt.layout.GridLayout;
26
import org.eclipse.swt.widgets.Button;
27
import org.eclipse.swt.widgets.Composite;
23
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Link;
29
24
30
/**
25
/**
31
 * @author Mik Kersten
26
 * @author Mik Kersten
Lines 33-48 Link Here
33
 */
28
 */
34
public class NewRepositoryTaskPage extends SelectRepositoryPage {
29
public class NewRepositoryTaskPage extends SelectRepositoryPage {
35
30
36
	private Button searchForDuplicatesButton;
37
38
	private DuplicateDetectionData duplicateData;
39
40
	private boolean initUseStackTrace = false;
41
42
	private IWizard newWizard;
43
44
	private boolean dupPagesAdded = false;
45
46
	public NewRepositoryTaskPage(List<String> kinds) {
31
	public NewRepositoryTaskPage(List<String> kinds) {
47
		super(kinds);
32
		super(kinds);
48
	}
33
	}
Lines 51-125 Link Here
51
	protected IWizard createWizard(TaskRepository taskRepository) {
36
	protected IWizard createWizard(TaskRepository taskRepository) {
52
		AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
37
		AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager().getRepositoryConnector(
53
				taskRepository.getKind());
38
				taskRepository.getKind());
54
		newWizard = connector.getNewTaskWizard(taskRepository, getSelection());
39
		return connector.getNewTaskWizard(taskRepository, getSelection());
55
		if (newWizard instanceof AbstractDuplicateDetectingReportWizard && getUseStackTrace()) {
56
			AbstractDuplicateDetectingReportWizard dupWizard = (AbstractDuplicateDetectingReportWizard) newWizard;
57
			// queue the duplicate detection pages to be added to the
58
			// wizard when it gets created
59
			dupWizard.queuePage(new FindRelatedReportsPage(duplicateData));
60
			dupWizard.queuePage(new DisplayRelatedReportsPage());
61
			dupPagesAdded = true;
62
		}
63
		return newWizard;
64
	}
65
66
	public IWizardPage getNextPage() {
67
		// ensure the dup pages are added (in the case of going "back" in the
68
		// wizard)
69
		if (!dupPagesAdded && newWizard instanceof AbstractDuplicateDetectingReportWizard && getUseStackTrace()) {
70
			AbstractDuplicateDetectingReportWizard dupWizard = (AbstractDuplicateDetectingReportWizard) newWizard;
71
			dupWizard.addPage(new FindRelatedReportsPage(duplicateData));
72
			dupWizard.addPage(new DisplayRelatedReportsPage());
73
			dupPagesAdded = true;
74
		}
75
		return super.getNextPage();
76
	}
40
	}
77
41
78
	public void createControl(Composite parent) {
42
	public void createControl(Composite parent) {
79
		Composite container = new Composite(parent, SWT.NONE);
43
		Composite container = new Composite(parent, SWT.NONE);
80
		container.setLayout(new GridLayout());
44
		container.setLayout(new GridLayout());
81
		// super.createControl(container);
82
		createTableViewer(container).setLayoutData(new GridData(GridData.FILL_BOTH));
83
45
84
		searchForDuplicatesButton = new Button(container, SWT.CHECK);
46
//		Link link = new Link(container, SWT.NONE);
85
		searchForDuplicatesButton.setText("Search for related stack traces before creating");
47
//		link.setText("<A>Close wizard and search for related reports before continuing</A>");
86
		searchForDuplicatesButton.setSelection(initUseStackTrace);
48
//		link.addSelectionListener(new SelectionListener() {
87
49
//			public void widgetDefaultSelected(SelectionEvent arg0) {
88
		Link link = new Link(container, SWT.NONE);
50
//				// ignore
89
		link.setText("<A>Close wizard and search for related reports before continuing</A>");
51
//			}
90
		final IWizardPage thisPage = this;
52
//
91
		link.addSelectionListener(new SelectionListener() {
53
//			public void widgetSelected(SelectionEvent arg0) {
92
			public void widgetDefaultSelected(SelectionEvent arg0) {
54
//				getWizard().performCancel();
93
				// ignore
55
//				getWizard().getContainer().getShell().dispose();
94
			}
56
//				NewSearchUI.openSearchDialog(NewSearchUI.getSearchResultView().getSite().getWorkbenchWindow(), "");
95
57
//
96
			public void widgetSelected(SelectionEvent arg0) {
58
//			}
97
				thisPage.getWizard().performCancel();
59
//		});
98
			}
99
		});
100
60
61
		createTableViewer(container).setLayoutData(new GridData(GridData.FILL_BOTH));
101
		setControl(container);
62
		setControl(container);
102
	}
63
	}
103
104
	public DuplicateDetectionData getDuplicateData() {
105
		return duplicateData;
106
	}
107
108
	public void setDuplicateData(DuplicateDetectionData duplicateData) {
109
		this.duplicateData = duplicateData;
110
	}
111
112
	public void setUseStackTrace(boolean use) {
113
		if (searchForDuplicatesButton != null) {
114
			searchForDuplicatesButton.setSelection(use);
115
		}
116
		initUseStackTrace = use;
117
	}
118
119
	public boolean getUseStackTrace() {
120
		if (searchForDuplicatesButton != null) {
121
			return searchForDuplicatesButton.getSelection();
122
		}
123
		return initUseStackTrace;
124
	}
125
}
64
}
(-)src/org/eclipse/mylar/internal/tasks/ui/wizards/MultiRepositoryAwareWizard.java (-4 lines)
Lines 52-59 Link Here
52
		// Can't finish on the first page
52
		// Can't finish on the first page
53
		return false;
53
		return false;
54
	}
54
	}
55
56
	public SelectRepositoryPage getSelectRepositoryPage() {
57
		return selectRepositoryPage;
58
	}
59
}
55
}
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 19-25 Link Here
19
 org.eclipse.mylar.tasks.core,
19
 org.eclipse.mylar.tasks.core,
20
 org.eclipse.mylar.monitor,
20
 org.eclipse.mylar.monitor,
21
 org.eclipse.core.resources,
21
 org.eclipse.core.resources,
22
 org.eclipse.ui.ide
22
 org.eclipse.ui.ide,
23
 org.eclipse.search
23
Eclipse-AutoStart: true
24
Eclipse-AutoStart: true
24
Bundle-Vendor: Eclipse.org
25
Bundle-Vendor: Eclipse.org
25
Export-Package: org.eclipse.mylar.internal.tasks.ui,
26
Export-Package: org.eclipse.mylar.internal.tasks.ui,
(-)src/org/eclipse/mylar/internal/tasks/ui/actions/NewTaskFromErrorAction.java (-8 lines)
Lines 20-26 Link Here
20
import org.eclipse.jface.wizard.WizardDialog;
20
import org.eclipse.jface.wizard.WizardDialog;
21
import org.eclipse.mylar.internal.tasks.ui.editors.AbstractRepositoryTaskEditor;
21
import org.eclipse.mylar.internal.tasks.ui.editors.AbstractRepositoryTaskEditor;
22
import org.eclipse.mylar.internal.tasks.ui.editors.ExistingBugEditorInput;
22
import org.eclipse.mylar.internal.tasks.ui.editors.ExistingBugEditorInput;
23
import org.eclipse.mylar.internal.tasks.ui.wizards.DuplicateDetectionData;
24
import org.eclipse.mylar.internal.tasks.ui.wizards.NewRepositoryTaskWizard;
23
import org.eclipse.mylar.internal.tasks.ui.wizards.NewRepositoryTaskWizard;
25
import org.eclipse.pde.internal.runtime.logview.LogEntry;
24
import org.eclipse.pde.internal.runtime.logview.LogEntry;
26
import org.eclipse.swt.widgets.Shell;
25
import org.eclipse.swt.widgets.Shell;
Lines 57-69 Link Here
57
		}
56
		}
58
57
59
		NewRepositoryTaskWizard wizard = new NewRepositoryTaskWizard();
58
		NewRepositoryTaskWizard wizard = new NewRepositoryTaskWizard();
60
		if (selection != null) {
61
			DuplicateDetectionData dup = new DuplicateDetectionData();
62
			dup.setStackTrace(((selection.getStack() == null) ? "no stack trace available" : selection.getStack()));
63
			// getSummaryString(selection);
64
65
			wizard.setDuplicateData(dup);
66
		}
67
59
68
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
60
		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
69
		if (wizard != null && shell != null && !shell.isDisposed()) {
61
		if (wizard != null && shell != null && !shell.isDisposed()) {
(-)src/org/eclipse/mylar/bugzilla/tests/headless/BugzillaDuplicateDetectionTest.java (-57 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004 - 2006 University Of British Columbia and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     University Of British Columbia - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.mylar.bugzilla.tests.headless;
13
14
import java.util.List;
15
16
import junit.framework.TestCase;
17
18
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
19
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
20
import org.eclipse.mylar.internal.bugzilla.ui.wizard.NewBugzillaReportWizard;
21
import org.eclipse.mylar.internal.tasks.ui.wizards.DuplicateDetectionData;
22
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
23
import org.eclipse.mylar.tasks.core.TaskRepository;
24
25
/**
26
 * 
27
 * @author Jeff Pound
28
 */
29
public class BugzillaDuplicateDetectionTest extends TestCase {
30
31
	private TaskRepository repository;
32
33
	@Override
34
	protected void setUp() throws Exception {
35
		super.setUp();
36
		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND, IBugzillaConstants.TEST_BUGZILLA_222_URL);
37
	}
38
39
	public void testDuplicateDetection() throws Exception {
40
		String stackTrace = "java.lang.NullPointerException\njeff.testing.stack.trace.functionality";
41
		String fakeStackTrace = "thisisnotreallyastacktrace";
42
		int numMatches = 2;
43
44
		NewBugzillaReportWizard wizard = new NewBugzillaReportWizard(repository, null);
45
		DuplicateDetectionData dupData = new DuplicateDetectionData();
46
		dupData.setStackTrace(stackTrace);
47
48
		List<AbstractRepositoryTask> tasks = wizard.searchForDuplicates(dupData);
49
		assertNotNull(tasks);
50
		assertEquals(numMatches, tasks.size());
51
		
52
		dupData.setStackTrace(fakeStackTrace);
53
		tasks = wizard.searchForDuplicates(dupData);
54
		assertNotNull(tasks);
55
		assertEquals(0, tasks.size());
56
	}
57
}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/wizard/NewBugzillaReportWizard.java (-76 / +5 lines)
Lines 10-40 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.mylar.internal.bugzilla.ui.wizard;
11
package org.eclipse.mylar.internal.bugzilla.ui.wizard;
12
12
13
import java.io.UnsupportedEncodingException;
14
import java.net.URLEncoder;
15
import java.util.Iterator;
16
import java.util.LinkedList;
17
import java.util.List;
18
19
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.core.runtime.Status;
14
import org.eclipse.core.runtime.Status;
23
import org.eclipse.jface.viewers.IStructuredSelection;
15
import org.eclipse.jface.viewers.IStructuredSelection;
24
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
16
import org.eclipse.jface.wizard.Wizard;
25
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
17
import org.eclipse.mylar.internal.bugzilla.core.NewBugzillaReport;
26
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
18
import org.eclipse.mylar.internal.bugzilla.ui.BugzillaUiPlugin;
27
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditorInput;
19
import org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditorInput;
28
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryQuery;
29
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
20
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
30
import org.eclipse.mylar.internal.tasks.ui.editors.AbstractBugEditorInput;
31
import org.eclipse.mylar.internal.tasks.ui.editors.ExistingBugEditorInput;
32
import org.eclipse.mylar.internal.tasks.ui.wizards.AbstractDuplicateDetectingReportWizard;
33
import org.eclipse.mylar.internal.tasks.ui.wizards.DuplicateDetectionData;
34
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
35
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
36
import org.eclipse.mylar.tasks.core.TaskRepository;
21
import org.eclipse.mylar.tasks.core.TaskRepository;
37
import org.eclipse.mylar.tasks.ui.AbstractRepositoryConnector;
38
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
22
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
39
import org.eclipse.ui.INewWizard;
23
import org.eclipse.ui.INewWizard;
40
import org.eclipse.ui.IWorkbench;
24
import org.eclipse.ui.IWorkbench;
Lines 45-51 Link Here
45
 * @author Mik Kersten
29
 * @author Mik Kersten
46
 * @author Rob Elves
30
 * @author Rob Elves
47
 */
31
 */
48
public class NewBugzillaReportWizard extends AbstractDuplicateDetectingReportWizard implements INewWizard {
32
public class NewBugzillaReportWizard extends Wizard implements INewWizard {
49
33
50
	private static final String TITLE = "New Bugzilla Task";
34
	private static final String TITLE = "New Bugzilla Task";
51
35
Lines 91-118 Link Here
91
		super.addPages();
75
		super.addPages();
92
		addPage(productPage);
76
		addPage(productPage);
93
77
94
		super.addQueuedPages();
95
	}
78
	}
96
79
97
	@Override
80
	@Override
98
	public boolean canFinish() {
81
	public boolean canFinish() {
99
		return completed && super.canFinish();
82
		return completed;
100
	}
83
	}
101
84
102
	@Override
85
	@Override
103
	public boolean performFinish() {
86
	public boolean performFinish() {
104
		List<AbstractRepositoryTask> dups = getSelectedDuplicates();
87
105
		if (dups != null && !dups.isEmpty()) {
106
			Iterator<AbstractRepositoryTask> iter = dups.iterator();
107
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
108
			while (iter.hasNext()) {
109
				AbstractRepositoryTask task = iter.next();
110
				AbstractBugEditorInput editorInput = new ExistingBugEditorInput(TasksUiPlugin.getRepositoryManager()
111
						.getRepository(task.getRepositoryKind(), task.getRepositoryUrl()), task.getTaskData());
112
				TaskUiUtil.openEditor(editorInput, BugzillaUiPlugin.EXISTING_BUG_EDITOR_ID, page);
113
			}
114
			return true;
115
		}
116
		try {
88
		try {
117
			productPage.saveDataToModel();
89
			productPage.saveDataToModel();
118
			NewBugEditorInput editorInput = new NewBugEditorInput(repository, model);
90
			NewBugEditorInput editorInput = new NewBugEditorInput(repository, model);
Lines 126-174 Link Here
126
		return false;
98
		return false;
127
	}
99
	}
128
100
129
	/**
130
	 * Perform a query using the given duplicate detection criteria and return a
131
	 * list of tasks which match.
132
	 */
133
	@Override
134
	public List<AbstractRepositoryTask> searchForDuplicates(DuplicateDetectionData data) {
135
		// RepositoryQueryResultsFactory factory = new
136
		// RepositoryQueryResultsFactory();
137
		// IBugzillaSearchResultCollector collector = new
138
		// BugzillaSearchResultCollector();
139
		// factory.performQuery(repository.getUrl(), collector, queryUrl,
140
		// proxySettings, 20, BugzillaPlugin.ENCODING_UTF_8);
141
142
		String[] products = productPage.getSelectedProducts();
143
144
		// TODO: Is there a class that can create this string?
145
		String queryUrl;
146
		try {
147
			queryUrl = repository.getUrl() + "/buglist.cgi?long_desc_type=allwordssubstr&long_desc="
148
					+ URLEncoder.encode("Stack Trace:\n" + data.getStackTrace(), BugzillaPlugin.ENCODING_UTF_8);
149
		} catch (UnsupportedEncodingException e) {
150
			// This should never happen
151
			return null;
152
		}
153
154
		for (int i = 0; i < products.length; i++) {
155
			queryUrl += "&product=" + products[i];
156
		}
157
158
		List<AbstractRepositoryTask> tasks = new LinkedList<AbstractRepositoryTask>();
159
		BugzillaRepositoryQuery repositoryQuery = new BugzillaRepositoryQuery(repository.getUrl(), queryUrl,
160
				"DUPLICATE_DETECTION_QUERY", "20", TasksUiPlugin.getTaskListManager().getTaskList());
161
		AbstractRepositoryConnector connector = (AbstractRepositoryConnector) TasksUiPlugin.getRepositoryManager()
162
				.getRepositoryConnector(BugzillaPlugin.REPOSITORY_KIND);
163
		List<AbstractQueryHit> hits = connector.performQuery(repositoryQuery, new NullProgressMonitor(),
164
				new MultiStatus(TasksUiPlugin.PLUGIN_ID, IStatus.OK, "Query result", null));
165
		Iterator<AbstractQueryHit> iterator = hits.iterator();
166
		while (iterator.hasNext()) {
167
			tasks.add(iterator.next().getOrCreateCorrespondingTask());
168
		}
169
170
		return tasks;
171
	}
172
}
101
}
173
102
174
// @Override
103
// @Override
Lines 231-234 Link Here
231
// MylarTaskListPlugin.getSynchronizationManager().synchNow(0);
160
// MylarTaskListPlugin.getSynchronizationManager().synchNow(0);
232
//
161
//
233
// return true;
162
// return true;
234
// }
163
// }
(-)src/org/eclipse/mylar/internal/bugzilla/ui/wizard/BugzillaProductPage.java (-2 / +2 lines)
Lines 287-293 Link Here
287
		listBox.setFocus();
287
		listBox.setFocus();
288
	}
288
	}
289
289
290
	protected String[] getSelectedProducts() {
290
	private String[] getSelectedProducts() {
291
		ArrayList<String> products = new ArrayList<String>();
291
		ArrayList<String> products = new ArrayList<String>();
292
		if (selection == null) {
292
		if (selection == null) {
293
			return products.toArray(new String[0]);
293
			return products.toArray(new String[0]);
Lines 513-516 Link Here
513
	// return super.getNextPage();
513
	// return super.getNextPage();
514
	// }
514
	// }
515
515
516
}
516
}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/ExistingBugEditor.java (-4 lines)
Lines 261-270 Link Here
261
		FormToolkit toolkit = new FormToolkit(composite.getDisplay());
261
		FormToolkit toolkit = new FormToolkit(composite.getDisplay());
262
		RepositoryTaskAttribute owner = taskData.getAttribute(RepositoryTaskAttribute.USER_ASSIGNED);
262
		RepositoryTaskAttribute owner = taskData.getAttribute(RepositoryTaskAttribute.USER_ASSIGNED);
263
263
264
		if (repository.getUserName() == null) {
265
			return;
266
		}
267
		
268
		if (owner != null && owner.getValue().indexOf(repository.getUserName()) != -1) {
264
		if (owner != null && owner.getValue().indexOf(repository.getUserName()) != -1) {
269
			return;
265
			return;
270
		}
266
		}
(-)src/org/eclipse/mylar/internal/bugzilla/ui/editor/NewBugEditor.java (-2 / +64 lines)
Lines 12-17 Link Here
12
12
13
import java.io.UnsupportedEncodingException;
13
import java.io.UnsupportedEncodingException;
14
import java.net.Proxy;
14
import java.net.Proxy;
15
import java.net.URLEncoder;
15
import java.util.Calendar;
16
import java.util.Calendar;
16
import java.util.GregorianCalendar;
17
import java.util.GregorianCalendar;
17
18
Lines 26-31 Link Here
26
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
27
import org.eclipse.mylar.internal.bugzilla.core.BugzillaReportSubmitForm;
27
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
28
import org.eclipse.mylar.internal.bugzilla.ui.WebBrowserDialog;
29
import org.eclipse.mylar.internal.bugzilla.ui.WebBrowserDialog;
30
import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchOperation;
31
import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchQuery;
32
import org.eclipse.mylar.internal.bugzilla.ui.search.BugzillaSearchResultCollector;
33
import org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchOperation;
34
import org.eclipse.mylar.internal.bugzilla.ui.search.IBugzillaSearchResultCollector;
29
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
35
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryConnector;
30
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
36
import org.eclipse.mylar.internal.tasks.ui.TaskUiUtil;
31
import org.eclipse.mylar.internal.tasks.ui.editors.AbstractRepositoryTaskEditor;
37
import org.eclipse.mylar.internal.tasks.ui.editors.AbstractRepositoryTaskEditor;
Lines 38-46 Link Here
38
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
44
import org.eclipse.mylar.tasks.core.RepositoryTaskData;
39
import org.eclipse.mylar.tasks.core.TaskCategory;
45
import org.eclipse.mylar.tasks.core.TaskCategory;
40
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
46
import org.eclipse.mylar.tasks.ui.TasksUiPlugin;
47
import org.eclipse.search.ui.NewSearchUI;
41
import org.eclipse.swt.SWT;
48
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.layout.GridData;
49
import org.eclipse.swt.layout.GridData;
43
import org.eclipse.swt.layout.GridLayout;
50
import org.eclipse.swt.layout.GridLayout;
51
import org.eclipse.swt.widgets.Button;
44
import org.eclipse.swt.widgets.Composite;
52
import org.eclipse.swt.widgets.Composite;
45
import org.eclipse.swt.widgets.Event;
53
import org.eclipse.swt.widgets.Event;
46
import org.eclipse.swt.widgets.Listener;
54
import org.eclipse.swt.widgets.Listener;
Lines 61-72 Link Here
61
 */
69
 */
62
public class NewBugEditor extends AbstractRepositoryTaskEditor {
70
public class NewBugEditor extends AbstractRepositoryTaskEditor {
63
71
72
	private static final String NO_STACK_MESSAGE = "Unable to locate a stack trace in the description text.\nDuplicate search currently only supports stack trace matching.";
73
64
	private static final String ERROR_CREATING_BUG_REPORT = "Error creating bug report";
74
	private static final String ERROR_CREATING_BUG_REPORT = "Error creating bug report";
65
75
76
	private static final String LABEL_BUTTON_SEARCH_DUPS = "Search for Duplicates";
77
66
	protected RepositoryTaskData taskData;
78
	protected RepositoryTaskData taskData;
67
79
68
	protected String newSummary = "";
80
	protected String newSummary = "";
69
81
82
	private Button searchDuplicatesButton;
83
70
	@Override
84
	@Override
71
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
85
	public void init(IEditorSite site, IEditorInput input) throws PartInitException {
72
		if (!(input instanceof NewBugEditorInput))
86
		if (!(input instanceof NewBugEditorInput))
Lines 172-177 Link Here
172
		return taskData.getLabel();
186
		return taskData.getLabel();
173
	}
187
	}
174
188
189
	protected void searchForDuplicates() {
190
191
		String stackTrace = getStackTraceFromDescription();
192
		if (stackTrace == null) {
193
			MessageDialog.openWarning(null, "No Stack Trace Found", NO_STACK_MESSAGE);
194
			return;
195
		}
196
197
		String queryUrl = "";
198
		try {
199
			queryUrl = repository.getUrl() + "/buglist.cgi?long_desc_type=allwordssubstr&long_desc="
200
					+ URLEncoder.encode("Stack Trace:\n" + stackTrace, BugzillaPlugin.ENCODING_UTF_8);
201
		} catch (UnsupportedEncodingException e) {
202
			// This should never happen
203
		}
204
205
		queryUrl += "&product=" + getRepositoryTaskData().getProduct();
206
207
		IBugzillaSearchResultCollector resultCollector = new BugzillaSearchResultCollector();
208
		IBugzillaSearchOperation operation = new BugzillaSearchOperation(repository, queryUrl, TasksUiPlugin
209
				.getDefault().getProxySettings(), resultCollector, "100");
210
		BugzillaSearchQuery query = new BugzillaSearchQuery(operation);
211
212
		NewSearchUI.runQueryInBackground(query);
213
	}
214
215
	private String getStackTraceFromDescription() {
216
		String description = newDescriptionTextViewer.getTextWidget().getText().trim();
217
		// TODO: improve stack trace detection
218
		int index;
219
		String stackIdentifier = "Stack Trace:\n";
220
		if (description == null || (index = description.indexOf(stackIdentifier)) < 0) {
221
			return null;
222
		}
223
224
		description = description.substring(index + stackIdentifier.length());
225
		return description;
226
	}
227
175
	@Override
228
	@Override
176
	protected void submitBug() {
229
	protected void submitBug() {
177
		submitButton.setEnabled(false);
230
		submitButton.setEnabled(false);
Lines 237-243 Link Here
237
									Calendar reminderCalendar = GregorianCalendar.getInstance();
290
									Calendar reminderCalendar = GregorianCalendar.getInstance();
238
									TasksUiPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
291
									TasksUiPlugin.getTaskListManager().setScheduledToday(reminderCalendar);
239
									TasksUiPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime());
292
									TasksUiPlugin.getTaskListManager().setReminder(newTask, reminderCalendar.getTime());
240
									
293
241
									TaskUiUtil.refreshAndOpenTaskListElement(newTask);
294
									TaskUiUtil.refreshAndOpenTaskListElement(newTask);
242
								}
295
								}
243
								return;
296
								return;
Lines 344-349 Link Here
344
397
345
	protected void addActionButtons(Composite buttonComposite) {
398
	protected void addActionButtons(Composite buttonComposite) {
346
		FormToolkit toolkit = new FormToolkit(buttonComposite.getDisplay());
399
		FormToolkit toolkit = new FormToolkit(buttonComposite.getDisplay());
400
		searchDuplicatesButton = toolkit.createButton(buttonComposite, LABEL_BUTTON_SEARCH_DUPS, SWT.NONE);
401
		GridData searchDuplicatesButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
402
		searchDuplicatesButton.setLayoutData(searchDuplicatesButtonData);
403
		searchDuplicatesButton.addListener(SWT.Selection, new Listener() {
404
			public void handleEvent(Event e) {
405
				searchForDuplicates();
406
			}
407
		});
408
347
		submitButton = toolkit.createButton(buttonComposite, "Create", SWT.NONE);
409
		submitButton = toolkit.createButton(buttonComposite, "Create", SWT.NONE);
348
		GridData submitButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
410
		GridData submitButtonData = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
349
		submitButton.setLayoutData(submitButtonData);
411
		submitButton.setLayoutData(submitButtonData);
Lines 354-358 Link Here
354
		});
416
		});
355
		submitButton.addListener(SWT.FocusIn, new GenericListener());
417
		submitButton.addListener(SWT.FocusIn, new GenericListener());
356
	}
418
	}
357
	
419
358
}
420
}
(-).refactorings/2006/7/30/refactorings.history (+5 lines)
Added Link Here
1
<?xml version="1.0" encoding="utf-8"?>
2
<session version="1.0">
3
<refactoring comment="Extract local variable 'stackIdentifier' from expression '&quot;Stack Trace:&quot;'&#10;- Variable name: 'stackIdentifier'&#10;- Destination method: 'org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditor.getStackTraceFromDescription()'&#10;- Variable expression: '&quot;Stack Trace:&quot;'&#10;- Replace occurrences of expression with variable" description="Extract local variable 'stackIdentifier'" final="false" id="org.eclipse.jdt.ui.extract.temp" input="/src&lt;org.eclipse.mylar.internal.bugzilla.ui.editor{NewBugEditor.java" name="stackIdentifier" replace="true" selection="8464 14" stamp="1154025692191" version="1.0"/>
4
<refactoring comment="Extract constant 'org.eclipse.mylar.internal.bugzilla.ui.editor.NewBugEditor.NO_STACK_MESSAGE' from expression '&quot;Unable to locate a stack trace in the description text.\nDuplicate search currently only supports stack trace matching.&quot;'&#10;- Constant name: 'NO_STACK_MESSAGE'&#10;- Constant expression: '&quot;Unable to locate a stack trace in the description text.\nDuplicate search currently only supports stack trace matching.&quot;'&#10;- Declared visibility: 'private'&#10;- Replace occurrences of expression with constant" description="Extract constant 'NO_STACK_MESSAGE'" flags="786432" id="org.eclipse.jdt.ui.extract.constant" input="/src&lt;org.eclipse.mylar.internal.bugzilla.ui.editor{NewBugEditor.java" name="NO_STACK_MESSAGE" qualify="false" replace="true" selection="7580 0" stamp="1154026840382" version="1.0" visibility="2"/>
5
</session>
(-).refactorings/2006/7/30/refactorings.index (+2 lines)
Added Link Here
1
1154025692191	Extract local variable 'stackIdentifier'
2
1154026840382	Extract constant 'NO_STACK_MESSAGE'

Return to bug 143567