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

Collapse All | Expand All

(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java (-5 / +91 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Xavier Coulon <xcoulon@redhat.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
10
 *     Xavier Coulon <xcoulon@redhat.com> 
11
 *     - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
12
 *     - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588 - [JUnit] Add "Link with Editor" to JUnit view 
11
 *******************************************************************************/
13
 *******************************************************************************/
12
14
13
package org.eclipse.jdt.internal.junit.model;
15
package org.eclipse.jdt.internal.junit.model;
Lines 15-23 Link Here
15
import org.eclipse.jdt.junit.model.ITestCaseElement;
17
import org.eclipse.jdt.junit.model.ITestCaseElement;
16
18
17
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.IAdaptable;
18
21
22
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.JavaModelException;
19
26
20
public class TestCaseElement extends TestElement implements ITestCaseElement {
27
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
28
29
/**
30
 * 
31
 * @since 3.7 implements {@link IAdaptable}
32
 */
33
public class TestCaseElement extends TestElement implements ITestCaseElement, IAdaptable {
34
35
	private IMethod fJavaMethod= null;
36
37
	private boolean fJavaMethodResolved= false;
21
38
22
	private boolean fIgnored;
39
	private boolean fIgnored;
23
40
Lines 27-33 Link Here
27
	}
44
	}
28
45
29
	/**
46
	/**
47
	 * @return the name of the Java Method associated with this {@link TestCaseElement}, ie, it
48
	 *         returns the valid java identifier part of the name (in particular, it removes the
49
	 *         brackets suffix for Parameterized JUnit tests).
50
	 * 
51
	 * 
52
	 */
53
	private String getJavaTestMethodName() {
54
		String testMethodName= getTestMethodName();
55
		for (int i= 0; i < testMethodName.length(); i++) {
56
			if (!Character.isJavaIdentifierPart(testMethodName.charAt(i))) {
57
				return testMethodName.substring(0, i);
58
			}
59
		}
60
		return testMethodName;
61
	}
62
63
	/**
30
	 * {@inheritDoc}
64
	 * {@inheritDoc}
65
	 * 
31
	 * @see org.eclipse.jdt.junit.model.ITestCaseElement#getTestMethodName()
66
	 * @see org.eclipse.jdt.junit.model.ITestCaseElement#getTestMethodName()
32
	 * @see org.eclipse.jdt.internal.junit.runner.MessageIds#TEST_IDENTIFIER_MESSAGE_FORMAT
67
	 * @see org.eclipse.jdt.internal.junit.runner.MessageIds#TEST_IDENTIFIER_MESSAGE_FORMAT
33
	 * @see org.eclipse.jdt.internal.junit.runner.MessageIds#IGNORED_TEST_PREFIX
68
	 * @see org.eclipse.jdt.internal.junit.runner.MessageIds#IGNORED_TEST_PREFIX
Lines 35-50 Link Here
35
	public String getTestMethodName() {
70
	public String getTestMethodName() {
36
		String testName= getTestName();
71
		String testName= getTestName();
37
		int index= testName.lastIndexOf('(');
72
		int index= testName.lastIndexOf('(');
38
		if (index > 0)
73
		if (index > 0) {
39
			return testName.substring(0, index);
74
			return testName.substring(0, index);
75
		}
76
		index= testName.indexOf('(');
77
		if (index > 0) {
78
			return testName.substring(0, index);
79
		}
40
		index= testName.indexOf('@');
80
		index= testName.indexOf('@');
41
		if (index > 0)
81
		if (index > 0) {
42
			return testName.substring(0, index);
82
			return testName.substring(0, index);
83
		}
43
		return testName;
84
		return testName;
44
	}
85
	}
45
86
46
	/**
87
	/**
88
	 * Finds and returns the {@link IMethod} associated with this {@link TestCaseElement}.
89
	 * 
90
	 * @return the corresponding Java method element or null if not found.
91
	 */
92
	public IMethod getJavaMethod() {
93
		if (!fJavaMethodResolved) {
94
			try {
95
				final IType type= getJavaType();
96
				if (type != null) {
97
					final IMethod[] methods= type.getMethods();
98
					String testMethodName= getJavaTestMethodName();
99
					for (int i= 0; i < methods.length; i++) {
100
						if (methods[i].getElementName().equals(testMethodName)) {
101
							fJavaMethod= methods[i];
102
							return methods[i];
103
						}
104
					}
105
				}
106
				return null;
107
			} catch (JavaModelException e) {
108
				JUnitCorePlugin.log(e);
109
			} finally {
110
				fJavaMethodResolved= true;
111
			}
112
		}
113
		return fJavaMethod;
114
	}
115
116
	/**
47
	 * {@inheritDoc}
117
	 * {@inheritDoc}
118
	 * 
48
	 * @see org.eclipse.jdt.junit.model.ITestCaseElement#getTestClassName()
119
	 * @see org.eclipse.jdt.junit.model.ITestCaseElement#getTestClassName()
49
	 */
120
	 */
50
	public String getTestClassName() {
121
	public String getTestClassName() {
Lines 61-67 Link Here
61
		else
132
		else
62
			return super.getTestResult(includeChildren);
133
			return super.getTestResult(includeChildren);
63
	}
134
	}
64
	
135
65
	public void setIgnored(boolean ignored) {
136
	public void setIgnored(boolean ignored) {
66
		fIgnored= ignored;
137
		fIgnored= ignored;
67
	}
138
	}
Lines 73-76 Link Here
73
	public String toString() {
144
	public String toString() {
74
		return "TestCase: " + getTestClassName() + "." + getTestMethodName() + " : " + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
145
		return "TestCase: " + getTestClassName() + "." + getTestMethodName() + " : " + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
75
	}
146
	}
147
148
	/**
149
	 * Provides support for converting this {@link TestCaseElement} into an {@link IMethod} when the
150
	 * given adapter class is {@link IJavaElement}.
151
	 * 
152
	 * @param adapter the class in which this {@link TestCaseElement} should be adapted.
153
	 * @return an object in the request type, or null if it could not be adapted.
154
	 * @since 3.7
155
	 */
156
	public Object getAdapter(Class adapter) {
157
		if (adapter != null && adapter.equals(IJavaElement.class)) {
158
			return getJavaMethod();
159
		}
160
		return null;
161
	}
76
}
162
}
(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java (+27 lines)
Lines 20-25 Link Here
20
20
21
import org.eclipse.core.runtime.Assert;
21
import org.eclipse.core.runtime.Assert;
22
22
23
import org.eclipse.jdt.core.IType;
24
import org.eclipse.jdt.core.JavaModelException;
25
26
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
27
23
28
24
public abstract class TestElement implements ITestElement {
29
public abstract class TestElement implements ITestElement {
25
	public final static class Status {
30
	public final static class Status {
Lines 175-180 Link Here
175
180
176
	private boolean fAssumptionFailed;
181
	private boolean fAssumptionFailed;
177
182
183
	private IType fJavaType= null;
184
185
	private boolean fJavaTypeResolved= false;
186
178
	/**
187
	/**
179
	 * Running time in seconds. Contents depend on the current {@link #getProgressState()}:
188
	 * Running time in seconds. Contents depend on the current {@link #getProgressState()}:
180
	 * <ul>
189
	 * <ul>
Lines 324-329 Link Here
324
		return extractClassName(getTestName());
333
		return extractClassName(getTestName());
325
	}
334
	}
326
335
336
	/**
337
	 * @return the Java {@link IType} associated with this {@link TestElement}.
338
	 */
339
	public IType getJavaType() {
340
		if (!fJavaTypeResolved) {
341
			try {
342
				fJavaType= getTestRunSession().getLaunchedProject().findType(getClassName());
343
			} catch (JavaModelException e) {
344
				JUnitCorePlugin.log(e);
345
			} finally {
346
				fJavaTypeResolved= true;
347
			}
348
		}
349
		return fJavaType;
350
	}
351
352
353
327
	private static String extractClassName(String testNameString) {
354
	private static String extractClassName(String testNameString) {
328
		testNameString= extractRawClassName(testNameString);
355
		testNameString= extractRawClassName(testNameString);
329
		testNameString= testNameString.replace('$', '.'); // see bug 178503
356
		testNameString= testNameString.replace('$', '.'); // see bug 178503
(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestSuiteElement.java (-1 / +67 lines)
Lines 17-24 Link Here
17
import org.eclipse.jdt.junit.model.ITestElement;
17
import org.eclipse.jdt.junit.model.ITestElement;
18
import org.eclipse.jdt.junit.model.ITestSuiteElement;
18
import org.eclipse.jdt.junit.model.ITestSuiteElement;
19
19
20
import org.eclipse.core.runtime.IAdaptable;
20
21
21
public class TestSuiteElement extends TestElement implements ITestSuiteElement {
22
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IType;
25
26
27
public class TestSuiteElement extends TestElement implements ITestSuiteElement, IAdaptable {
28
29
	private IJavaElement fJavaElement= null;
30
31
	private boolean fJavaElementResolved= false;
22
32
23
	private List/*<TestElement>*/ fChildren;
33
	private List/*<TestElement>*/ fChildren;
24
	private Status fChildrenStatus;
34
	private Status fChildrenStatus;
Lines 151-154 Link Here
151
		return "TestSuite: " + getSuiteTypeName() + " : " + super.toString() + " (" + fChildren.size() + ")";   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
161
		return "TestSuite: " + getSuiteTypeName() + " : " + super.toString() + " (" + fChildren.size() + ")";   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
152
	}
162
	}
153
163
164
	/**
165
	 * Provides support for converting this {@link TestSuiteElement} into an {@link IType} (or an
166
	 * {@link IMethod} when this {@link TestSuiteElement} matches a JUnit Parameterized Test) when
167
	 * the given adapter class is {@link IJavaElement}.
168
	 * 
169
	 * @param adapter the class in which this {@link TestSuiteElement} should be adapted.
170
	 * @return an object in the request type, or null if it could not be adapted.
171
	 * @since 3.7
172
	 */
173
	public Object getAdapter(Class adapter) {
174
		if (adapter != null && adapter.equals(IJavaElement.class)) {
175
			return getJavaElement();
176
		}
177
		return null;
178
	}
179
180
	/**
181
	 * Returns the closest {@link IJavaElement} for the given {@link TestSuiteElement}, including
182
	 * with a work-around for Parameterized tests by looking at the child elements: if there's only
183
	 * one, return its Java {@link IMethod}. Otherwise, return the {@link IType}
184
	 * 
185
	 * @return the {@link IJavaElement} found for this {@link TestSuiteElement}.
186
	 * 
187
	 * @see TestElement#getJavaType()
188
	 */
189
	public IJavaElement getJavaElement() {
190
		if (!fJavaElementResolved) {
191
			// whatever happens, let's consider that the Java Type has been resolved, to make sure we don't come back here again for this TestSuitElement.
192
			fJavaElementResolved= true;
193
			fJavaElement= super.getJavaType();
194
			if (fJavaElement == null) {
195
				if (getChildren().length == 1 && getChildren()[0] instanceof TestCaseElement) {
196
					fJavaElement= ((TestCaseElement)getChildren()[0]).getJavaMethod();
197
				}
198
			}
199
		}
200
		return fJavaElement;
201
	}
202
203
	/**
204
	 * Returns the {@link IType} associated with the given {@link TestSuiteElement}, or uses the
205
	 * work-around in {@link TestSuiteElement#getJavaElement()} to retrieve the {@link IType}
206
	 * associated with the single child {@link TestCaseElement} if this {@link TestSuiteElement}
207
	 * matches a Parameterized JUnit Test.
208
	 * 
209
	 * @see TestElement#getJavaType()
210
	 */
211
	public IType getJavaType() {
212
		final IType javaType= super.getJavaType();
213
		if (javaType != null) {
214
			return javaType;
215
		} else if (getJavaElement() != null) {
216
			return (IType)fJavaElement.getAncestor(IJavaElement.TYPE);
217
		}
218
		return null;
219
	}
154
}
220
}
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java (-151 / +343 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2013 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 16-21 Link Here
16
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Rerun failed first does not work with JUnit4 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140392
16
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Rerun failed first does not work with JUnit4 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140392
17
 *     Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
17
 *     Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
18
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Add a monospace font option for the junit results view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411794
18
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Add a monospace font option for the junit results view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411794
19
 *     Xavier Coulon <xcoulon@redhat.com> -  [JUnit] Add "Link with Editor" to JUnit view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588
19
 *******************************************************************************/
20
 *******************************************************************************/
20
package org.eclipse.jdt.internal.junit.ui;
21
package org.eclipse.jdt.internal.junit.ui;
21
22
Lines 96-101 Link Here
96
import org.eclipse.jface.dialogs.MessageDialog;
97
import org.eclipse.jface.dialogs.MessageDialog;
97
import org.eclipse.jface.operation.IRunnableWithProgress;
98
import org.eclipse.jface.operation.IRunnableWithProgress;
98
import org.eclipse.jface.resource.ImageDescriptor;
99
import org.eclipse.jface.resource.ImageDescriptor;
100
import org.eclipse.jface.viewers.ISelection;
99
101
100
import org.eclipse.ui.IActionBars;
102
import org.eclipse.ui.IActionBars;
101
import org.eclipse.ui.IEditorActionBarContributor;
103
import org.eclipse.ui.IEditorActionBarContributor;
Lines 149-154 Link Here
149
151
150
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
152
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
151
153
154
import org.eclipse.jdt.internal.ui.JavaPluginImages;
155
import org.eclipse.jdt.internal.ui.actions.AbstractToggleLinkingAction;
152
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
156
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
153
157
154
/**
158
/**
Lines 159-185 Link Here
159
	public static final String NAME= "org.eclipse.jdt.junit.ResultView"; //$NON-NLS-1$
163
	public static final String NAME= "org.eclipse.jdt.junit.ResultView"; //$NON-NLS-1$
160
164
161
	private static final String RERUN_LAST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunLast"; //$NON-NLS-1$
165
	private static final String RERUN_LAST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunLast"; //$NON-NLS-1$
166
162
	private static final String RERUN_FAILED_FIRST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunFailedFirst"; //$NON-NLS-1$
167
	private static final String RERUN_FAILED_FIRST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunFailedFirst"; //$NON-NLS-1$
163
168
164
	static final int REFRESH_INTERVAL= 200;
169
	static final int REFRESH_INTERVAL= 200;
165
170
166
	static final int LAYOUT_FLAT= 0;
171
	static final int LAYOUT_FLAT= 0;
172
167
	static final int LAYOUT_HIERARCHICAL= 1;
173
	static final int LAYOUT_HIERARCHICAL= 1;
168
174
169
	/**
175
	/**
170
	 * Whether the output scrolls and reveals tests as they are executed.
176
	 * Whether the output scrolls and reveals tests as they are executed.
171
	 */
177
	 */
172
	protected boolean fAutoScroll = true;
178
	protected boolean fAutoScroll= true;
179
173
	/**
180
	/**
174
	 * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
181
	 * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
175
	 * <code>VIEW_ORIENTATION_VERTICAL</code>, or <code>VIEW_ORIENTATION_AUTOMATIC</code>.
182
	 * <code>VIEW_ORIENTATION_VERTICAL</code>, or <code>VIEW_ORIENTATION_AUTOMATIC</code>.
176
	 */
183
	 */
177
	private int fOrientation= VIEW_ORIENTATION_AUTOMATIC;
184
	private int fOrientation= VIEW_ORIENTATION_AUTOMATIC;
185
178
	/**
186
	/**
179
	 * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
187
	 * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
180
	 * <code>VIEW_ORIENTATION_VERTICAL</code>.
188
	 * <code>VIEW_ORIENTATION_VERTICAL</code>.
181
	 */
189
	 */
182
	private int fCurrentOrientation;
190
	private int fCurrentOrientation;
191
183
	/**
192
	/**
184
	 * The current layout mode (LAYOUT_FLAT or LAYOUT_HIERARCHICAL).
193
	 * The current layout mode (LAYOUT_FLAT or LAYOUT_HIERARCHICAL).
185
	 */
194
	 */
Lines 188-203 Link Here
188
//	private boolean fTestIsRunning= false;
197
//	private boolean fTestIsRunning= false;
189
198
190
	protected JUnitProgressBar fProgressBar;
199
	protected JUnitProgressBar fProgressBar;
200
191
	protected ProgressImages fProgressImages;
201
	protected ProgressImages fProgressImages;
202
192
	protected Image fViewImage;
203
	protected Image fViewImage;
204
193
	protected CounterPanel fCounterPanel;
205
	protected CounterPanel fCounterPanel;
206
194
	protected boolean fShowOnErrorOnly= false;
207
	protected boolean fShowOnErrorOnly= false;
208
195
	protected Clipboard fClipboard;
209
	protected Clipboard fClipboard;
210
196
	protected volatile String fInfoMessage;
211
	protected volatile String fInfoMessage;
197
212
198
	private FailureTrace fFailureTrace;
213
	private FailureTrace fFailureTrace;
199
214
200
	private TestViewer fTestViewer;
215
	private TestViewer fTestViewer;
216
201
	/**
217
	/**
202
	 * Is the UI disposed?
218
	 * Is the UI disposed?
203
	 */
219
	 */
Lines 207-279 Link Here
207
	 * Actions
223
	 * Actions
208
	 */
224
	 */
209
	private Action fNextAction;
225
	private Action fNextAction;
226
210
	private Action fPreviousAction;
227
	private Action fPreviousAction;
211
228
212
	private StopAction fStopAction;
229
	private StopAction fStopAction;
230
231
232
	/**
233
	 * Helper to open and activate editors.
234
	 * 
235
	 * @since 3.7
236
	 */
237
	private LinkWithEditorAction fLinkWithEditorAction;
238
213
	private JUnitCopyAction fCopyAction;
239
	private JUnitCopyAction fCopyAction;
240
214
	private Action fPasteAction;
241
	private Action fPasteAction;
215
242
216
	private Action fRerunLastTestAction;
243
	private Action fRerunLastTestAction;
244
217
	private IHandlerActivation fRerunLastActivation;
245
	private IHandlerActivation fRerunLastActivation;
246
218
	private Action fRerunFailedFirstAction;
247
	private Action fRerunFailedFirstAction;
248
219
	private IHandlerActivation fRerunFailedFirstActivation;
249
	private IHandlerActivation fRerunFailedFirstActivation;
220
250
221
	private Action fFailuresOnlyFilterAction;
251
	private Action fFailuresOnlyFilterAction;
252
222
	private ScrollLockAction fScrollLockAction;
253
	private ScrollLockAction fScrollLockAction;
254
223
	private ToggleOrientationAction[] fToggleOrientationActions;
255
	private ToggleOrientationAction[] fToggleOrientationActions;
256
224
	private ShowTestHierarchyAction fShowTestHierarchyAction;
257
	private ShowTestHierarchyAction fShowTestHierarchyAction;
258
225
	private ShowTimeAction fShowTimeAction;
259
	private ShowTimeAction fShowTimeAction;
260
226
	private ActivateOnErrorAction fActivateOnErrorAction;
261
	private ActivateOnErrorAction fActivateOnErrorAction;
262
227
	private IMenuListener fViewMenuListener;
263
	private IMenuListener fViewMenuListener;
228
264
229
	private TestRunSession fTestRunSession;
265
	private TestRunSession fTestRunSession;
266
230
	private TestSessionListener fTestSessionListener;
267
	private TestSessionListener fTestSessionListener;
231
268
232
	private RunnerViewHistory fViewHistory;
269
	private RunnerViewHistory fViewHistory;
270
233
	private TestRunSessionListener fTestRunSessionListener;
271
	private TestRunSessionListener fTestRunSessionListener;
234
272
235
	final Image fStackViewIcon;
273
	final Image fStackViewIcon;
274
236
	final Image fTestRunOKIcon;
275
	final Image fTestRunOKIcon;
276
237
	final Image fTestRunFailIcon;
277
	final Image fTestRunFailIcon;
278
238
	final Image fTestRunOKDirtyIcon;
279
	final Image fTestRunOKDirtyIcon;
280
239
	final Image fTestRunFailDirtyIcon;
281
	final Image fTestRunFailDirtyIcon;
240
282
241
	final Image fTestIcon;
283
	final Image fTestIcon;
284
242
	final Image fTestOkIcon;
285
	final Image fTestOkIcon;
286
243
	final Image fTestErrorIcon;
287
	final Image fTestErrorIcon;
288
244
	final Image fTestFailIcon;
289
	final Image fTestFailIcon;
290
245
	final Image fTestAssumptionFailureIcon;
291
	final Image fTestAssumptionFailureIcon;
292
246
	final Image fTestRunningIcon;
293
	final Image fTestRunningIcon;
294
247
	final Image fTestIgnoredIcon;
295
	final Image fTestIgnoredIcon;
248
296
249
	final ImageDescriptor fSuiteIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuite.gif"); //$NON-NLS-1$
297
	final ImageDescriptor fSuiteIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuite.gif"); //$NON-NLS-1$
298
250
	final ImageDescriptor fSuiteOkIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteok.gif"); //$NON-NLS-1$
299
	final ImageDescriptor fSuiteOkIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteok.gif"); //$NON-NLS-1$
300
251
	final ImageDescriptor fSuiteErrorIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteerror.gif"); //$NON-NLS-1$
301
	final ImageDescriptor fSuiteErrorIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteerror.gif"); //$NON-NLS-1$
302
252
	final ImageDescriptor fSuiteFailIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuitefail.gif"); //$NON-NLS-1$
303
	final ImageDescriptor fSuiteFailIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuitefail.gif"); //$NON-NLS-1$
304
253
	final ImageDescriptor fSuiteRunningIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiterun.gif"); //$NON-NLS-1$
305
	final ImageDescriptor fSuiteRunningIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiterun.gif"); //$NON-NLS-1$
254
306
255
	final Image fSuiteIcon;
307
	final Image fSuiteIcon;
308
256
	final Image fSuiteOkIcon;
309
	final Image fSuiteOkIcon;
310
257
	final Image fSuiteErrorIcon;
311
	final Image fSuiteErrorIcon;
312
258
	final Image fSuiteFailIcon;
313
	final Image fSuiteFailIcon;
314
259
	final Image fSuiteRunningIcon;
315
	final Image fSuiteRunningIcon;
260
316
261
	final List<Image> fImagesToDispose;
317
	final List<Image> fImagesToDispose;
262
318
263
	// Persistence tags.
319
	// Persistence tags.
264
	static final String TAG_PAGE= "page"; //$NON-NLS-1$
320
	static final String TAG_PAGE= "page"; //$NON-NLS-1$
321
265
	static final String TAG_RATIO= "ratio"; //$NON-NLS-1$
322
	static final String TAG_RATIO= "ratio"; //$NON-NLS-1$
323
266
	static final String TAG_TRACEFILTER= "tracefilter"; //$NON-NLS-1$
324
	static final String TAG_TRACEFILTER= "tracefilter"; //$NON-NLS-1$
325
267
	static final String TAG_ORIENTATION= "orientation"; //$NON-NLS-1$
326
	static final String TAG_ORIENTATION= "orientation"; //$NON-NLS-1$
327
268
	static final String TAG_SCROLL= "scroll"; //$NON-NLS-1$
328
	static final String TAG_SCROLL= "scroll"; //$NON-NLS-1$
329
269
	/**
330
	/**
270
	 * @since 3.2
331
	 * @since 3.2
271
	 */
332
	 */
272
	static final String TAG_LAYOUT= "layout"; //$NON-NLS-1$
333
	static final String TAG_LAYOUT= "layout"; //$NON-NLS-1$
334
273
	/**
335
	/**
274
	 * @since 3.2
336
	 * @since 3.2
275
	 */
337
	 */
276
	static final String TAG_FAILURES_ONLY= "failuresOnly"; //$NON-NLS-1$
338
	static final String TAG_FAILURES_ONLY= "failuresOnly"; //$NON-NLS-1$
339
277
	/**
340
	/**
278
	 * @since 3.4
341
	 * @since 3.4
279
	 */
342
	 */
Lines 288-302 Link Here
288
	 * @since 3.6
351
	 * @since 3.6
289
	 */
352
	 */
290
	static final String PREF_LAST_URL= "lastImportURL"; //$NON-NLS-1$
353
	static final String PREF_LAST_URL= "lastImportURL"; //$NON-NLS-1$
291
	
354
292
	//orientations
355
	//orientations
293
	static final int VIEW_ORIENTATION_VERTICAL= 0;
356
	static final int VIEW_ORIENTATION_VERTICAL= 0;
357
294
	static final int VIEW_ORIENTATION_HORIZONTAL= 1;
358
	static final int VIEW_ORIENTATION_HORIZONTAL= 1;
359
295
	static final int VIEW_ORIENTATION_AUTOMATIC= 2;
360
	static final int VIEW_ORIENTATION_AUTOMATIC= 2;
296
361
297
	private IMemento fMemento;
362
	private IMemento fMemento;
298
363
299
	Image fOriginalViewImage;
364
	Image fOriginalViewImage;
365
300
	IElementChangedListener fDirtyListener;
366
	IElementChangedListener fDirtyListener;
301
367
302
368
Lines 304-309 Link Here
304
	private SashForm fSashForm;
370
	private SashForm fSashForm;
305
371
306
	private Composite fCounterComposite;
372
	private Composite fCounterComposite;
373
307
	private Composite fParent;
374
	private Composite fParent;
308
375
309
	/**
376
	/**
Lines 312-331 Link Here
312
	private UpdateUIJob fUpdateJob;
379
	private UpdateUIJob fUpdateJob;
313
380
314
	/**
381
	/**
315
	 * A Job that runs as long as a test run is running.
382
	 * A Job that runs as long as a test run is running. It is used to show busyness for running
316
	 * It is used to show busyness for running jobs in the view (title in italics).
383
	 * jobs in the view (title in italics).
317
	 */
384
	 */
318
	private JUnitIsRunningJob fJUnitIsRunningJob;
385
	private JUnitIsRunningJob fJUnitIsRunningJob;
386
319
	private ILock fJUnitIsRunningLock;
387
	private ILock fJUnitIsRunningLock;
320
	public static final Object FAMILY_JUNIT_RUN = new Object();
388
389
	public static final Object FAMILY_JUNIT_RUN= new Object();
321
390
322
	private IPartListener2 fPartListener= new IPartListener2() {
391
	private IPartListener2 fPartListener= new IPartListener2() {
323
		public void partActivated(IWorkbenchPartReference ref) { }
392
		public void partActivated(IWorkbenchPartReference ref) {
324
		public void partBroughtToTop(IWorkbenchPartReference ref) { }
393
		}
325
		public void partInputChanged(IWorkbenchPartReference ref) { }
394
326
		public void partClosed(IWorkbenchPartReference ref) { }
395
		public void partBroughtToTop(IWorkbenchPartReference ref) {
327
		public void partDeactivated(IWorkbenchPartReference ref) { }
396
		}
328
		public void partOpened(IWorkbenchPartReference ref) { }
397
398
		public void partInputChanged(IWorkbenchPartReference ref) {
399
		}
400
401
		public void partClosed(IWorkbenchPartReference ref) {
402
		}
403
404
		public void partDeactivated(IWorkbenchPartReference ref) {
405
		}
406
407
		public void partOpened(IWorkbenchPartReference ref) {
408
		}
329
409
330
		public void partVisible(IWorkbenchPartReference ref) {
410
		public void partVisible(IWorkbenchPartReference ref) {
331
			if (getSite().getId().equals(ref.getId())) {
411
			if (getSite().getId().equals(ref.getId())) {
Lines 410-416 Link Here
410
490
411
		@Override
491
		@Override
412
		public ImageDescriptor getImageDescriptor(Object element) {
492
		public ImageDescriptor getImageDescriptor(Object element) {
413
			TestRunSession session= (TestRunSession) element;
493
			TestRunSession session= (TestRunSession)element;
414
			if (session.isStopped())
494
			if (session.isStopped())
415
				return fSuiteIconDescriptor;
495
				return fSuiteIconDescriptor;
416
496
Lines 481-487 Link Here
481
			if (lastPath != null) {
561
			if (lastPath != null) {
482
				importDialog.setFilterPath(lastPath);
562
				importDialog.setFilterPath(lastPath);
483
			}
563
			}
484
			importDialog.setFilterExtensions(new String[] {"*.xml", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
564
			importDialog.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
485
			String path= importDialog.open();
565
			String path= importDialog.open();
486
			if (path == null)
566
			if (path == null)
487
				return;
567
				return;
Lines 497-519 Link Here
497
			}
577
			}
498
		}
578
		}
499
	}
579
	}
500
	
580
501
	private static class JUnitPasteAction extends Action {
581
	private static class JUnitPasteAction extends Action {
502
		private final Shell fShell;
582
		private final Shell fShell;
583
503
		private Clipboard fClipboard;
584
		private Clipboard fClipboard;
504
		
585
505
		public JUnitPasteAction(Shell shell, Clipboard clipboard) {
586
		public JUnitPasteAction(Shell shell, Clipboard clipboard) {
506
			super(JUnitMessages.TestRunnerViewPart_JUnitPasteAction_label);
587
			super(JUnitMessages.TestRunnerViewPart_JUnitPasteAction_label);
507
			Assert.isNotNull(clipboard);
588
			Assert.isNotNull(clipboard);
508
			fShell= shell;
589
			fShell= shell;
509
			fClipboard= clipboard;
590
			fClipboard= clipboard;
510
		}
591
		}
511
		
592
512
		@Override
593
		@Override
513
		public void run() {
594
		public void run() {
514
			String urlData= (String) fClipboard.getContents(URLTransfer.getInstance());
595
			String urlData= (String)fClipboard.getContents(URLTransfer.getInstance());
515
			if (urlData == null) {
596
			if (urlData == null) {
516
				urlData= (String) fClipboard.getContents(TextTransfer.getInstance());
597
				urlData= (String)fClipboard.getContents(TextTransfer.getInstance());
517
			}
598
			}
518
			if (urlData != null && urlData.length() > 0) {
599
			if (urlData != null && urlData.length() > 0) {
519
				if (isValidUrl(urlData)) {
600
				if (isValidUrl(urlData)) {
Lines 524-530 Link Here
524
			MessageDialog.openInformation(fShell,
605
			MessageDialog.openInformation(fShell,
525
					JUnitMessages.TestRunnerViewPart_JUnitPasteAction_cannotpaste_title,
606
					JUnitMessages.TestRunnerViewPart_JUnitPasteAction_cannotpaste_title,
526
					JUnitMessages.TestRunnerViewPart_JUnitPasteAction_cannotpaste_message
607
					JUnitMessages.TestRunnerViewPart_JUnitPasteAction_cannotpaste_message
527
			);
608
					);
528
		}
609
		}
529
610
530
		private boolean isValidUrl(String urlData) {
611
		private boolean isValidUrl(String urlData) {
Lines 537-543 Link Here
537
			return true;
618
			return true;
538
		}
619
		}
539
	}
620
	}
540
	
621
541
	private static class ImportTestRunSessionFromURLAction extends Action {
622
	private static class ImportTestRunSessionFromURLAction extends Action {
542
		private static class URLValidator implements IInputValidator {
623
		private static class URLValidator implements IInputValidator {
543
			public String isValid(String newText) {
624
			public String isValid(String newText) {
Lines 554-577 Link Here
554
		}
635
		}
555
636
556
		private static final String DIALOG_SETTINGS= "ImportTestRunSessionFromURLAction"; //$NON-NLS-1$
637
		private static final String DIALOG_SETTINGS= "ImportTestRunSessionFromURLAction"; //$NON-NLS-1$
557
		
638
558
		private final Shell fShell;
639
		private final Shell fShell;
559
		
640
560
		public ImportTestRunSessionFromURLAction(Shell shell) {
641
		public ImportTestRunSessionFromURLAction(Shell shell) {
561
			super(JUnitMessages.TestRunnerViewPart_ImportTestRunSessionFromURLAction_import_from_url);
642
			super(JUnitMessages.TestRunnerViewPart_ImportTestRunSessionFromURLAction_import_from_url);
562
			fShell= shell;
643
			fShell= shell;
563
		}
644
		}
564
		
645
565
		@Override
646
		@Override
566
		public void run() {
647
		public void run() {
567
			String title= JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_title;
648
			String title= JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_title;
568
			String message= JUnitMessages.TestRunnerViewPart_ImportTestRunSessionFromURLAction_url;
649
			String message= JUnitMessages.TestRunnerViewPart_ImportTestRunSessionFromURLAction_url;
569
			
650
570
			final IDialogSettings dialogSettings= JUnitPlugin.getDefault().getDialogSettings();
651
			final IDialogSettings dialogSettings= JUnitPlugin.getDefault().getDialogSettings();
571
			String url= dialogSettings.get(PREF_LAST_URL);
652
			String url= dialogSettings.get(PREF_LAST_URL);
572
			
653
573
			IInputValidator validator= new URLValidator();
654
			IInputValidator validator= new URLValidator();
574
			
655
575
			InputDialog inputDialog= new InputDialog(fShell, title, message, url, validator) {
656
			InputDialog inputDialog= new InputDialog(fShell, title, message, url, validator) {
576
				@Override
657
				@Override
577
				protected Control createDialogArea(Composite parent) {
658
				protected Control createDialogArea(Composite parent) {
Lines 583-588 Link Here
583
					}
664
					}
584
					return dialogArea2;
665
					return dialogArea2;
585
				}
666
				}
667
586
				@Override
668
				@Override
587
				protected IDialogSettings getDialogBoundsSettings() {
669
				protected IDialogSettings getDialogBoundsSettings() {
588
					IDialogSettings settings= dialogSettings.getSection(DIALOG_SETTINGS);
670
					IDialogSettings settings= dialogSettings.getSection(DIALOG_SETTINGS);
Lines 592-603 Link Here
592
					settings.put("DIALOG_HEIGHT", Dialog.DIALOG_DEFAULT_BOUNDS); //$NON-NLS-1$
674
					settings.put("DIALOG_HEIGHT", Dialog.DIALOG_DEFAULT_BOUNDS); //$NON-NLS-1$
593
					return settings;
675
					return settings;
594
				}
676
				}
677
595
				@Override
678
				@Override
596
				protected boolean isResizable() {
679
				protected boolean isResizable() {
597
					return true;
680
					return true;
598
				}
681
				}
599
			};
682
			};
600
			
683
601
			int res= inputDialog.open();
684
			int res= inputDialog.open();
602
			if (res == IDialogConstants.OK_ID) {
685
			if (res == IDialogConstants.OK_ID) {
603
				url= inputDialog.getValue();
686
				url= inputDialog.getValue();
Lines 609-614 Link Here
609
692
610
	private static class ExportTestRunSessionAction extends Action {
693
	private static class ExportTestRunSessionAction extends Action {
611
		private final TestRunSession fTestRunSession;
694
		private final TestRunSession fTestRunSession;
695
612
		private final Shell fShell;
696
		private final Shell fShell;
613
697
614
		public ExportTestRunSessionAction(Shell shell, TestRunSession testRunSession) {
698
		public ExportTestRunSessionAction(Shell shell, TestRunSession testRunSession) {
Lines 627-633 Link Here
627
				exportDialog.setFilterPath(lastPath);
711
				exportDialog.setFilterPath(lastPath);
628
			}
712
			}
629
			exportDialog.setFileName(getFileName());
713
			exportDialog.setFileName(getFileName());
630
			exportDialog.setFilterExtensions(new String[] {"*.xml", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
714
			exportDialog.setFilterExtensions(new String[] { "*.xml", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$
631
			String path= exportDialog.open();
715
			String path= exportDialog.open();
632
			if (path == null)
716
			if (path == null)
633
				return;
717
				return;
Lines 664-676 Link Here
664
							String testRunLabel= BasicElementLabels.getJavaElementName(testRunSession.getTestRunName());
748
							String testRunLabel= BasicElementLabels.getJavaElementName(testRunSession.getTestRunName());
665
							String msg;
749
							String msg;
666
							if (testRunSession.getLaunch() != null) {
750
							if (testRunSession.getLaunch() != null) {
667
								msg= Messages.format(JUnitMessages.TestRunnerViewPart_Launching, new Object[]{ testRunLabel });
751
								msg= Messages.format(JUnitMessages.TestRunnerViewPart_Launching, new Object[] { testRunLabel });
668
							} else {
752
							} else {
669
								msg= testRunLabel;
753
								msg= testRunLabel;
670
							}
754
							}
671
							registerInfoMessage(msg);
755
							registerInfoMessage(msg);
672
						}
756
						}
673
						
757
674
						TestRunSession deactivatedSession= setActiveTestRunSession(testRunSession);
758
						TestRunSession deactivatedSession= setActiveTestRunSession(testRunSession);
675
						if (deactivatedSession != null)
759
						if (deactivatedSession != null)
676
							deactivatedSession.swapOut();
760
							deactivatedSession.swapOut();
Lines 678-690 Link Here
678
				}
762
				}
679
			});
763
			});
680
		}
764
		}
765
681
		public void sessionRemoved(final TestRunSession testRunSession) {
766
		public void sessionRemoved(final TestRunSession testRunSession) {
682
			getDisplay().asyncExec(new Runnable() {
767
			getDisplay().asyncExec(new Runnable() {
683
				public void run() {
768
				public void run() {
684
					if (testRunSession.equals(fTestRunSession)) {
769
					if (testRunSession.equals(fTestRunSession)) {
685
						List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
770
						List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
686
						TestRunSession deactivatedSession;
771
						TestRunSession deactivatedSession;
687
						if (! testRunSessions.isEmpty()) {
772
						if (!testRunSessions.isEmpty()) {
688
							deactivatedSession= setActiveTestRunSession(testRunSessions.get(0));
773
							deactivatedSession= setActiveTestRunSession(testRunSessions.get(0));
689
						} else {
774
						} else {
690
							deactivatedSession= setActiveTestRunSession(null);
775
							deactivatedSession= setActiveTestRunSession(null);
Lines 698-704 Link Here
698
	}
783
	}
699
784
700
	private class TestSessionListener implements ITestSessionListener {
785
	private class TestSessionListener implements ITestSessionListener {
701
		public void sessionStarted(){
786
		public void sessionStarted() {
702
			fTestViewer.registerViewersRefresh();
787
			fTestViewer.registerViewersRefresh();
703
			fShowOnErrorOnly= getShowOnErrorOnly();
788
			fShowOnErrorOnly= getShowOnErrorOnly();
704
789
Lines 708-719 Link Here
708
			fRerunLastTestAction.setEnabled(true);
793
			fRerunLastTestAction.setEnabled(true);
709
		}
794
		}
710
795
711
		public void sessionEnded(long elapsedTime){
796
		public void sessionEnded(long elapsedTime) {
712
			deregisterTestSessionListener(false);
797
			deregisterTestSessionListener(false);
713
			
798
714
			fTestViewer.registerAutoScrollTarget(null);
799
			fTestViewer.registerAutoScrollTarget(null);
715
800
716
			String[] keys= {elapsedTimeAsString(elapsedTime)};
801
			String[] keys= { elapsedTimeAsString(elapsedTime) };
717
			String msg= Messages.format(JUnitMessages.TestRunnerViewPart_message_finish, keys);
802
			String msg= Messages.format(JUnitMessages.TestRunnerViewPart_message_finish, keys);
718
			registerInfoMessage(msg);
803
			registerInfoMessage(msg);
719
804
Lines 732-737 Link Here
732
						JavaCore.addElementChangedListener(fDirtyListener);
817
						JavaCore.addElementChangedListener(fDirtyListener);
733
					}
818
					}
734
					warnOfContentChange();
819
					warnOfContentChange();
820
					fLinkWithEditorAction.setEnabled(fTestRunSession != null);
821
					setLinkingWithEditorActive(fTestRunSession != null);
735
				}
822
				}
736
			});
823
			});
737
			stopUpdateJobs();
824
			stopUpdateJobs();
Lines 739-745 Link Here
739
826
740
		public void sessionStopped(final long elapsedTime) {
827
		public void sessionStopped(final long elapsedTime) {
741
			deregisterTestSessionListener(false);
828
			deregisterTestSessionListener(false);
742
			
829
743
			fTestViewer.registerAutoScrollTarget(null);
830
			fTestViewer.registerAutoScrollTarget(null);
744
831
745
			registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_stopped);
832
			registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_stopped);
Lines 748-754 Link Here
748
835
749
		public void sessionTerminated() {
836
		public void sessionTerminated() {
750
			deregisterTestSessionListener(true);
837
			deregisterTestSessionListener(true);
751
			
838
752
			fTestViewer.registerAutoScrollTarget(null);
839
			fTestViewer.registerAutoScrollTarget(null);
753
840
754
			registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_terminated);
841
			registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_terminated);
Lines 776-796 Link Here
776
			}
863
			}
777
			fTestViewer.registerViewerUpdate(testElement);
864
			fTestViewer.registerViewerUpdate(testElement);
778
865
779
		    // show the view on the first error only
866
			// show the view on the first error only
780
		    if (fShowOnErrorOnly && (getErrorsPlusFailures() == 1))
867
			if (fShowOnErrorOnly && (getErrorsPlusFailures() == 1))
781
		        postShowTestResultsView();
868
				postShowTestResultsView();
782
869
783
		    //TODO:
870
			//TODO:
784
		    // [Bug 35590] JUnit window doesn't report errors from junit.extensions.TestSetup [JUnit]
871
			// [Bug 35590] JUnit window doesn't report errors from junit.extensions.TestSetup [JUnit]
785
		    // when a failure occurs in test setup then no test is running
872
			// when a failure occurs in test setup then no test is running
786
		    // to update the views we artificially signal the end of a test run
873
			// to update the views we artificially signal the end of a test run
787
//		    if (!fTestIsRunning) {
874
//		    if (!fTestIsRunning) {
788
//				fTestIsRunning= false;
875
//				fTestIsRunning= false;
789
//				testEnded(testCaseElement);
876
//				testEnded(testCaseElement);
790
//			}
877
//			}
791
		}
878
		}
792
879
793
		public void testEnded(TestCaseElement testCaseElement){
880
		public void testEnded(TestCaseElement testCaseElement) {
794
			fTestViewer.registerViewerUpdate(testCaseElement);
881
			fTestViewer.registerViewerUpdate(testCaseElement);
795
		}
882
		}
796
883
Lines 816-821 Link Here
816
			super(name);
903
			super(name);
817
			setSystem(true);
904
			setSystem(true);
818
		}
905
		}
906
819
		@Override
907
		@Override
820
		public IStatus runInUIThread(IProgressMonitor monitor) {
908
		public IStatus runInUIThread(IProgressMonitor monitor) {
821
			if (!isDisposed()) {
909
			if (!isDisposed()) {
Lines 828-833 Link Here
828
		public void stop() {
916
		public void stop() {
829
			fRunning= false;
917
			fRunning= false;
830
		}
918
		}
919
831
		@Override
920
		@Override
832
		public boolean shouldSchedule() {
921
		public boolean shouldSchedule() {
833
			return fRunning;
922
			return fRunning;
Lines 839-850 Link Here
839
			super(name);
928
			super(name);
840
			setSystem(true);
929
			setSystem(true);
841
		}
930
		}
931
842
		@Override
932
		@Override
843
		public IStatus run(IProgressMonitor monitor) {
933
		public IStatus run(IProgressMonitor monitor) {
844
			// wait until the test run terminates
934
			// wait until the test run terminates
845
			fJUnitIsRunningLock.acquire();
935
			fJUnitIsRunningLock.acquire();
846
			return Status.OK_STATUS;
936
			return Status.OK_STATUS;
847
		}
937
		}
938
848
		@Override
939
		@Override
849
		public boolean belongsTo(Object family) {
940
		public boolean belongsTo(Object family) {
850
			return family == TestRunnerViewPart.FAMILY_JUNIT_RUN;
941
			return family == TestRunnerViewPart.FAMILY_JUNIT_RUN;
Lines 858-864 Link Here
858
			boolean enabled= false;
949
			boolean enabled= false;
859
			List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
950
			List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
860
			for (TestRunSession testRunSession : testRunSessions) {
951
			for (TestRunSession testRunSession : testRunSessions) {
861
				if (! testRunSession.isRunning() && ! testRunSession.isStarting()) {
952
				if (!testRunSession.isRunning() && !testRunSession.isStarting()) {
862
					enabled= true;
953
					enabled= true;
863
					break;
954
					break;
864
				}
955
				}
Lines 877-883 Link Here
877
			List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
968
			List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
878
			for (Iterator<TestRunSession> iter= testRunSessions.iterator(); iter.hasNext();) {
969
			for (Iterator<TestRunSession> iter= testRunSessions.iterator(); iter.hasNext();) {
879
				TestRunSession testRunSession= iter.next();
970
				TestRunSession testRunSession= iter.next();
880
				if (! testRunSession.isRunning() && ! testRunSession.isStarting()) {
971
				if (!testRunSession.isRunning() && !testRunSession.isStarting()) {
881
					iter.remove();
972
					iter.remove();
882
				}
973
				}
883
			}
974
			}
Lines 899-904 Link Here
899
		}
990
		}
900
	}
991
	}
901
992
993
	/**
994
	 * This action toggles whether this {@link TestRunnerViewPart} links its selection to the active
995
	 * editor.
996
	 *
997
	 */
998
	private class LinkWithEditorAction extends AbstractToggleLinkingAction {
999
1000
		/** Image to use when the sync is on.*/
1001
		private static final String SYNCED_GIF= "synced.gif"; //$NON-NLS-1$
1002
		
1003
		/** Image to use when the sync is broken.*/
1004
		private static final String SYNC_BROKEN_GIF= "sync_broken.gif"; //$NON-NLS-1$
1005
		
1006
		private String fIconName = SYNC_BROKEN_GIF;
1007
		
1008
		LinkWithEditorAction() {
1009
			// enable by default
1010
			setChecked(true);
1011
		}
1012
1013
		@Override
1014
		public void run() {
1015
			setLinkingWithEditorActive(isChecked());
1016
		}
1017
		
1018
		/**
1019
		 * Updates the Link image with a "normal link" image if parameter is true, or a
1020
		 * "broken link" image otherwise
1021
		 * 
1022
		 * @param isInSync the state of synchronization
1023
		 */
1024
		public void updateLinkImage(boolean isInSync) {
1025
			String iconName= isInSync ? SYNCED_GIF : SYNC_BROKEN_GIF;
1026
			if (!iconName.equals(fIconName)) {
1027
				JavaPluginImages.setLocalImageDescriptors(fLinkWithEditorAction, iconName);
1028
				fIconName= iconName;
1029
			}
1030
		}
1031
1032
	}
1033
1034
	/**
1035
	 * @return {@code true} if the {@link LinkWithEditorAction} is checked, false otherwise.
1036
	 * @since 3.7
1037
	 */
1038
	public boolean isLinkWithEditorActive() {
1039
		return fLinkWithEditorAction.isChecked();
1040
	}
1041
902
	private class RerunLastAction extends Action {
1042
	private class RerunLastAction extends Action {
903
		public RerunLastAction() {
1043
		public RerunLastAction() {
904
			setText(JUnitMessages.TestRunnerViewPart_rerunaction_label);
1044
			setText(JUnitMessages.TestRunnerViewPart_rerunaction_label);
Lines 909-915 Link Here
909
		}
1049
		}
910
1050
911
		@Override
1051
		@Override
912
		public void run(){
1052
		public void run() {
913
			rerunTestRun();
1053
			rerunTestRun();
914
		}
1054
		}
915
	}
1055
	}
Lines 924-930 Link Here
924
		}
1064
		}
925
1065
926
		@Override
1066
		@Override
927
		public void run(){
1067
		public void run() {
928
			rerunTestFailedFirst();
1068
			rerunTestFailedFirst();
929
		}
1069
		}
930
	}
1070
	}
Lines 975-981 Link Here
975
			int type= delta.getElement().getElementType();
1115
			int type= delta.getElement().getElementType();
976
1116
977
			switch (type) {
1117
			switch (type) {
978
				// Consider containers for class files.
1118
			// Consider containers for class files.
979
				case IJavaElement.JAVA_MODEL:
1119
				case IJavaElement.JAVA_MODEL:
980
				case IJavaElement.JAVA_PROJECT:
1120
				case IJavaElement.JAVA_PROJECT:
981
				case IJavaElement.PACKAGE_FRAGMENT_ROOT:
1121
				case IJavaElement.PACKAGE_FRAGMENT_ROOT:
Lines 1059-1067 Link Here
1059
			//setImageDescriptor(JUnitPlugin.getImageDescriptor("obj16/failures.gif")); //$NON-NLS-1$
1199
			//setImageDescriptor(JUnitPlugin.getImageDescriptor("obj16/failures.gif")); //$NON-NLS-1$
1060
			update();
1200
			update();
1061
		}
1201
		}
1202
1062
		public void update() {
1203
		public void update() {
1063
			setChecked(getShowOnErrorOnly());
1204
			setChecked(getShowOnErrorOnly());
1064
		}
1205
		}
1206
1065
		@Override
1207
		@Override
1066
		public void run() {
1208
		public void run() {
1067
			boolean checked= isChecked();
1209
			boolean checked= isChecked();
Lines 1085-1091 Link Here
1085
		fTestFailIcon= createManagedImage("obj16/testfail.gif"); //$NON-NLS-1$
1227
		fTestFailIcon= createManagedImage("obj16/testfail.gif"); //$NON-NLS-1$
1086
		fTestRunningIcon= createManagedImage("obj16/testrun.gif"); //$NON-NLS-1$
1228
		fTestRunningIcon= createManagedImage("obj16/testrun.gif"); //$NON-NLS-1$
1087
		fTestIgnoredIcon= createManagedImage("obj16/testignored.gif"); //$NON-NLS-1$
1229
		fTestIgnoredIcon= createManagedImage("obj16/testignored.gif"); //$NON-NLS-1$
1088
		fTestAssumptionFailureIcon = createManagedImage("obj16/testassumptionfailed.gif"); //$NON-NLS-1$
1230
		fTestAssumptionFailureIcon= createManagedImage("obj16/testassumptionfailed.gif"); //$NON-NLS-1$
1089
1231
1090
		fSuiteIcon= createManagedImage(fSuiteIconDescriptor);
1232
		fSuiteIcon= createManagedImage(fSuiteIconDescriptor);
1091
		fSuiteOkIcon= createManagedImage(fSuiteOkIconDescriptor);
1233
		fSuiteOkIcon= createManagedImage(fSuiteOkIconDescriptor);
Lines 1120-1126 Link Here
1120
	private IWorkbenchSiteProgressService getProgressService() {
1262
	private IWorkbenchSiteProgressService getProgressService() {
1121
		Object siteService= getSite().getAdapter(IWorkbenchSiteProgressService.class);
1263
		Object siteService= getSite().getAdapter(IWorkbenchSiteProgressService.class);
1122
		if (siteService != null)
1264
		if (siteService != null)
1123
			return (IWorkbenchSiteProgressService) siteService;
1265
			return (IWorkbenchSiteProgressService)siteService;
1124
		return null;
1266
		return null;
1125
	}
1267
	}
1126
1268
Lines 1158-1164 Link Here
1158
//		}
1300
//		}
1159
		Integer ratio= memento.getInteger(TAG_RATIO);
1301
		Integer ratio= memento.getInteger(TAG_RATIO);
1160
		if (ratio != null)
1302
		if (ratio != null)
1161
			fSashForm.setWeights(new int[] { ratio.intValue(), 1000 - ratio.intValue()} );
1303
			fSashForm.setWeights(new int[] { ratio.intValue(), 1000 - ratio.intValue() });
1162
		Integer orientation= memento.getInteger(TAG_ORIENTATION);
1304
		Integer orientation= memento.getInteger(TAG_ORIENTATION);
1163
		if (orientation != null)
1305
		if (orientation != null)
1164
			fOrientation= orientation.intValue();
1306
			fOrientation= orientation.intValue();
Lines 1200-1205 Link Here
1200
		}
1342
		}
1201
	}
1343
	}
1202
1344
1345
	/**
1346
	 * Activate the 'Link with Editor' in the current {@link IWorkbenchPage}. (The
1347
	 * {@link TestViewer} will respond to {@link ISelection} changes.)
1348
	 * 
1349
	 * @param active boolean to indicate if the link with editor is active ({@code true}) or not (
1350
	 *            {@code false})
1351
	 * 
1352
	 * @since 3.7
1353
	 */
1354
	public void setLinkingWithEditorActive(final boolean active) {
1355
		if (active) {
1356
			getSite().getPage().addPostSelectionListener(fTestViewer);
1357
			fTestViewer.setSelection(getSite().getPage().getActiveEditor());
1358
		} else {
1359
			getSite().getPage().removePostSelectionListener(fTestViewer);
1360
		}
1361
	}
1362
	
1363
	/**
1364
	 * Updates the Link image with a "normal link" image if parameter is true, or a "broken link"
1365
	 * image otherwise
1366
	 * 
1367
	 * @param isInSync the state of synchronization
1368
	 * 
1369
	 * @since 3.7
1370
	 */
1371
	public void setLinkingWithEditorInSync(final boolean isInSync) {
1372
		fLinkWithEditorAction.updateLinkImage(isInSync);
1373
	}
1374
1203
	private void startUpdateJobs() {
1375
	private void startUpdateJobs() {
1204
		postSyncProcessChanges();
1376
		postSyncProcessChanges();
1205
1377
Lines 1237-1243 Link Here
1237
		doShowInfoMessage();
1409
		doShowInfoMessage();
1238
		refreshCounters();
1410
		refreshCounters();
1239
1411
1240
		if (! fPartIsVisible)
1412
		if (!fPartIsVisible)
1241
			updateViewTitleProgress();
1413
			updateViewTitleProgress();
1242
		else {
1414
		else {
1243
			updateViewIcon();
1415
			updateViewIcon();
Lines 1298-1328 Link Here
1298
		}
1470
		}
1299
		ILaunch launch= fTestRunSession.getLaunch();
1471
		ILaunch launch= fTestRunSession.getLaunch();
1300
		if (launch != null && launch.getLaunchConfiguration() != null) {
1472
		if (launch != null && launch.getLaunchConfiguration() != null) {
1301
				ILaunchConfiguration launchConfiguration= launch.getLaunchConfiguration();
1473
			ILaunchConfiguration launchConfiguration= launch.getLaunchConfiguration();
1302
				if (launchConfiguration != null) {
1474
			if (launchConfiguration != null) {
1303
					try {
1475
				try {
1304
						String oldName= launchConfiguration.getName();
1476
					String oldName= launchConfiguration.getName();
1305
						String oldFailuresFilename= launchConfiguration.getAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, (String) null);
1477
					String oldFailuresFilename= launchConfiguration.getAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, (String)null);
1306
						String configName;
1478
					String configName;
1307
						if (oldFailuresFilename != null) {
1479
					if (oldFailuresFilename != null) {
1308
							configName= oldName;
1480
						configName= oldName;
1309
						} else {
1481
					} else {
1310
							configName= Messages.format(JUnitMessages.TestRunnerViewPart_rerunFailedFirstLaunchConfigName, oldName);
1482
						configName= Messages.format(JUnitMessages.TestRunnerViewPart_rerunFailedFirstLaunchConfigName, oldName);
1311
						}
1312
						ILaunchConfigurationWorkingCopy tmp= launchConfiguration.copy(configName);
1313
						tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, createFailureNamesFile());
1314
						relaunch(tmp, launch.getLaunchMode());
1315
						return;
1316
					} catch (CoreException e) {
1317
						ErrorDialog.openError(getSite().getShell(),
1318
							JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
1319
						);
1320
					}
1483
					}
1484
					ILaunchConfigurationWorkingCopy tmp= launchConfiguration.copy(configName);
1485
					tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, createFailureNamesFile());
1486
					relaunch(tmp, launch.getLaunchMode());
1487
					return;
1488
				} catch (CoreException e) {
1489
					ErrorDialog.openError(getSite().getShell(),
1490
							JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
1491
							);
1321
				}
1492
				}
1322
				MessageDialog.openInformation(getSite().getShell(),
1493
			}
1494
			MessageDialog.openInformation(getSite().getShell(),
1323
					JUnitMessages.TestRunnerViewPart_cannotrerun_title,
1495
					JUnitMessages.TestRunnerViewPart_cannotrerun_title,
1324
					JUnitMessages.TestRunnerViewPart_cannotrerurn_message
1496
					JUnitMessages.TestRunnerViewPart_cannotrerurn_message
1325
				);
1497
					);
1326
		}
1498
		}
1327
	}
1499
	}
1328
1500
Lines 1354-1360 Link Here
1354
	}
1526
	}
1355
1527
1356
	public void setAutoScroll(boolean scroll) {
1528
	public void setAutoScroll(boolean scroll) {
1357
		fAutoScroll = scroll;
1529
		fAutoScroll= scroll;
1358
	}
1530
	}
1359
1531
1360
	public boolean isAutoScroll() {
1532
	public boolean isAutoScroll() {
Lines 1385-1391 Link Here
1385
	}
1557
	}
1386
1558
1387
	private String elapsedTimeAsString(long runTime) {
1559
	private String elapsedTimeAsString(long runTime) {
1388
		return NumberFormat.getInstance().format((double)runTime/1000);
1560
		return NumberFormat.getInstance().format((double)runTime / 1000);
1389
	}
1561
	}
1390
1562
1391
	private void handleStopped() {
1563
	private void handleStopped() {
Lines 1493-1499 Link Here
1493
			}
1665
			}
1494
			if (!fTestRunSession.isStarting() && !fShowOnErrorOnly)
1666
			if (!fTestRunSession.isStarting() && !fShowOnErrorOnly)
1495
				showTestResultsView();
1667
				showTestResultsView();
1496
			
1668
1497
			setTitleToolTip();
1669
			setTitleToolTip();
1498
1670
1499
			clearStatus();
1671
			clearStatus();
Lines 1507-1517 Link Here
1507
				startUpdateJobs();
1679
				startUpdateJobs();
1508
1680
1509
				fStopAction.setEnabled(true);
1681
				fStopAction.setEnabled(true);
1682
				fLinkWithEditorAction.setEnabled(true);
1510
1683
1511
			} else /* old or fresh session: don't want jobs at this stage */ {
1684
			} else /* old or fresh session: don't want jobs at this stage */{
1512
				stopUpdateJobs();
1685
				stopUpdateJobs();
1513
1686
1514
				fStopAction.setEnabled(fTestRunSession.isKeptAlive());
1687
				fStopAction.setEnabled(fTestRunSession.isKeptAlive());
1688
				fLinkWithEditorAction.setEnabled(fTestRunSession != null);
1689
				// if "Link with Editor" is active, register the listener
1690
				if (isLinkWithEditorActive()) {
1691
					getSite().getPage().addPostSelectionListener(fTestViewer);
1692
					fTestViewer.setSelection(getSite().getPage().getActiveEditor());
1693
				}
1694
1515
				fTestViewer.expandFirstLevel();
1695
				fTestViewer.expandFirstLevel();
1516
			}
1696
			}
1517
		}
1697
		}
Lines 1527-1542 Link Here
1527
1707
1528
	private void updateRerunFailedFirstAction() {
1708
	private void updateRerunFailedFirstAction() {
1529
		boolean state= hasErrorsOrFailures() && fTestRunSession.getLaunch() != null;
1709
		boolean state= hasErrorsOrFailures() && fTestRunSession.getLaunch() != null;
1530
	    fRerunFailedFirstAction.setEnabled(state);
1710
		fRerunFailedFirstAction.setEnabled(state);
1531
    }
1711
	}
1532
1712
1533
    /**
1713
	/**
1534
     * @return the display name of the current test run sessions kind, or <code>null</code>
1714
	 * @return the display name of the current test run sessions kind, or <code>null</code>
1535
     */
1715
	 */
1536
    public String getTestKindDisplayName() {
1716
	public String getTestKindDisplayName() {
1537
    	ITestKind kind= fTestRunSession.getTestRunnerKind();
1717
		ITestKind kind= fTestRunSession.getTestRunnerKind();
1538
		if (!kind.isNull()) {
1718
		if (!kind.isNull()) {
1539
			return  kind.getDisplayName();
1719
			return kind.getDisplayName();
1540
		}
1720
		}
1541
		return null;
1721
		return null;
1542
	}
1722
	}
Lines 1546-1563 Link Here
1546
1726
1547
		String testRunLabel= BasicElementLabels.getJavaElementName(fTestRunSession.getTestRunName());
1727
		String testRunLabel= BasicElementLabels.getJavaElementName(fTestRunSession.getTestRunName());
1548
		if (testKindDisplayStr != null)
1728
		if (testKindDisplayStr != null)
1549
			setTitleToolTip(MessageFormat.format(JUnitMessages.TestRunnerViewPart_titleToolTip, new Object[] {testRunLabel, testKindDisplayStr}));
1729
			setTitleToolTip(MessageFormat.format(JUnitMessages.TestRunnerViewPart_titleToolTip, new Object[] { testRunLabel, testKindDisplayStr }));
1550
		else
1730
		else
1551
			setTitleToolTip(testRunLabel);
1731
			setTitleToolTip(testRunLabel);
1552
	}
1732
	}
1553
1733
1554
	@Override
1734
	@Override
1555
	public synchronized void dispose(){
1735
	public synchronized void dispose() {
1556
		fIsDisposed= true;
1736
		fIsDisposed= true;
1557
		if (fTestRunSessionListener != null)
1737
		if (fTestRunSessionListener != null)
1558
			JUnitCorePlugin.getModel().removeTestRunSessionListener(fTestRunSessionListener);
1738
			JUnitCorePlugin.getModel().removeTestRunSessionListener(fTestRunSessionListener);
1559
1739
1560
		IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class);
1740
		IHandlerService handlerService= (IHandlerService)getSite().getWorkbenchWindow().getService(IHandlerService.class);
1561
		handlerService.deactivateHandler(fRerunLastActivation);
1741
		handlerService.deactivateHandler(fRerunLastActivation);
1562
		handlerService.deactivateHandler(fRerunFailedFirstActivation);
1742
		handlerService.deactivateHandler(fRerunFailedFirstActivation);
1563
		setActiveTestRunSession(null);
1743
		setActiveTestRunSession(null);
Lines 1579-1584 Link Here
1579
		if (fFailureTrace != null) {
1759
		if (fFailureTrace != null) {
1580
			fFailureTrace.dispose();
1760
			fFailureTrace.dispose();
1581
		}
1761
		}
1762
		getSite().getPage().removePostSelectionListener(fTestViewer);
1582
	}
1763
	}
1583
1764
1584
	private void disposeImages() {
1765
	private void disposeImages() {
Lines 1593-1599 Link Here
1593
	}
1774
	}
1594
1775
1595
	private void refreshCounters() {
1776
	private void refreshCounters() {
1596
		 // TODO: Inefficient. Either
1777
		// TODO: Inefficient. Either
1597
		// - keep a boolean fHasTestRun and update only on changes, or
1778
		// - keep a boolean fHasTestRun and update only on changes, or
1598
		// - improve components to only redraw on changes (once!).
1779
		// - improve components to only redraw on changes (once!).
1599
1780
Lines 1612-1618 Link Here
1612
			totalCount= fTestRunSession.getTotalCount();
1793
			totalCount= fTestRunSession.getTotalCount();
1613
			errorCount= fTestRunSession.getErrorCount();
1794
			errorCount= fTestRunSession.getErrorCount();
1614
			failureCount= fTestRunSession.getFailureCount();
1795
			failureCount= fTestRunSession.getFailureCount();
1615
			assumptionFailureCount = fTestRunSession.getAssumptionFailureCount();
1796
			assumptionFailureCount= fTestRunSession.getAssumptionFailureCount();
1616
			hasErrorsOrFailures= errorCount + failureCount > 0;
1797
			hasErrorsOrFailures= errorCount + failureCount > 0;
1617
			stopped= fTestRunSession.isStopped();
1798
			stopped= fTestRunSession.isStopped();
1618
		} else {
1799
		} else {
Lines 1621-1627 Link Here
1621
			totalCount= 0;
1802
			totalCount= 0;
1622
			errorCount= 0;
1803
			errorCount= 0;
1623
			failureCount= 0;
1804
			failureCount= 0;
1624
			assumptionFailureCount = 0;
1805
			assumptionFailureCount= 0;
1625
			hasErrorsOrFailures= false;
1806
			hasErrorsOrFailures= false;
1626
			stopped= false;
1807
			stopped= false;
1627
		}
1808
		}
Lines 1634-1640 Link Here
1634
		int ticksDone;
1815
		int ticksDone;
1635
		if (startedCount == 0)
1816
		if (startedCount == 0)
1636
			ticksDone= 0;
1817
			ticksDone= 0;
1637
		else if (startedCount == totalCount && ! fTestRunSession.isRunning())
1818
		else if (startedCount == totalCount && !fTestRunSession.isRunning())
1638
			ticksDone= totalCount;
1819
			ticksDone= totalCount;
1639
		else
1820
		else
1640
			ticksDone= startedCount - 1;
1821
			ticksDone= startedCount - 1;
Lines 1660-1666 Link Here
1660
		if (page != null) {
1841
		if (page != null) {
1661
			try { // show the result view
1842
			try { // show the result view
1662
				testRunner= (TestRunnerViewPart)page.findView(TestRunnerViewPart.NAME);
1843
				testRunner= (TestRunnerViewPart)page.findView(TestRunnerViewPart.NAME);
1663
				if(testRunner == null) {
1844
				if (testRunner == null) {
1664
					IWorkbenchPart activePart= page.getActivePart();
1845
					IWorkbenchPart activePart= page.getActivePart();
1665
					testRunner= (TestRunnerViewPart)page.showView(TestRunnerViewPart.NAME, null, IWorkbenchPage.VIEW_VISIBLE);
1846
					testRunner= (TestRunnerViewPart)page.showView(TestRunnerViewPart.NAME, null, IWorkbenchPage.VIEW_VISIBLE);
1666
					//restore focus
1847
					//restore focus
Lines 1696-1701 Link Here
1696
			protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
1877
			protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
1697
				return new Point(1, 1); // (0, 0) does not work with super-intelligent ViewForm
1878
				return new Point(1, 1); // (0, 0) does not work with super-intelligent ViewForm
1698
			}
1879
			}
1880
1699
			@Override
1881
			@Override
1700
			protected void layout(Composite composite, boolean flushCache) {
1882
			protected void layout(Composite composite, boolean flushCache) {
1701
			}
1883
			}
Lines 1715-1721 Link Here
1715
		fFailureTrace= new FailureTrace(bottom, fClipboard, this, failureToolBar);
1897
		fFailureTrace= new FailureTrace(bottom, fClipboard, this, failureToolBar);
1716
		bottom.setContent(fFailureTrace.getComposite());
1898
		bottom.setContent(fFailureTrace.getComposite());
1717
1899
1718
		fSashForm.setWeights(new int[]{50, 50});
1900
		fSashForm.setWeights(new int[] { 50, 50 });
1719
		return fSashForm;
1901
		return fSashForm;
1720
	}
1902
	}
1721
1903
Lines 1750-1764 Link Here
1750
		sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
1932
		sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
1751
1933
1752
		IActionBars actionBars= getViewSite().getActionBars();
1934
		IActionBars actionBars= getViewSite().getActionBars();
1753
		
1935
1754
		fCopyAction = new JUnitCopyAction(fFailureTrace, fClipboard);
1936
		fCopyAction= new JUnitCopyAction(fFailureTrace, fClipboard);
1755
		fCopyAction.setActionDefinitionId(ActionFactory.COPY.getCommandId());
1937
		fCopyAction.setActionDefinitionId(ActionFactory.COPY.getCommandId());
1756
		actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
1938
		actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
1757
		
1939
1758
		fPasteAction= new JUnitPasteAction(parent.getShell(), fClipboard);
1940
		fPasteAction= new JUnitPasteAction(parent.getShell(), fClipboard);
1759
		fPasteAction.setActionDefinitionId(ActionFactory.PASTE.getCommandId());
1941
		fPasteAction.setActionDefinitionId(ActionFactory.PASTE.getCommandId());
1760
		actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction);
1942
		actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), fPasteAction);
1761
		
1943
1762
		initPageSwitcher();
1944
		initPageSwitcher();
1763
		addDropAdapter(parent);
1945
		addDropAdapter(parent);
1764
1946
Lines 1777-1783 Link Here
1777
1959
1778
		fTestRunSessionListener= new TestRunSessionListener();
1960
		fTestRunSessionListener= new TestRunSessionListener();
1779
		JUnitCorePlugin.getModel().addTestRunSessionListener(fTestRunSessionListener);
1961
		JUnitCorePlugin.getModel().addTestRunSessionListener(fTestRunSessionListener);
1780
		
1962
1781
		// always show youngest test run in view. simulate "sessionAdded" event to do that
1963
		// always show youngest test run in view. simulate "sessionAdded" event to do that
1782
		List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
1964
		List<TestRunSession> testRunSessions= JUnitCorePlugin.getModel().getTestRunSessions();
1783
		if (!testRunSessions.isEmpty()) {
1965
		if (!testRunSessions.isEmpty()) {
Lines 1786-1816 Link Here
1786
	}
1968
	}
1787
1969
1788
	private void addDropAdapter(Composite parent) {
1970
	private void addDropAdapter(Composite parent) {
1789
		DropTarget dropTarget = new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT);
1971
		DropTarget dropTarget= new DropTarget(parent, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_LINK | DND.DROP_DEFAULT);
1790
		dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
1972
		dropTarget.setTransfer(new Transfer[] { TextTransfer.getInstance() });
1791
		class DropAdapter extends DropTargetAdapter {
1973
		class DropAdapter extends DropTargetAdapter {
1792
		    @Override
1974
			@Override
1793
			public void dragEnter(DropTargetEvent event) {
1975
			public void dragEnter(DropTargetEvent event) {
1794
		        event.detail = DND.DROP_COPY;
1976
				event.detail= DND.DROP_COPY;
1795
		        event.feedback = DND.FEEDBACK_NONE;
1977
				event.feedback= DND.FEEDBACK_NONE;
1796
		    }
1978
			}
1797
		    @Override
1979
1980
			@Override
1798
			public void dragOver(DropTargetEvent event) {
1981
			public void dragOver(DropTargetEvent event) {
1799
		        event.detail = DND.DROP_COPY;
1982
				event.detail= DND.DROP_COPY;
1800
		        event.feedback = DND.FEEDBACK_NONE;
1983
				event.feedback= DND.FEEDBACK_NONE;
1801
		    }
1984
			}
1802
		    @Override
1985
1986
			@Override
1803
			public void dragOperationChanged(DropTargetEvent event) {
1987
			public void dragOperationChanged(DropTargetEvent event) {
1804
		        event.detail = DND.DROP_COPY;
1988
				event.detail= DND.DROP_COPY;
1805
		        event.feedback = DND.FEEDBACK_NONE;
1989
				event.feedback= DND.FEEDBACK_NONE;
1806
		    }
1990
			}
1807
		    @Override
1991
1992
			@Override
1808
			public void drop(final DropTargetEvent event) {
1993
			public void drop(final DropTargetEvent event) {
1809
		        if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
1994
				if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
1810
					String url= (String) event.data;
1995
					String url= (String)event.data;
1811
					importTestRunSession(url);
1996
					importTestRunSession(url);
1812
		        }
1997
				}
1813
		    }
1998
			}
1814
		}
1999
		}
