Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2014 IBM Corporation 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 |
* IBM Corporation - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.internal.junit.ui; |
12 |
|
13 |
import org.eclipse.swt.SWTError; |
14 |
import org.eclipse.swt.dnd.Clipboard; |
15 |
import org.eclipse.swt.dnd.DND; |
16 |
import org.eclipse.swt.dnd.TextTransfer; |
17 |
import org.eclipse.swt.dnd.Transfer; |
18 |
|
19 |
import org.eclipse.jface.dialogs.MessageDialog; |
20 |
|
21 |
import org.eclipse.ui.IWorkbenchPartSite; |
22 |
import org.eclipse.ui.actions.SelectionListenerAction; |
23 |
|
24 |
import org.eclipse.jdt.internal.junit.model.TestCaseElement; |
25 |
import org.eclipse.jdt.internal.junit.model.TestElement; |
26 |
import org.eclipse.jdt.internal.junit.model.TestSuiteElement; |
27 |
|
28 |
import org.eclipse.jdt.internal.ui.actions.ActionMessages; |
29 |
import org.eclipse.jdt.internal.ui.actions.CopyQualifiedNameAction; |
30 |
|
31 |
public class JUnitCopyQualifiedNameAction extends SelectionListenerAction { |
32 |
|
33 |
private IWorkbenchPartSite fSite; |
34 |
private Clipboard fClipboard; |
35 |
private TestElement fTestElement; |
36 |
|
37 |
|
38 |
public JUnitCopyQualifiedNameAction(IWorkbenchPartSite site, Clipboard clipboard) { |
39 |
super(ActionMessages.CopyQualifiedNameAction_ActionName); |
40 |
setActionDefinitionId(CopyQualifiedNameAction.ACTION_DEFINITION_ID); |
41 |
setToolTipText(ActionMessages.CopyQualifiedNameAction_ToolTipText); |
42 |
fSite= site; |
43 |
fClipboard= clipboard; |
44 |
} |
45 |
|
46 |
public void handleTestSelected(TestElement test) { |
47 |
fTestElement= test; |
48 |
setEnabled(fTestElement != null); |
49 |
} |
50 |
|
51 |
/* |
52 |
* SelectionListener |
53 |
*/ |
54 |
|
55 |
@Override |
56 |
public void run() { |
57 |
|
58 |
String qualifiedName; |
59 |
if (fTestElement instanceof TestSuiteElement) { |
60 |
qualifiedName= ((TestSuiteElement)fTestElement).getClassName(); |
61 |
} else if (fTestElement instanceof TestCaseElement) { |
62 |
qualifiedName= ((TestCaseElement)fTestElement).getClassName() |
63 |
+ "." //$NON-NLS-1$ |
64 |
+ ((TestCaseElement)fTestElement).getTestMethodName() |
65 |
+"()"; //$NON-NLS-1$ |
66 |
} else { |
67 |
qualifiedName= null; |
68 |
} |
69 |
|
70 |
if (qualifiedName != null) { |
71 |
TextTransfer plainTextTransfer= TextTransfer.getInstance(); |
72 |
try{ |
73 |
fClipboard.setContents( |
74 |
new String[]{ qualifiedName }, |
75 |
new Transfer[]{ plainTextTransfer }); |
76 |
} catch (SWTError e){ |
77 |
if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD) |
78 |
throw e; |
79 |
if (MessageDialog.openQuestion(fSite.getShell(), JUnitMessages.CopyTraceAction_problem, JUnitMessages.CopyTraceAction_clipboard_busy)) |
80 |
run(); |
81 |
} |
82 |
} |
83 |
} |
84 |
|
85 |
} |