Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2004, 2007 Mylyn project 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.mylyn.internal.bugzilla.ide.actions; |
10 |
|
11 |
import org.eclipse.jdt.internal.junit.model.TestCaseElement; |
12 |
import org.eclipse.jdt.internal.junit.model.TestElement; |
13 |
import org.eclipse.jface.action.IAction; |
14 |
import org.eclipse.jface.dialogs.MessageDialog; |
15 |
import org.eclipse.jface.viewers.ISelection; |
16 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
17 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
18 |
import org.eclipse.jface.viewers.TreeSelection; |
19 |
import org.eclipse.jface.wizard.WizardDialog; |
20 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiConstants; |
21 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.NewTaskWizard; |
22 |
import org.eclipse.mylyn.tasks.ui.editors.AbstractRepositoryTaskEditor; |
23 |
import org.eclipse.mylyn.tasks.ui.editors.TaskEditor; |
24 |
import org.eclipse.swt.dnd.Clipboard; |
25 |
import org.eclipse.swt.dnd.TextTransfer; |
26 |
import org.eclipse.swt.dnd.Transfer; |
27 |
import org.eclipse.swt.widgets.Shell; |
28 |
import org.eclipse.ui.IViewActionDelegate; |
29 |
import org.eclipse.ui.IViewPart; |
30 |
import org.eclipse.ui.IWorkbenchPage; |
31 |
import org.eclipse.ui.PlatformUI; |
32 |
import org.eclipse.ui.internal.ViewPluginAction; |
33 |
|
34 |
/** |
35 |
* Creates a new task from the selected JUnit Test. |
36 |
* |
37 |
* @author Frank Becker |
38 |
*/ |
39 |
public class NewTaskFromFailureAction implements IViewActionDelegate, ISelectionChangedListener { |
40 |
|
41 |
public static final String ID = "org.eclipse.mylyn.tasklist.ui.repositories.actions.create"; |
42 |
|
43 |
public void run(IAction action) { |
44 |
String traceString = null; |
45 |
TestCaseElement testCaseElement = null; |
46 |
if (action instanceof ViewPluginAction) { |
47 |
ViewPluginAction a = (ViewPluginAction)action; |
48 |
ISelection selection = a.getSelection(); |
49 |
if (selection instanceof TreeSelection) { |
50 |
TreeSelection t = (TreeSelection) selection; |
51 |
TestElement testElement= (TestElement) t.getFirstElement(); |
52 |
if (testElement instanceof TestCaseElement) { |
53 |
testCaseElement= (TestCaseElement) testElement; |
54 |
traceString = testCaseElement.getTrace(); |
55 |
} |
56 |
} |
57 |
} |
58 |
if (traceString == null || testCaseElement == null) { |
59 |
return; |
60 |
} |
61 |
NewTaskWizard wizard = new NewTaskWizard(); |
62 |
|
63 |
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); |
64 |
if (shell != null && !shell.isDisposed()) { |
65 |
WizardDialog dialog = new WizardDialog(shell, wizard); |
66 |
dialog.setBlockOnOpen(true); |
67 |
if (dialog.open() == WizardDialog.CANCEL) { |
68 |
return; |
69 |
} |
70 |
|
71 |
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
72 |
AbstractRepositoryTaskEditor editor = null; |
73 |
|
74 |
String summary = ""; |
75 |
String description = "\n\n-- Error Log from JUnit --\nClass: " + testCaseElement.getTestClassName() |
76 |
+ "\nMethod: " + testCaseElement.getTestMethodName() + "\nActual: " + testCaseElement.getActual() |
77 |
+ "\nExpected: " + testCaseElement.getExpected() + "\nStack Trace:\n" + traceString; |
78 |
|
79 |
try { |
80 |
TaskEditor taskEditor = (TaskEditor) page.getActiveEditor(); |
81 |
editor = (AbstractRepositoryTaskEditor) taskEditor.getActivePageInstance(); |
82 |
} catch (ClassCastException e) { |
83 |
Clipboard clipboard = new Clipboard(page.getWorkbenchWindow().getShell().getDisplay()); |
84 |
clipboard.setContents(new Object[] { summary + "\n" + description }, |
85 |
new Transfer[] { TextTransfer.getInstance() }); |
86 |
|
87 |
MessageDialog.openInformation( |
88 |
page.getWorkbenchWindow().getShell(), |
89 |
ITasksUiConstants.TITLE_DIALOG, |
90 |
"This connector does not provide a rich task editor for creating tasks.\n\n" |
91 |
+ "The error contents have been placed in the clipboard so that you can paste them into the entry form."); |
92 |
return; |
93 |
} |
94 |
|
95 |
editor.setSummaryText(summary); |
96 |
editor.setDescriptionText(description); |
97 |
} |
98 |
} |
99 |
|
100 |
public void selectionChanged(SelectionChangedEvent event) { |
101 |
// ignore |
102 |
} |
103 |
|
104 |
public void init(IViewPart view) { |
105 |
// ignore |
106 |
} |
107 |
|
108 |
public void selectionChanged(IAction action, ISelection selection) { |
109 |
// ignore |
110 |
} |
111 |
} |