1815
		dropTarget.addDropListener(new DropAdapter());
2000
		dropTarget.addDropListener(new DropAdapter());
1816
	}
2001
	}
Lines 1825-1831 Link Here
1825
2010
1826
			@Override
2011
			@Override
1827
			public String getName(Object page) {
2012
			public String getName(Object page) {
1828
				return fViewHistory.getText((TestRunSession) page);
2013
				return fViewHistory.getText((TestRunSession)page);
1829
			}
2014
			}
1830
2015
1831
			@Override
2016
			@Override
Lines 1835-1841 Link Here
1835
2020
1836
			@Override
2021
			@Override
1837
			public void activatePage(Object page) {
2022
			public void activatePage(Object page) {
1838
				fViewHistory.setActiveEntry((TestRunSession) page);
2023
				fViewHistory.setActiveEntry((TestRunSession)page);
1839
			}
2024
			}
1840
2025
1841
			@Override
2026
			@Override
Lines 1849-1854 Link Here
1849
		parent.addControlListener(new ControlListener() {
2034
		parent.addControlListener(new ControlListener() {
1850
			public void controlMoved(ControlEvent e) {
2035
			public void controlMoved(ControlEvent e) {
1851
			}
2036
			}
2037
1852
			public void controlResized(ControlEvent e) {
2038
			public void controlResized(ControlEvent e) {
1853
				computeOrientation();
2039
				computeOrientation();
1854
			}
2040
			}
Lines 1874-1880 Link Here
1874
	private void configureToolBar() {
2060
	private void configureToolBar() {
1875
		IActionBars actionBars= getViewSite().getActionBars();
2061
		IActionBars actionBars= getViewSite().getActionBars();
1876
		IToolBarManager toolBar= actionBars.getToolBarManager();
2062
		IToolBarManager toolBar= actionBars.getToolBarManager();
1877
		IMenuManager viewMenu = actionBars.getMenuManager();
2063
		IMenuManager viewMenu= actionBars.getMenuManager();
1878
2064
1879
		fNextAction= new ShowNextFailureAction(this);
2065
		fNextAction= new ShowNextFailureAction(this);
1880
		fNextAction.setEnabled(false);
2066
		fNextAction.setEnabled(false);
Lines 1887-1912 Link Here
1887
		fStopAction= new StopAction();
2073
		fStopAction= new StopAction();
1888
		fStopAction.setEnabled(false);
2074
		fStopAction.setEnabled(false);
1889
2075
2076
		fLinkWithEditorAction= new LinkWithEditorAction();
2077
		fLinkWithEditorAction.setEnabled(false);
2078
1890
		fRerunLastTestAction= new RerunLastAction();
2079
		fRerunLastTestAction= new RerunLastAction();
1891
		IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class);
2080
		IHandlerService handlerService= (IHandlerService)getSite().getWorkbenchWindow().getService(IHandlerService.class);
1892
		IHandler handler = new AbstractHandler() {
2081
		IHandler handler= new AbstractHandler() {
1893
			public Object execute(ExecutionEvent event) throws ExecutionException {
2082
			public Object execute(ExecutionEvent event) throws ExecutionException {
1894
				fRerunLastTestAction.run();
2083
				fRerunLastTestAction.run();
1895
				return null;
2084
				return null;
1896
			}
2085
			}
2086
1897
			@Override
2087
			@Override
1898
			public boolean isEnabled() {
2088
			public boolean isEnabled() {
1899
				return fRerunLastTestAction.isEnabled();
2089
				return fRerunLastTestAction.isEnabled();
1900
			}
2090
			}
1901
		};
2091
		};
1902
        fRerunLastActivation= handlerService.activateHandler(RERUN_LAST_COMMAND, handler);
2092
		fRerunLastActivation= handlerService.activateHandler(RERUN_LAST_COMMAND, handler);
1903
2093
1904
		fRerunFailedFirstAction= new RerunLastFailedFirstAction();
2094
		fRerunFailedFirstAction= new RerunLastFailedFirstAction();
1905
		handler = new AbstractHandler() {
2095
		handler= new AbstractHandler() {
1906
			public Object execute(ExecutionEvent event) throws ExecutionException {
2096
			public Object execute(ExecutionEvent event) throws ExecutionException {
1907
				fRerunFailedFirstAction.run();
2097
				fRerunFailedFirstAction.run();
1908
				return null;
2098
				return null;
1909
			}
2099
			}
2100
1910
			@Override
2101
			@Override
1911
			public boolean isEnabled() {
2102
			public boolean isEnabled() {
1912
				return fRerunFailedFirstAction.isEnabled();
2103
				return fRerunFailedFirstAction.isEnabled();
Lines 1919-1929 Link Here
1919
		fScrollLockAction= new ScrollLockAction(this);
2110
		fScrollLockAction= new ScrollLockAction(this);
1920
		fScrollLockAction.setChecked(!fAutoScroll);
2111
		fScrollLockAction.setChecked(!fAutoScroll);
1921
2112
1922
		fToggleOrientationActions =
2113
		fToggleOrientationActions=
1923
			new ToggleOrientationAction[] {
2114
				new ToggleOrientationAction[] {
1924
				new ToggleOrientationAction(VIEW_ORIENTATION_VERTICAL),
2115
						new ToggleOrientationAction(VIEW_ORIENTATION_VERTICAL),
1925
				new ToggleOrientationAction(VIEW_ORIENTATION_HORIZONTAL),
2116
						new ToggleOrientationAction(VIEW_ORIENTATION_HORIZONTAL),
1926
				new ToggleOrientationAction(VIEW_ORIENTATION_AUTOMATIC)};
2117
						new ToggleOrientationAction(VIEW_ORIENTATION_AUTOMATIC) };
1927
2118
1928
		fShowTestHierarchyAction= new ShowTestHierarchyAction();
2119
		fShowTestHierarchyAction= new ShowTestHierarchyAction();
1929
		fShowTimeAction= new ShowTimeAction();
2120
		fShowTimeAction= new ShowTimeAction();
Lines 1937-1950 Link Here
1937
		toolBar.add(fRerunFailedFirstAction);
2128
		toolBar.add(fRerunFailedFirstAction);
1938
		toolBar.add(fStopAction);
2129
		toolBar.add(fStopAction);
1939
		toolBar.add(fViewHistory.createHistoryDropDownAction());
2130
		toolBar.add(fViewHistory.createHistoryDropDownAction());
1940
2131
		toolBar.add(new Separator());
2132
		toolBar.add(fLinkWithEditorAction);
1941
2133
1942
		viewMenu.add(fShowTestHierarchyAction);
2134
		viewMenu.add(fShowTestHierarchyAction);
1943
		viewMenu.add(fShowTimeAction);
2135
		viewMenu.add(fShowTimeAction);
1944
		viewMenu.add(new Separator());
2136
		viewMenu.add(new Separator());
1945
2137
1946
		MenuManager layoutSubMenu= new MenuManager(JUnitMessages.TestRunnerViewPart_layout_menu);
2138
		MenuManager layoutSubMenu= new MenuManager(JUnitMessages.TestRunnerViewPart_layout_menu);
1947
		for (int i = 0; i < fToggleOrientationActions.length; ++i) {
2139
		for (int i= 0; i < fToggleOrientationActions.length; ++i) {
1948
			layoutSubMenu.add(fToggleOrientationActions[i]);
2140
			layoutSubMenu.add(fToggleOrientationActions[i]);
1949
		}
2141
		}
1950
		viewMenu.add(layoutSubMenu);
2142
		viewMenu.add(layoutSubMenu);
Lines 1983-1989 Link Here
1983
			IEditorPart activeEditorPart= (IEditorPart)activePart;
2175
			IEditorPart activeEditorPart= (IEditorPart)activePart;
1984
			IEditorActionBarContributor contributor= activeEditorPart.getEditorSite().getActionBarContributor();
2176
			IEditorActionBarContributor contributor= activeEditorPart.getEditorSite().getActionBarContributor();
1985
			if (contributor instanceof EditorActionBarContributor)
2177
			if (contributor instanceof EditorActionBarContributor)
1986
				return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager();
2178
				return ((EditorActionBarContributor)contributor).getActionBars().getStatusLineManager();
1987
		}
2179
		}
1988
		// no active part
2180
		// no active part
1989
		return getViewSite().getActionBars().getStatusLineManager();
2181
		return getViewSite().getActionBars().getStatusLineManager();
Lines 1995-2004 Link Here
1995
		composite.setLayout(layout);
2187
		composite.setLayout(layout);
1996
		setCounterColumns(layout);
2188
		setCounterColumns(layout);
1997
2189
1998
		fCounterPanel = new CounterPanel(composite);
2190
		fCounterPanel= new CounterPanel(composite);
1999
		fCounterPanel.setLayoutData(
2191
		fCounterPanel.setLayoutData(
2000
			new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
2192
				new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
2001
		fProgressBar = new JUnitProgressBar(composite);
2193
		fProgressBar= new JUnitProgressBar(composite);
2002
		fProgressBar.setLayoutData(
2194
		fProgressBar.setLayoutData(
2003
				new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
2195
				new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
2004
		return composite;
2196
		return composite;
Lines 2070-2076 Link Here
2070
	public void rerunTest(String testId, String className, String testName, String launchMode) {
2262
	public void rerunTest(String testId, String className, String testName, String launchMode) {
2071
		if (lastLaunchIsKeptAlive()) {
2263
		if (lastLaunchIsKeptAlive()) {
2072
			fTestRunSession.rerunTest(testId, className, testName);
2264
			fTestRunSession.rerunTest(testId, className, testName);
2073
			TestCaseElement testCaseElement= (TestCaseElement) fTestRunSession.getTestElement(testId);
2265
			TestCaseElement testCaseElement= (TestCaseElement)fTestRunSession.getTestElement(testId);
2074
			testCaseElement.setStatus(TestElement.Status.RUNNING, null, null, null);
2266
			testCaseElement.setStatus(TestElement.Status.RUNNING, null, null, null);
2075
			fTestViewer.registerViewerUpdate(testCaseElement);
2267
			fTestViewer.registerViewerUpdate(testCaseElement);
2076
			postSyncProcessChanges();
2268
			postSyncProcessChanges();
Lines 2086-2094 Link Here
2086
					try {
2278
					try {
2087
						String name= className;
2279
						String name= className;
2088
						if (testName != null)
2280
						if (testName != null)
2089
							name+= "."+testName; //$NON-NLS-1$
2281
							name+= "." + testName; //$NON-NLS-1$
2090
						String configName= Messages.format(JUnitMessages.TestRunnerViewPart_configName, name);
2282
						String configName= Messages.format(JUnitMessages.TestRunnerViewPart_configName, name);
2091
						ILaunchConfigurationWorkingCopy tmp = launchConfiguration.copy(configName);
2283
						ILaunchConfigurationWorkingCopy tmp= launchConfiguration.copy(configName);
2092
						// fix for bug: 64838  junit view run single test does not use correct class [JUnit]
2284
						// fix for bug: 64838  junit view run single test does not use correct class [JUnit]
2093
						tmp.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, className);
2285
						tmp.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, className);
2094
						// reset the container
2286
						// reset the container
Lines 2098-2109 Link Here
2098
						}
2290
						}
2099
						relaunch(tmp, launchMode);
2291
						relaunch(tmp, launchMode);
2100
						return;
2292
						return;
2101
						} catch (CoreException e) {
2293
					} catch (CoreException e) {
2102
							ErrorDialog.openError(getSite().getShell(),
2294
						ErrorDialog.openError(getSite().getShell(),
2103
									JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
2295
								JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
2104
								);
2296
								);
2105
							return;
2297
						return;
2106
						}
2298
					}
2107
				}
2299
				}
2108
			}
2300
			}
2109
		}
2301
		}
Lines 2134-2145 Link Here
2134
	private void setOrientation(int orientation) {
2326
	private void setOrientation(int orientation) {
2135
		if ((fSashForm == null) || fSashForm.isDisposed())
2327
		if ((fSashForm == null) || fSashForm.isDisposed())
2136
			return;
2328
			return;
2137
		boolean horizontal = orientation == VIEW_ORIENTATION_HORIZONTAL;
2329
		boolean horizontal= orientation == VIEW_ORIENTATION_HORIZONTAL;
2138
		fSashForm.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
2330
		fSashForm.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
2139
		for (int i = 0; i < fToggleOrientationActions.length; ++i)
2331
		for (int i= 0; i < fToggleOrientationActions.length; ++i)
2140
			fToggleOrientationActions[i].setChecked(fOrientation == fToggleOrientationActions[i].getOrientation());
2332
			fToggleOrientationActions[i].setChecked(fOrientation == fToggleOrientationActions[i].getOrientation());
2141
		fCurrentOrientation = orientation;
2333
		fCurrentOrientation= orientation;
2142
		GridLayout layout= (GridLayout) fCounterComposite.getLayout();
2334
		GridLayout layout= (GridLayout)fCounterComposite.getLayout();
2143
		setCounterColumns(layout);
2335
		setCounterColumns(layout);
2144
		fParent.layout();
2336
		fParent.layout();
2145
	}
2337
	}
Lines 2165-2171 Link Here
2165
		} catch (InterruptedException e) {
2357
		} catch (InterruptedException e) {
2166
			// cancelled
2358
			// cancelled
2167
		} catch (InvocationTargetException e) {
2359
		} catch (InvocationTargetException e) {
2168
			CoreException ce= (CoreException) e.getCause();
2360
			CoreException ce= (CoreException)e.getCause();
2169
			StatusManager.getManager().handle(ce.getStatus(), StatusManager.SHOW | StatusManager.LOG);
2361
			StatusManager.getManager().handle(ce.getStatus(), StatusManager.SHOW | StatusManager.LOG);
2170
		}
2362
		}
2171
	}
2363
	}
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java (-44 / +304 lines)
Lines 9-16 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au)
10
 *     Brock Janiczak (brockj@tpg.com.au)
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
12
 *     Xavier Coulon <xcoulon@redhat.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
