blob: 6be8639141a0879ef5b8b44ab4a0008846a9c6de (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*******************************************************************************
* Copyright (c) 2011, 2012 Anton Gorenkov
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Anton Gorenkov - initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.testsrunner.internal.ui.view.actions;
import java.util.Iterator;
import org.eclipse.cdt.testsrunner.internal.ui.view.TestPathUtils;
import org.eclipse.cdt.testsrunner.model.ITestItem;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
import org.eclipse.swt.dnd.Transfer;
import org.eclipse.ui.IWorkbenchCommandConstants;
/**
* Copies the name of the selected test items (test suites or cases) to the
* clipboard.
*/
public class CopySelectedTestsAction extends Action {
private TreeViewer treeViewer;
private Clipboard clipboard;
public CopySelectedTestsAction(TreeViewer treeViewer, Clipboard clipboard) {
super(ActionsMessages.CopySelectedTestsAction_text);
setToolTipText(ActionsMessages.CopySelectedTestsAction_tooltip);
setActionDefinitionId(IWorkbenchCommandConstants.EDIT_COPY);
this.treeViewer = treeViewer;
this.clipboard = clipboard;
}
@Override
public void run() {
IStructuredSelection selection = (IStructuredSelection)treeViewer.getSelection();
if (!selection.isEmpty()) {
StringBuilder sb = new StringBuilder();
boolean needEOL = false;
for (Iterator<?> it = selection.iterator(); it.hasNext();) {
if (needEOL) {
sb.append(System.getProperty("line.separator")); //$NON-NLS-1$
} else {
needEOL = true;
}
sb.append(TestPathUtils.getTestItemPath((ITestItem)it.next()));
}
clipboard.setContents(
new String[]{ sb.toString() },
new Transfer[]{ TextTransfer.getInstance() });
}
}
}
|