12
 *     Xavier Coulon <xcoulon@redhat.com> 
13
13
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
14
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588 - [JUnit] Add "Link with Editor" to JUnit view 
14
 *******************************************************************************/
15
 *******************************************************************************/
15
16
16
package org.eclipse.jdt.internal.junit.ui;
17
package org.eclipse.jdt.internal.junit.ui;
Lines 23-29 Link Here
23
import java.util.List;
24
import java.util.List;
24
import java.util.ListIterator;
25
import java.util.ListIterator;
25
26
27
import org.eclipse.jdt.junit.model.ITestCaseElement;
26
import org.eclipse.jdt.junit.model.ITestElement;
28
import org.eclipse.jdt.junit.model.ITestElement;
29
import org.eclipse.jdt.junit.model.ITestSuiteElement;
27
30
28
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.dnd.Clipboard;
32
import org.eclipse.swt.dnd.Clipboard;
Lines 40-47 Link Here
40
import org.eclipse.jface.action.MenuManager;
43
import org.eclipse.jface.action.MenuManager;
41
import org.eclipse.jface.action.Separator;
44
import org.eclipse.jface.action.Separator;
42
import org.eclipse.jface.viewers.AbstractTreeViewer;
45
import org.eclipse.jface.viewers.AbstractTreeViewer;
46
import org.eclipse.jface.viewers.ISelection;
43
import org.eclipse.jface.viewers.ISelectionChangedListener;
47
import org.eclipse.jface.viewers.ISelectionChangedListener;
44
import org.eclipse.jface.viewers.IStructuredSelection;
48
import org.eclipse.jface.viewers.IStructuredSelection;
49
import org.eclipse.jface.viewers.ITreeSelection;
45
import org.eclipse.jface.viewers.SelectionChangedEvent;
50
import org.eclipse.jface.viewers.SelectionChangedEvent;
46
import org.eclipse.jface.viewers.StructuredSelection;
51
import org.eclipse.jface.viewers.StructuredSelection;
47
import org.eclipse.jface.viewers.StructuredViewer;
52
import org.eclipse.jface.viewers.StructuredViewer;
Lines 50-61 Link Here
50
import org.eclipse.jface.viewers.Viewer;
55
import org.eclipse.jface.viewers.Viewer;
51
import org.eclipse.jface.viewers.ViewerFilter;
56
import org.eclipse.jface.viewers.ViewerFilter;
52
57
58
import org.eclipse.jface.text.ITextSelection;
59
60
import org.eclipse.ui.IEditorPart;
61
import org.eclipse.ui.ISelectionListener;
53
import org.eclipse.ui.IWorkbenchActionConstants;
62
import org.eclipse.ui.IWorkbenchActionConstants;
63
import org.eclipse.ui.IWorkbenchPart;
64
import org.eclipse.ui.PartInitException;
54
import org.eclipse.ui.part.PageBook;
65
import org.eclipse.ui.part.PageBook;
55
66
56
import org.eclipse.debug.core.ILaunchManager;
67
import org.eclipse.debug.core.ILaunchManager;
57
68
69
import org.eclipse.jdt.core.ICompilationUnit;
70
import org.eclipse.jdt.core.IJavaElement;
58
import org.eclipse.jdt.core.IJavaProject;
71
import org.eclipse.jdt.core.IJavaProject;
72
import org.eclipse.jdt.core.IMethod;
59
import org.eclipse.jdt.core.IType;
73
import org.eclipse.jdt.core.IType;
60
import org.eclipse.jdt.core.JavaModelException;
74
import org.eclipse.jdt.core.JavaModelException;
61
75
Lines 66-76 Link Here
66
import org.eclipse.jdt.internal.junit.model.TestRunSession;
80
import org.eclipse.jdt.internal.junit.model.TestRunSession;
67
import org.eclipse.jdt.internal.junit.model.TestSuiteElement;
81
import org.eclipse.jdt.internal.junit.model.TestSuiteElement;
68
82
83
import org.eclipse.jdt.ui.JavaUI;
84
85
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
86
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
87
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
69
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
88
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
70
import org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator;
89
import org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator;
71
90
72
91
73
public class TestViewer {
92
public class TestViewer implements ISelectionListener {
74
	private final class TestSelectionListener implements ISelectionChangedListener {
93
	private final class TestSelectionListener implements ISelectionChangedListener {
75
		public void selectionChanged(SelectionChangedEvent event) {
94
		public void selectionChanged(SelectionChangedEvent event) {
76
			handleSelected();
95
			handleSelected();
Lines 87-93 Link Here
87
	private final class FailuresOnlyFilter extends ViewerFilter {
106
	private final class FailuresOnlyFilter extends ViewerFilter {
88
		@Override
107
		@Override
89
		public boolean select(Viewer viewer, Object parentElement, Object element) {
108
		public boolean select(Viewer viewer, Object parentElement, Object element) {
90
			return select(((TestElement) element));
109
			return select(((TestElement)element));
91
		}
110
		}
92
111
93
		public boolean select(TestElement testElement) {
112
		public boolean select(TestElement testElement) {
Lines 95-113 Link Here
95
			if (status.isErrorOrFailure())
114
			if (status.isErrorOrFailure())
96
				return true;
115
				return true;
97
			else
116
			else
98
				return ! fTestRunSession.isRunning() && status == Status.RUNNING;  // rerunning
117
				return !fTestRunSession.isRunning() && status == Status.RUNNING; // rerunning
99
		}
118
		}
100
	}
119
	}
101
120
102
	private static class ReverseList<E> extends AbstractList<E> {
121
	private static class ReverseList<E> extends AbstractList<E> {
103
		private final List<E> fList;
122
		private final List<E> fList;
123
104
		public ReverseList(List<E> list) {
124
		public ReverseList(List<E> list) {
105
			fList= list;
125
			fList= list;
106
		}
126
		}
127
107
		@Override
128
		@Override
108
		public E get(int index) {
129
		public E get(int index) {
109
			return fList.get(fList.size() - index - 1);
130
			return fList.get(fList.size() - index - 1);
110
		}
131
		}
132
111
		@Override
133
		@Override
112
		public int size() {
134
		public int size() {
113
			return fList.size();
135
			return fList.size();
Lines 121-127 Link Here
121
		}
143
		}
122
144
123
		@Override
145
		@Override
124
		public void run(){
146
		public void run() {
125
			fTreeViewer.expandAll();
147
			fTreeViewer.expandAll();
126
		}
148
		}
127
	}
149
	}
Lines 129-157 Link Here
129
	private final FailuresOnlyFilter fFailuresOnlyFilter= new FailuresOnlyFilter();
151
	private final FailuresOnlyFilter fFailuresOnlyFilter= new FailuresOnlyFilter();
130
152
131
	private final TestRunnerViewPart fTestRunnerPart;
153
	private final TestRunnerViewPart fTestRunnerPart;
154
132
	private final Clipboard fClipboard;
155
	private final Clipboard fClipboard;
133
156
134
	private PageBook fViewerbook;
157
	private PageBook fViewerbook;
158
135
	private TreeViewer fTreeViewer;
159
	private TreeViewer fTreeViewer;
160
136
	private TestSessionTreeContentProvider fTreeContentProvider;
161
	private TestSessionTreeContentProvider fTreeContentProvider;
162
137
	private TestSessionLabelProvider fTreeLabelProvider;
163
	private TestSessionLabelProvider fTreeLabelProvider;
164
138
	private TableViewer fTableViewer;
165
	private TableViewer fTableViewer;
166
139
	private TestSessionTableContentProvider fTableContentProvider;
167
	private TestSessionTableContentProvider fTableContentProvider;
168
140
	private TestSessionLabelProvider fTableLabelProvider;
169
	private TestSessionLabelProvider fTableLabelProvider;
170
141
	private SelectionProviderMediator fSelectionProvider;
171
	private SelectionProviderMediator fSelectionProvider;
142
172
143
	private int fLayoutMode;
173
	private int fLayoutMode;
174
144
	private boolean fTreeHasFilter;
175
	private boolean fTreeHasFilter;
176
145
	private boolean fTableHasFilter;
177
	private boolean fTableHasFilter;
146
178
147
	private TestRunSession fTestRunSession;
179
	private TestRunSession fTestRunSession;
148
180
149
	private boolean fTreeNeedsRefresh;
181
	private boolean fTreeNeedsRefresh;
182
150
	private boolean fTableNeedsRefresh;
183
	private boolean fTableNeedsRefresh;
184
151
	private HashSet<TestElement> fNeedUpdate;
185
	private HashSet<TestElement> fNeedUpdate;
186
152
	private TestCaseElement fAutoScrollTarget;
187
	private TestCaseElement fAutoScrollTarget;
153
188
154
	private LinkedList<TestSuiteElement> fAutoClose;
189
	private LinkedList<TestSuiteElement> fAutoClose;
190
155
	private HashSet<TestSuiteElement> fAutoExpand;
191
	private HashSet<TestSuiteElement> fAutoExpand;
156
192
157
193
Lines 191-198 Link Here
191
		fTreeViewer.getTree().addSelectionListener(testOpenListener);
227
		fTreeViewer.getTree().addSelectionListener(testOpenListener);
192
		fTableViewer.getTable().addSelectionListener(testOpenListener);
228
		fTableViewer.getTable().addSelectionListener(testOpenListener);
193
229
230
		// register the selection provider to broadcast selection to other views
194
		fTestRunnerPart.getSite().setSelectionProvider(fSelectionProvider);
231
		fTestRunnerPart.getSite().setSelectionProvider(fSelectionProvider);
195
196
		fViewerbook.showPage(fTreeViewer.getTree());
232
		fViewerbook.showPage(fTreeViewer.getTree());
197
	}
233
	}
198
234
Lines 212-220 Link Here
212
248
213
249
214
	void handleMenuAboutToShow(IMenuManager manager) {
250
	void handleMenuAboutToShow(IMenuManager manager) {
215
		IStructuredSelection selection= (IStructuredSelection) fSelectionProvider.getSelection();
251
		IStructuredSelection selection= (IStructuredSelection)fSelectionProvider.getSelection();
216
		if (! selection.isEmpty()) {
252
		if (!selection.isEmpty()) {
217
			TestElement testElement= (TestElement) selection.getFirstElement();
253
			TestElement testElement= (TestElement)selection.getFirstElement();
218
254
219
			String testLabel= testElement.getTestName();
255
			String testLabel= testElement.getTestName();
220
			String className= testElement.getClassName();
256
			String className= testElement.getClassName();
Lines 226-232 Link Here
226
					manager.add(new RerunAction(JUnitMessages.RerunAction_label_debug, fTestRunnerPart, testElement.getId(), className, null, ILaunchManager.DEBUG_MODE));
262
					manager.add(new RerunAction(JUnitMessages.RerunAction_label_debug, fTestRunnerPart, testElement.getId(), className, null, ILaunchManager.DEBUG_MODE));
227
				}
263
				}
228
			} else {
264
			} else {
229
				TestCaseElement testCaseElement= (TestCaseElement) testElement;
265
				TestCaseElement testCaseElement= (TestCaseElement)testElement;
230
				String testMethodName= testCaseElement.getTestMethodName();
266
				String testMethodName= testCaseElement.getTestMethodName();
231
				manager.add(new OpenTestAction(fTestRunnerPart, testCaseElement));
267
				manager.add(new OpenTestAction(fTestRunnerPart, testCaseElement));
232
				manager.add(new Separator());
268
				manager.add(new Separator());
Lines 277-287 Link Here
277
	}
313
	}
278
314
279
	void handleDefaultSelected() {
315
	void handleDefaultSelected() {
280
		IStructuredSelection selection= (IStructuredSelection) fSelectionProvider.getSelection();
316
		IStructuredSelection selection= (IStructuredSelection)fSelectionProvider.getSelection();
281
		if (selection.size() != 1)
317
		if (selection.size() != 1)
282
			return;
318
			return;
283
319
284
		TestElement testElement= (TestElement) selection.getFirstElement();
320
		TestElement testElement= (TestElement)selection.getFirstElement();
285
321
286
		OpenTestAction action;
322
		OpenTestAction action;
287
		if (testElement instanceof TestSuiteElement) {
323
		if (testElement instanceof TestSuiteElement) {
Lines 306-317 Link Here
306
	}
342
	}
307
343
308
	private void handleSelected() {
344
	private void handleSelected() {
309
		IStructuredSelection selection= (IStructuredSelection) fSelectionProvider.getSelection();
345
		IStructuredSelection selection= (IStructuredSelection)fSelectionProvider.getSelection();
310
		TestElement testElement= null;
346
		TestElement testElement= null;
311
		if (selection.size() == 1) {
347
		if (selection.size() == 1) {
312
			testElement= (TestElement) selection.getFirstElement();
348
			testElement= (TestElement)selection.getFirstElement();
313
		}
349
		}
314
		fTestRunnerPart.handleTestSelected(testElement);
350
		fTestRunnerPart.handleTestSelected(testElement);
351
		// if LinkWithEditor is active, reveal the JavaEditor and select the java type or method 
352
		// matching the selected test element, even if the JavaEditor is opened by not active.
353
		if (fTestRunnerPart.isLinkWithEditorActive()) {
354
			handleTestElementSelected(testElement);
355
		}
315
	}
356
	}
316
357
317
	public synchronized void setShowTime(boolean showTime) {
358
	public synchronized void setShowTime(boolean showTime) {
Lines 339-345 Link Here
339
			IStructuredSelection selection= null;
380
			IStructuredSelection selection= null;
340
			boolean switchLayout= layoutMode != fLayoutMode;
381
			boolean switchLayout= layoutMode != fLayoutMode;
341
			if (switchLayout) {
382
			if (switchLayout) {
342
				selection= (IStructuredSelection) fSelectionProvider.getSelection();
383
				selection= (IStructuredSelection)fSelectionProvider.getSelection();
343
				if (layoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
384
				if (layoutMode == TestRunnerViewPart.LAYOUT_HIERARCHICAL) {
344
					if (fTreeNeedsRefresh) {
385
					if (fTreeNeedsRefresh) {
345
						clearUpdateAndExpansion();
386
						clearUpdateAndExpansion();
Lines 356-362 Link Here
356
			//avoid realizing all TableItems, especially in flat mode!
397
			//avoid realizing all TableItems, especially in flat mode!
357
			StructuredViewer viewer= getActiveViewer();
398
			StructuredViewer viewer= getActiveViewer();
358
			if (failuresOnly) {
399
			if (failuresOnly) {
359
				if (! getActiveViewerHasFilter()) {
400
				if (!getActiveViewerHasFilter()) {
360
					setActiveViewerNeedsRefresh(true);
401
					setActiveViewerNeedsRefresh(true);
361
					setActiveViewerHasFilter(true);
402
					setActiveViewerHasFilter(true);
362
					viewer.setInput(null);
403
					viewer.setInput(null);
Lines 448-462 Link Here
448
				toUpdate= fNeedUpdate.toArray();
489
				toUpdate= fNeedUpdate.toArray();
449
				fNeedUpdate.clear();
490
				fNeedUpdate.clear();
450
			}
491
			}
451
			if (! fTreeNeedsRefresh && toUpdate.length > 0) {
492
			if (!fTreeNeedsRefresh && toUpdate.length > 0) {
452
				if (fTreeHasFilter)
493
				if (fTreeHasFilter)
453
					for (Object element : toUpdate)
494
					for (Object element : toUpdate)
454
						updateElementInTree((TestElement) element);
495
						updateElementInTree((TestElement)element);
455
				else {
496
				else {
456
					HashSet<Object> toUpdateWithParents= new HashSet<Object>();
497
					HashSet<Object> toUpdateWithParents= new HashSet<Object>();
457
					toUpdateWithParents.addAll(Arrays.asList(toUpdate));
498
					toUpdateWithParents.addAll(Arrays.asList(toUpdate));
458
					for (Object element : toUpdate) {
499
					for (Object element : toUpdate) {
459
						TestElement parent= ((TestElement) element).getParent();
500
						TestElement parent= ((TestElement)element).getParent();
460
						while (parent != null) {
501
						while (parent != null) {
461
							toUpdateWithParents.add(parent);
502
							toUpdateWithParents.add(parent);
462
							parent= parent.getParent();
503
							parent= parent.getParent();
Lines 465-474 Link Here
465
					fTreeViewer.update(toUpdateWithParents.toArray(), null);
506
					fTreeViewer.update(toUpdateWithParents.toArray(), null);
466
				}
507
				}
467
			}
508
			}
468
			if (! fTableNeedsRefresh && toUpdate.length > 0) {
509
			if (!fTableNeedsRefresh && toUpdate.length > 0) {
469
				if (fTableHasFilter)
510
				if (fTableHasFilter)
470
					for (Object element : toUpdate)
511
					for (Object element : toUpdate)
471
						updateElementInTable((TestElement) element);
512
						updateElementInTable((TestElement)element);
472
				else
513
				else
473
					fTableViewer.update(toUpdate, null);
514
					fTableViewer.update(toUpdate, null);
474
			}
515
			}
Lines 485-493 Link Here
485
				if (fTreeViewer.testFindItem(current) != null)
526
				if (fTreeViewer.testFindItem(current) != null)
486
					fTreeViewer.remove(current);
527
					fTreeViewer.remove(current);
487
				current= current.getParent();
528
				current= current.getParent();
488
			} while (! (current instanceof TestRoot) && ! isShown(current));
529
			} while (!(current instanceof TestRoot) && !isShown(current));
489
530
490
			while (current != null && ! (current instanceof TestRoot)) {
531
			while (current != null && !(current instanceof TestRoot)) {
491
				fTreeViewer.update(current, null);
532
				fTreeViewer.update(current, null);
492
				current= current.getParent();
533
				current= current.getParent();
493
			}
534
			}
Lines 514-525 Link Here
514
				TestElement previous= getNextFailure(element, false);
555
				TestElement previous= getNextFailure(element, false);
515
				int insertionIndex= -1;
556
				int insertionIndex= -1;
516
				if (previous != null) {
557
				if (previous != null) {
517
					TableItem item= (TableItem) fTableViewer.testFindItem(previous);
558
					TableItem item= (TableItem)fTableViewer.testFindItem(previous);
518
					if (item != null)
559
					if (item != null)
519
						insertionIndex= fTableViewer.getTable().indexOf(item);
560
						insertionIndex= fTableViewer.getTable().indexOf(item);
520
				}
561
				}
521
				fTableViewer.insert(element, insertionIndex);
562
				fTableViewer.insert(element, insertionIndex);
522
			} else  {
563
			} else {
523
				fTableViewer.update(element, null);
564
				fTableViewer.update(element, null);
524
			}
565
			}
525
		} else {
566
		} else {
Lines 532-538 Link Here
532
	}
573
	}
533
574
534
	private void autoScrollInUI() {
575
	private void autoScrollInUI() {
535
		if (! fTestRunnerPart.isAutoScroll()) {
576
		if (!fTestRunnerPart.isAutoScroll()) {
536
			clearAutoExpand();
577
			clearAutoExpand();
537
			fAutoClose.clear();
578
			fAutoClose.clear();
538
			return;
579
			return;
Lines 554-561 Link Here
554
		TestCaseElement current= fAutoScrollTarget;
595
		TestCaseElement current= fAutoScrollTarget;
555
		fAutoScrollTarget= null;
596
		fAutoScrollTarget= null;
556
597
557
		TestSuiteElement parent= current == null ? null : (TestSuiteElement) fTreeContentProvider.getParent(current);
598
		TestSuiteElement parent= current == null ? null : (TestSuiteElement)fTreeContentProvider.getParent(current);
558
		if (fAutoClose.isEmpty() || ! fAutoClose.getLast().equals(parent)) {
599
		if (fAutoClose.isEmpty() || !fAutoClose.getLast().equals(parent)) {
559
			// we're in a new branch, so let's close old OK branches:
600
			// we're in a new branch, so let's close old OK branches:
560
			for (ListIterator<TestSuiteElement> iter= fAutoClose.listIterator(fAutoClose.size()); iter.hasPrevious();) {
601
			for (ListIterator<TestSuiteElement> iter= fAutoClose.listIterator(fAutoClose.size()); iter.hasPrevious();) {
561
				TestSuiteElement previousAutoOpened= iter.previous();
602
				TestSuiteElement previousAutoOpened= iter.previous();
Lines 569-581 Link Here
569
				}
610
				}
570
			}
611
			}
571
612
572
			while (parent != null && ! fTestRunSession.getTestRoot().equals(parent) && fTreeViewer.getExpandedState(parent) == false) {
613
			while (parent != null && !fTestRunSession.getTestRoot().equals(parent) && fTreeViewer.getExpandedState(parent) == false) {
573
				fAutoClose.add(parent); // add to auto-opened elements -> close later if STATUS_OK
614
				fAutoClose.add(parent); // add to auto-opened elements -> close later if STATUS_OK
574
				parent= (TestSuiteElement) fTreeContentProvider.getParent(parent);
615
				parent= (TestSuiteElement)fTreeContentProvider.getParent(parent);
575
			}
616
			}
576
		}
617
		}
577
		if (current != null)
618
		if (current != null)
578
			fTreeViewer.reveal(current);
619
			fTreeViewer.reveal(current);
620
	}
621
622
	/**
623
	 * Sets the current selection from the given {@link IEditorPart} (if it is a
624
	 * {@link CompilationUnitEditor}) and its selection.
625
	 * 
626
	 * @param editor the selected Java Element in the active Compilation Unit Editor
627
	 * 
628
	 * @since 3.7
629
	 */
630
	public void setSelection(final IEditorPart editor) {
631
		final IJavaElement selectedJavaElement= getSelectedJavaElementInEditor(editor);
632
		setSelection(editor, selectedJavaElement);
633
	}
634
635
	/**
636
	 * Sets the current selection from the given {@link IJavaElement} if it matches an
637
	 * {@link ITestCaseElement} and updates the LinkWithEditorAction image in the associated
638
	 * {@link TestRunnerViewPart}.
639
	 * 
640
	 * @param part the {@link IWorkbenchPart} in which the selection changed. Nothing happens if the
641
	 *            given part if the {@link TestRunnerViewPart} associated with this
642
	 *            {@link TestViewer}.
643
	 * @param activeJavaElement the selected Java Element (or null) in the active
644
	 *            {@link IWorkbenchPart}
645
	 * 
646
	 */
647
	private void setSelection(final IWorkbenchPart part, final IJavaElement activeJavaElement) {
648
		if (part != fTestRunnerPart) {
649
			final ITestElement activeTestCaseElement= findTestElement(activeJavaElement);
650
			if (activeTestCaseElement != null) {
651
				// selection is in-sync
652
				fTestRunnerPart.setLinkingWithEditorInSync(true);
653
				// update the current selection in the viewer if it does not match with the java element selected in the given part (if it's not the parent TestViewerPart)
654
				final Object currentSelection= getCurrentViewerSelection();
655
				if ((currentSelection instanceof TestCaseElement && ((TestCaseElement)currentSelection).getJavaMethod() != null && !((TestCaseElement)currentSelection).getJavaMethod().equals(
656
						activeJavaElement))
657
						|| (currentSelection instanceof TestSuiteElement && ((TestSuiteElement)currentSelection).getJavaType() != null && !((TestSuiteElement)currentSelection).getJavaType().equals(
658
								activeJavaElement))) {
659
					final IStructuredSelection selection= new StructuredSelection(activeTestCaseElement);
660
					fSelectionProvider.setSelection(selection, true);
661
				}
662
			}
663
			else {
664
				// selection is out-of-sync: show a different icon on the button.
665
				fTestRunnerPart.setLinkingWithEditorInSync(false);
666
			}
667
		}
668
	}
669
670
	/**
671
	 * @return the current selection in the JUnit Viewer (provided by the underlying selection
672
	 *         provider), or {@code null} if the kind of selection is not an {@link ITreeSelection}
673
	 *         nor an {@link IStructuredSelection}.
674
	 */
675
	private Object getCurrentViewerSelection() {
676
		final ISelection currentSelection= fSelectionProvider.getSelection();
677
		if (currentSelection instanceof ITreeSelection) {
678
			return ((ITreeSelection)currentSelection).getFirstElement();
679
		} else if (currentSelection instanceof IStructuredSelection) {
680
			return ((IStructuredSelection)currentSelection).getFirstElement();
681
		}
682
		return null;
683
	}
684
685
	/**
686
	 * Finds the {@link ITestElement} from the given {@link IJavaElement}
687
	 * 
688
	 * @param javaElement the java element associated with the {@link ITestElement} to find.
689
	 * @return the {@link ITestElement} or null if it could not be found.
690
	 */
691
	private ITestElement findTestElement(final IJavaElement javaElement) {
692
		if (fTestRunSession == null || javaElement == null) {
693
			return null;
694
		}
695
		switch (javaElement.getElementType()) {
696
			case IJavaElement.METHOD:
697
				final IMethod javaMethod= (IMethod)javaElement;
698
				final IType javaType= (IType)javaMethod.getAncestor(IJavaElement.TYPE);
699
				final String testClassName= javaType.getFullyQualifiedName();
700
				final String testMethodName= javaMethod.getElementName();
701
				return findTestCaseElement(fTestRunSession.getTestRoot(), testClassName, testMethodName);
702
			case IJavaElement.TYPE:
703
				return findTestSuiteElement(fTestRunSession.getTestRoot(), ((IType)javaElement).getFullyQualifiedName());
704
			default:
705
				return null;
706
		}
707
	}
708
709
	/**
710
	 * Finds the {@link ITestCaseElement} with the given test class name and test method name in the
711
	 * given {@link ITestSuiteElement}
712
	 * 
713
	 * @param parentElement the parent Test Suite
714
	 * @param testClassName the name of the test class
715
	 * @param testMethodName the name of the test method
716
	 * 
717
	 * @return the {@link ITestCaseElement} or null if it could not be found.
718
	 */
719
	private ITestCaseElement findTestCaseElement(final ITestSuiteElement parentElement, final String testClassName, final String testMethodName) {
720
		for (ITestElement childElement : parentElement.getChildren()) {
721
			if (childElement instanceof ITestCaseElement) {
722
				final TestCaseElement testCaseElement= (TestCaseElement)childElement;
723
				if (testCaseElement.getJavaType() != null && testCaseElement.getJavaType().getFullyQualifiedName().equals(testClassName) && testCaseElement.getJavaMethod() != null
724
						&& testCaseElement.getJavaMethod() != null && testCaseElement.getJavaMethod().getElementName().equals(testMethodName)) {
725
					return testCaseElement;
726
				}
727
			} else if (childElement instanceof ITestSuiteElement) {
728
				final ITestCaseElement localResult= findTestCaseElement((ITestSuiteElement)childElement, testClassName, testMethodName);
729
				if (localResult != null) {
730
					return localResult;
731
				}
732
			}
733
		}
734
		return null;
735
	}
736
737
	/**
738
	 * Finds the {@link ITestSuiteElement} with the given test class name in the given
739
	 * {@link ITestSuiteElement}
740
	 * 
741
	 * @param parentElement the parent Test Suite
742
	 * @param testClassName the name of the test class
743
	 * 
744
	 * @return the {@link ITestSuiteElement} or null if it could not be found.
745
	 */
746
	private ITestSuiteElement findTestSuiteElement(final ITestSuiteElement parentElement, final String testClassName) {
747
		for (ITestElement childElement : parentElement.getChildren()) {
748
			if (childElement instanceof ITestSuiteElement) {
749
				final ITestSuiteElement childTestSuite= (ITestSuiteElement)childElement;
750
				if (childTestSuite.getSuiteTypeName().equals(testClassName)) {
751
					return childTestSuite;
752
				}
753
			}
754
		}
755
		return null;
579
	}
756
	}
580
757
581
	public void selectFirstFailure() {
758
	public void selectFirstFailure() {
Lines 585-592 Link Here
585
	}
762
	}
586
763
587
	public void selectFailure(boolean showNext) {
764
	public void selectFailure(boolean showNext) {
588
		IStructuredSelection selection= (IStructuredSelection) getActiveViewer().getSelection();
765
		IStructuredSelection selection= (IStructuredSelection)getActiveViewer().getSelection();
589
		TestElement selected= (TestElement) selection.getFirstElement();
766
		TestElement selected= (TestElement)selection.getFirstElement();
590
		TestElement next;
767
		TestElement next;
591
768
592
		if (selected == null) {
769
		if (selected == null) {
Lines 601-607 Link Here
601
778
602
	private TestElement getNextFailure(TestElement selected, boolean showNext) {
779
	private TestElement getNextFailure(TestElement selected, boolean showNext) {
603
		if (selected instanceof TestSuiteElement) {
780
		if (selected instanceof TestSuiteElement) {
604
			TestElement nextChild= getNextChildFailure((TestSuiteElement) selected, showNext);
781
			TestElement nextChild= getNextChildFailure((TestSuiteElement)selected, showNext);
605
			if (nextChild != null)
782
			if (nextChild != null)
606
				return nextChild;
783
				return nextChild;
607
		}
784
		}
Lines 614-630 Link Here
614
			return null;
791
			return null;
615
792
616
		List<ITestElement> siblings= Arrays.asList(parent.getChildren());
793
		List<ITestElement> siblings= Arrays.asList(parent.getChildren());
617
		if (! showNext)
794
		if (!showNext)
618
			siblings= new ReverseList<ITestElement>(siblings);
795
			siblings= new ReverseList<ITestElement>(siblings);
619
796
620
		int nextIndex= siblings.indexOf(current) + 1;
797
		int nextIndex= siblings.indexOf(current) + 1;
621
		for (int i= nextIndex; i < siblings.size(); i++) {
798
		for (int i= nextIndex; i < siblings.size(); i++) {
622
			TestElement sibling= (TestElement) siblings.get(i);
799
			TestElement sibling= (TestElement)siblings.get(i);
623
			if (sibling.getStatus().isErrorOrFailure()) {
800
			if (sibling.getStatus().isErrorOrFailure()) {
624
				if (sibling instanceof TestCaseElement) {
801
				if (sibling instanceof TestCaseElement) {
625
					return (TestCaseElement) sibling;
802
					return (TestCaseElement)sibling;
626
				} else {
803
				} else {
627
					return getNextChildFailure((TestSuiteElement) sibling, showNext);
804
					return getNextChildFailure((TestSuiteElement)sibling, showNext);
628
				}
805
				}
629
			}
806
			}
630
		}
807
		}
Lines 633-647 Link Here
633
810
634
	private TestCaseElement getNextChildFailure(TestSuiteElement root, boolean showNext) {
811
	private TestCaseElement getNextChildFailure(TestSuiteElement root, boolean showNext) {
635
		List<ITestElement> children= Arrays.asList(root.getChildren());
812
		List<ITestElement> children= Arrays.asList(root.getChildren());
636
		if (! showNext)
813
		if (!showNext)
637
			children= new ReverseList<ITestElement>(children);
814
			children= new ReverseList<ITestElement>(children);
638
		for (int i= 0; i < children.size(); i++) {
815
		for (int i= 0; i < children.size(); i++) {
639
			TestElement child= (TestElement) children.get(i);
816
			TestElement child= (TestElement)children.get(i);
640
			if (child.getStatus().isErrorOrFailure()) {
817
			if (child.getStatus().isErrorOrFailure()) {
641
				if (child instanceof TestCaseElement) {
818
				if (child instanceof TestCaseElement) {
642
					return (TestCaseElement) child;
819
					return (TestCaseElement)child;
643
				} else {
820
				} else {
644
					return getNextChildFailure((TestSuiteElement) child, showNext);
821
					return getNextChildFailure((TestSuiteElement)child, showNext);
645
				}
822
				}
646
			}
823
			}
647
		}
824
		}
Lines 682-688 Link Here
682
	}
859
	}
683
860
684
	public synchronized void registerFailedForAutoScroll(TestElement testElement) {
861
	public synchronized void registerFailedForAutoScroll(TestElement testElement) {
685
		TestSuiteElement parent= (TestSuiteElement) fTreeContentProvider.getParent(testElement);
862
		TestSuiteElement parent= (TestSuiteElement)fTreeContentProvider.getParent(testElement);
686
		if (parent != null)
863
		if (parent != null)
687
			fAutoExpand.add(parent);
864
			fAutoExpand.add(parent);
688
	}
865
	}
Lines 691-695 Link Here
691
		fTreeViewer.expandToLevel(2);
868
		fTreeViewer.expandToLevel(2);
692
	}
869
	}
693
870
694
}
871
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
872
		if (selection instanceof ITextSelection && part instanceof IEditorPart) {
873
			setSelection((IEditorPart)part);
874
		}
875
	}
695
876
877
	/**
878
	 * @return the selected {@link IJavaElement} in the current editor if it is a {@link CompilationUnitEditor}, null otherwise. 
879
	 * @param editor the editor
880
	 */
881
	private IJavaElement getSelectedJavaElementInEditor(final IEditorPart editor) {
882
		if (editor instanceof CompilationUnitEditor) {
883
			final CompilationUnitEditor compilationUnitEditor = (CompilationUnitEditor)editor;
884
			try {
885
				final IJavaElement inputJavaElement= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
886
				final ITextSelection selection= (ITextSelection)compilationUnitEditor.getSelectionProvider().getSelection();
887
				final ICompilationUnit compilationUnit= (ICompilationUnit)inputJavaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
888
				return compilationUnit.getElementAt(selection.getOffset());
889
			} catch (JavaModelException e) {
890
				JUnitPlugin.log(e);
891
			}
892
		}
893
		return null;
894
	}
895
896
	/**
897
	 * Handles the case when a {@link TestCaseElement} has been selected: open the associated code
898
	 * in the Java Editor
899
	 * 
900
	 * @param testElement the new selected {@link TestCaseElement}
901
	 */
902
	private void handleTestElementSelected(final ITestElement testElement) {
903
		if (testElement instanceof TestCaseElement) {
904
			final IMethod selectedMethod= ((TestCaseElement)testElement).getJavaMethod();
905
			handleJavaElementSelected(selectedMethod);
906
		} else if (testElement instanceof TestSuiteElement) {
907
			final IJavaElement selectedElement= ((TestSuiteElement)testElement).getJavaElement();
908
			handleJavaElementSelected(selectedElement);
909
		}
910
	}
911
912
	/**
913
	 * Reveals the given {@link IJavaElement} in its associated Editor if this later is already
914
	 * open, and sets the "Link with Editor" button state accordingly.
915
	 * 
916
	 * @param selectedJavaElement the selected {@link IJavaElement} in the {@link TestViewer} that
917
	 *            should be revealed in its Java Editor.
918
	 */
919
	private void handleJavaElementSelected(final IJavaElement selectedJavaElement) {
920
		try {
921
			final IEditorPart editor= EditorUtility.isOpenInEditor(selectedJavaElement);
922
			if (selectedJavaElement != null && editor != null && editor instanceof JavaEditor) {
923
				final JavaEditor javaEditor= (JavaEditor)editor;
924
				final ITextSelection javaEditorSelection= (ITextSelection)javaEditor.getSelectionProvider().getSelection();
925
				final IEditorPart selectedMethodEditor= EditorUtility.isOpenInEditor(selectedJavaElement);
926
				// checks if the editor is already open or not
927
				if (selectedMethodEditor != null) {
928
					// Retrieve the current active editor
929
					final IEditorPart activeEditor= fTestRunnerPart.getSite().getPage().getActiveEditor();
930
					// open the required editor if it is not the active one   
931
					if (!selectedMethodEditor.equals(activeEditor)) {
932
						EditorUtility.openInEditor(selectedJavaElement, false);
933
					}
934
					// retrieve the current java element (unless the associated compilation unit cannot be retrieved)
935
					final ICompilationUnit compilationUnit= (ICompilationUnit)selectedJavaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
936
					if (compilationUnit != null) {
937
						final IJavaElement javaEditorSelectedElement= compilationUnit.getElementAt(javaEditorSelection.getOffset());
938
						// force to reveal the selected element in case where the editor was not active
939
						if (!selectedMethodEditor.equals(activeEditor) || !selectedJavaElement.equals(javaEditorSelectedElement)) {
940
							EditorUtility.revealInEditor(selectedMethodEditor, selectedJavaElement);
941
						}
942
						fTestRunnerPart.setLinkingWithEditorInSync(true);
943
						return;
944
					}
945
				}
946
			}
947
		} catch (JavaModelException e) {
948
			JUnitPlugin.log(e);
949
		} catch (PartInitException e) {
950
			// occurs if the editor could not be opened or the input element is not valid Status code
951
			JUnitPlugin.log(e);
952
		}
953
		fTestRunnerPart.setLinkingWithEditorInSync(false);
954
	}
955
}

Return to bug 372588