Lines 96-105
import org.eclipse.jface.dialogs.InputDialog;
Link Here
|
96 |
import org.eclipse.jface.dialogs.MessageDialog; |
96 |
import org.eclipse.jface.dialogs.MessageDialog; |
97 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
97 |
import org.eclipse.jface.operation.IRunnableWithProgress; |
98 |
import org.eclipse.jface.resource.ImageDescriptor; |
98 |
import org.eclipse.jface.resource.ImageDescriptor; |
|
|
99 |
import org.eclipse.jface.viewers.IPostSelectionProvider; |
100 |
import org.eclipse.jface.viewers.ISelection; |
101 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
102 |
import org.eclipse.jface.viewers.ISelectionProvider; |
103 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
104 |
|
105 |
import org.eclipse.jface.text.ITextSelection; |
99 |
|
106 |
|
100 |
import org.eclipse.ui.IActionBars; |
107 |
import org.eclipse.ui.IActionBars; |
101 |
import org.eclipse.ui.IEditorActionBarContributor; |
108 |
import org.eclipse.ui.IEditorActionBarContributor; |
102 |
import org.eclipse.ui.IEditorPart; |
109 |
import org.eclipse.ui.IEditorPart; |
|
|
110 |
import org.eclipse.ui.IEditorReference; |
103 |
import org.eclipse.ui.IMemento; |
111 |
import org.eclipse.ui.IMemento; |
104 |
import org.eclipse.ui.IPartListener2; |
112 |
import org.eclipse.ui.IPartListener2; |
105 |
import org.eclipse.ui.IViewPart; |
113 |
import org.eclipse.ui.IViewPart; |
Lines 128-138
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
Link Here
|
128 |
import org.eclipse.debug.ui.DebugUITools; |
136 |
import org.eclipse.debug.ui.DebugUITools; |
129 |
|
137 |
|
130 |
import org.eclipse.jdt.core.ElementChangedEvent; |
138 |
import org.eclipse.jdt.core.ElementChangedEvent; |
|
|
139 |
import org.eclipse.jdt.core.ICompilationUnit; |
131 |
import org.eclipse.jdt.core.IElementChangedListener; |
140 |
import org.eclipse.jdt.core.IElementChangedListener; |
132 |
import org.eclipse.jdt.core.IJavaElement; |
141 |
import org.eclipse.jdt.core.IJavaElement; |
133 |
import org.eclipse.jdt.core.IJavaElementDelta; |
142 |
import org.eclipse.jdt.core.IJavaElementDelta; |
134 |
import org.eclipse.jdt.core.IJavaProject; |
143 |
import org.eclipse.jdt.core.IJavaProject; |
|
|
144 |
import org.eclipse.jdt.core.IMethod; |
145 |
import org.eclipse.jdt.core.IType; |
135 |
import org.eclipse.jdt.core.JavaCore; |
146 |
import org.eclipse.jdt.core.JavaCore; |
|
|
147 |
import org.eclipse.jdt.core.JavaModelException; |
136 |
|
148 |
|
137 |
import org.eclipse.jdt.internal.junit.BasicElementLabels; |
149 |
import org.eclipse.jdt.internal.junit.BasicElementLabels; |
138 |
import org.eclipse.jdt.internal.junit.JUnitCorePlugin; |
150 |
import org.eclipse.jdt.internal.junit.JUnitCorePlugin; |
Lines 149-154
import org.eclipse.jdt.internal.junit.model.TestRunSession;
Link Here
|
149 |
|
161 |
|
150 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
162 |
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants; |
151 |
|
163 |
|
|
|
164 |
import org.eclipse.jdt.ui.JavaUI; |
165 |
|
166 |
import org.eclipse.jdt.internal.ui.actions.AbstractToggleLinkingAction; |
167 |
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; |
152 |
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory; |
168 |
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory; |
153 |
|
169 |
|
154 |
/** |
170 |
/** |
Lines 210-215
public class TestRunnerViewPart extends ViewPart {
Link Here
|
210 |
private Action fPreviousAction; |
226 |
private Action fPreviousAction; |
211 |
|
227 |
|
212 |
private StopAction fStopAction; |
228 |
private StopAction fStopAction; |
|
|
229 |
|
230 |
private LinkWithEditorAction fLinkWithEditorAction; |
231 |
|
213 |
private JUnitCopyAction fCopyAction; |
232 |
private JUnitCopyAction fCopyAction; |
214 |
private Action fPasteAction; |
233 |
private Action fPasteAction; |
215 |
|
234 |
|
Lines 342-348
public class TestRunnerViewPart extends ViewPart {
Link Here
|
342 |
|
361 |
|
343 |
protected boolean fPartIsVisible= false; |
362 |
protected boolean fPartIsVisible= false; |
344 |
|
363 |
|
345 |
|
|
|
346 |
private class RunnerViewHistory extends ViewHistory<TestRunSession> { |
364 |
private class RunnerViewHistory extends ViewHistory<TestRunSession> { |
347 |
|
365 |
|
348 |
@Override |
366 |
@Override |
Lines 705-710
public class TestRunnerViewPart extends ViewPart {
Link Here
|
705 |
startUpdateJobs(); |
723 |
startUpdateJobs(); |
706 |
|
724 |
|
707 |
fStopAction.setEnabled(true); |
725 |
fStopAction.setEnabled(true); |
|
|
726 |
fLinkWithEditorAction.setEnabled(true); |
727 |
|
708 |
fRerunLastTestAction.setEnabled(true); |
728 |
fRerunLastTestAction.setEnabled(true); |
709 |
} |
729 |
} |
710 |
|
730 |
|
Lines 722-727
public class TestRunnerViewPart extends ViewPart {
Link Here
|
722 |
if (isDisposed()) |
742 |
if (isDisposed()) |
723 |
return; |
743 |
return; |
724 |
fStopAction.setEnabled(lastLaunchIsKeptAlive()); |
744 |
fStopAction.setEnabled(lastLaunchIsKeptAlive()); |
|
|
745 |
fLinkWithEditorAction.setEnabled(fTestRunSession != null); |
725 |
updateRerunFailedFirstAction(); |
746 |
updateRerunFailedFirstAction(); |
726 |
processChangesInUI(); |
747 |
processChangesInUI(); |
727 |
if (hasErrorsOrFailures()) { |
748 |
if (hasErrorsOrFailures()) { |
Lines 899-904
public class TestRunnerViewPart extends ViewPart {
Link Here
|
899 |
} |
920 |
} |
900 |
} |
921 |
} |
901 |
|
922 |
|
|
|
923 |
private class LinkWithEditorAction extends AbstractToggleLinkingAction { |
924 |
|
925 |
@Override |
926 |
public void run() { |
927 |
setLinkingEnabled(isChecked()); |
928 |
} |
929 |
} |
930 |
|
902 |
private class RerunLastAction extends Action { |
931 |
private class RerunLastAction extends Action { |
903 |
public RerunLastAction() { |
932 |
public RerunLastAction() { |
904 |
setText(JUnitMessages.TestRunnerViewPart_rerunaction_label); |
933 |
setText(JUnitMessages.TestRunnerViewPart_rerunaction_label); |
Lines 1200-1205
public class TestRunnerViewPart extends ViewPart {
Link Here
|
1200 |
} |
1229 |
} |
1201 |
} |
1230 |
} |
1202 |
|
1231 |
|
|
|
1232 |
/** |
1233 |
* Links the selected test method with the Java Editor |
1234 |
* @param enabled boolean to indicate if the link with editor is enabled (<code>true</code>) or not (<code>false</code>) |
1235 |
*/ |
1236 |
public void setLinkingEnabled(boolean enabled) { |
1237 |
final IWorkbenchPage page= getSite().getPage(); |
1238 |
if(page == null) { |
1239 |
return; |
1240 |
} |
1241 |
if (enabled) { |
1242 |
// add an IPartListener for future editor activations/opening/closing/etc. |
1243 |
page.addPartListener(fLinkWithEditorPartListener); |
1244 |
} else { |
1245 |
// removes the IPartListener |
1246 |
page.removePartListener(fLinkWithEditorPartListener); |
1247 |
} |
1248 |
for(IEditorReference editorReference : page.getEditorReferences()) { |
1249 |
final IEditorPart editor = editorReference.getEditor(false); |
1250 |
// set the current editor as active as well |
1251 |
if (editor != null && enabled) { |
1252 |
editorActivated(editor); |
1253 |
} |
1254 |
// unset the current editor as active as well |
1255 |
else if(editor != null && !enabled){ |
1256 |
editorDeactivated(editor); |
1257 |
} |
1258 |
} |
1259 |
} |
1260 |
|
1261 |
|
1262 |
private final IPartListener2 fLinkWithEditorPartListener= new IPartListener2() { |
1263 |
public void partVisible(IWorkbenchPartReference partRef) {} |
1264 |
public void partBroughtToTop(IWorkbenchPartReference partRef) {} |
1265 |
public void partHidden(IWorkbenchPartReference partRef) {} |
1266 |
public void partOpened(IWorkbenchPartReference partRef) {} |
1267 |
public void partInputChanged(IWorkbenchPartReference partRef) {} |
1268 |
public void partClosed(IWorkbenchPartReference partRef) {} |
1269 |
|
1270 |
public void partActivated(IWorkbenchPartReference partRef) { |
1271 |
if (partRef instanceof IEditorReference) { |
1272 |
editorActivated(((IEditorReference) partRef).getEditor(true)); |
1273 |
} |
1274 |
} |
1275 |
|
1276 |
public void partDeactivated(IWorkbenchPartReference partRef) { |
1277 |
if (partRef instanceof IEditorReference) { |
1278 |
editorDeactivated(((IEditorReference) partRef).getEditor(true)); |
1279 |
} |
1280 |
} |
1281 |
|
1282 |
}; |
1283 |
|
1284 |
/** |
1285 |
* Static Inner Java Editor selection listener |
1286 |
* When the user moves to another |
1287 |
*/ |
1288 |
private class JavaEditorSelectionListener implements ISelectionChangedListener { |
1289 |
|
1290 |
private final ICompilationUnit compilationUnit; |
1291 |
|
1292 |
JavaEditorSelectionListener(final ICompilationUnit compilationUnit) { |
1293 |
this.compilationUnit = compilationUnit; |
1294 |
} |
1295 |
|
1296 |
public void selectionChanged(final SelectionChangedEvent event) { |
1297 |
selectActiveTestCaseElement(event.getSelection()); |
1298 |
} |
1299 |
|
1300 |
private IJavaElement getActiveJavaElement(final ISelection selection) { |
1301 |
if(selection instanceof ITextSelection) { |
1302 |
final int offset= ((ITextSelection)selection).getOffset(); |
1303 |
try { |
1304 |
return compilationUnit.getElementAt(offset); |
1305 |
} catch (JavaModelException e) { |
1306 |
} |
1307 |
} |
1308 |
return null; |
1309 |
} |
1310 |
|
1311 |
public void selectActiveTestCaseElement(final ISelection selection) { |
1312 |
final IJavaElement activeJavaElement = getActiveJavaElement(selection); |
1313 |
// select the method in the JUnit ViewPart |
1314 |
if(activeJavaElement != null && activeJavaElement.getElementType() == IJavaElement.METHOD) { |
1315 |
final IMethod activeJavaMethod = (IMethod)activeJavaElement; |
1316 |
final IType activeJavaType = (IType)activeJavaMethod.getAncestor(IJavaElement.TYPE); |
1317 |
fTestViewer.selectTestCaseElement(activeJavaType.getFullyQualifiedName(), activeJavaMethod.getElementName()); |
1318 |
} |
1319 |
|
1320 |
} |
1321 |
|
1322 |
/** |
1323 |
* Overriding java.lang.Object#hashCode() using the |
1324 |
* {@link ICompilationUnit#getHandleIdentifier()} value to avoid duplicate listener |
1325 |
* registrations in the {@link JavaEditor}'s {@link IPostSelectionProvider}. |
1326 |
*/ |
1327 |
@Override |
1328 |
public int hashCode() { |
1329 |
final int prime= 31; |
1330 |
int result= 1; |
1331 |
result= prime * result + ((compilationUnit == null) ? 0 : compilationUnit.getHandleIdentifier().hashCode()); |
1332 |
return result; |
1333 |
} |
1334 |
|
1335 |
/** |
1336 |
* Overriding java.lang.Object#equals() using the |
1337 |
* {@link ICompilationUnit#getHandleIdentifier()} value to avoid duplicate listener |
1338 |
* registrations in the {@link JavaEditor}'s {@link IPostSelectionProvider}. |
1339 |
*/ |
1340 |
@Override |
1341 |
public boolean equals(Object obj) { |
1342 |
if (this == obj) { |
1343 |
return true; |
1344 |
} |
1345 |
if (obj == null) { |
1346 |
return false; |
1347 |
} |
1348 |
if (getClass() != obj.getClass()) { |
1349 |
return false; |
1350 |
} |
1351 |
JavaEditorSelectionListener other= (JavaEditorSelectionListener)obj; |
1352 |
if (compilationUnit == null) { |
1353 |
if (other.compilationUnit != null) { |
1354 |
return false; |
1355 |
} |
1356 |
} else if (!compilationUnit.getHandleIdentifier().equals(other.compilationUnit.getHandleIdentifier())) { |
1357 |
return false; |
1358 |
} |
1359 |
return true; |
1360 |
} |
1361 |
|
1362 |
|
1363 |
} |
1364 |
|
1365 |
private JavaEditorSelectionListener fJavaEditorSelectionListener; |
1366 |
|
1367 |
/** |
1368 |
* An editor has been activated. Set the selection in this JUnit ViewPart |
1369 |
* to be the editor's input, if linking is enabled. |
1370 |
* @param editor the activated editor |
1371 |
*/ |
1372 |
private void editorActivated(IEditorPart editor) { |
1373 |
if(!(editor instanceof JavaEditor)) { |
1374 |
return; |
1375 |
} |
1376 |
final ISelectionProvider selectionProvider = ((JavaEditor)editor).getSelectionProvider(); |
1377 |
final Object input= JavaUI.getEditorInputJavaElement(editor.getEditorInput()); |
1378 |
if (input instanceof ICompilationUnit && selectionProvider instanceof IPostSelectionProvider) { |
1379 |
final ICompilationUnit unit = (ICompilationUnit) input; |
1380 |
final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)selectionProvider; |
1381 |
fJavaEditorSelectionListener = new JavaEditorSelectionListener(unit); |
1382 |
postSelectionProvider.addPostSelectionChangedListener(fJavaEditorSelectionListener); |
1383 |
fJavaEditorSelectionListener.selectActiveTestCaseElement(selectionProvider.getSelection()); |
1384 |
} |
1385 |
} |
1386 |
|
1387 |
/** |
1388 |
* An editor has been deactivated. |
1389 |
* @param editor the activated editor |
1390 |
*/ |
1391 |
private void editorDeactivated(IEditorPart editor) { |
1392 |
if(!(editor instanceof JavaEditor)) { |
1393 |
return; |
1394 |
} |
1395 |
final ISelectionProvider selectionProvider = ((JavaEditor)editor).getSelectionProvider(); |
1396 |
if (selectionProvider instanceof IPostSelectionProvider) { |
1397 |
final IPostSelectionProvider postSelectionProvider = (IPostSelectionProvider)selectionProvider; |
1398 |
postSelectionProvider.removePostSelectionChangedListener(fJavaEditorSelectionListener); |
1399 |
} |
1400 |
} |
1401 |
|
1402 |
|
1203 |
private void startUpdateJobs() { |
1403 |
private void startUpdateJobs() { |
1204 |
postSyncProcessChanges(); |
1404 |
postSyncProcessChanges(); |
1205 |
|
1405 |
|
Lines 1507-1517
action enablement
Link Here
|
1507 |
startUpdateJobs(); |
1707 |
startUpdateJobs(); |
1508 |
|
1708 |
|
1509 |
fStopAction.setEnabled(true); |
1709 |
fStopAction.setEnabled(true); |
|
|
1710 |
fLinkWithEditorAction.setEnabled(true); |
1510 |
|
1711 |
|
1511 |
} else /* old or fresh session: don't want jobs at this stage */ { |
1712 |
} else /* old or fresh session: don't want jobs at this stage */ { |
1512 |
stopUpdateJobs(); |
1713 |
stopUpdateJobs(); |
1513 |
|
1714 |
|
1514 |
fStopAction.setEnabled(fTestRunSession.isKeptAlive()); |
1715 |
fStopAction.setEnabled(fTestRunSession.isKeptAlive()); |
|
|
1716 |
fLinkWithEditorAction.setEnabled(fTestRunSession != null); |
1515 |
fTestViewer.expandFirstLevel(); |
1717 |
fTestViewer.expandFirstLevel(); |
1516 |
} |
1718 |
} |
1517 |
} |
1719 |
} |
Lines 1887-1892
action enablement
Link Here
|
1887 |
fStopAction= new StopAction(); |
2089 |
fStopAction= new StopAction(); |
1888 |
fStopAction.setEnabled(false); |
2090 |
fStopAction.setEnabled(false); |
1889 |
|
2091 |
|
|
|
2092 |
fLinkWithEditorAction= new LinkWithEditorAction(); |
2093 |
fLinkWithEditorAction.setEnabled(false); |
2094 |
|
1890 |
fRerunLastTestAction= new RerunLastAction(); |
2095 |
fRerunLastTestAction= new RerunLastAction(); |
1891 |
IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class); |
2096 |
IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class); |
1892 |
IHandler handler = new AbstractHandler() { |
2097 |
IHandler handler = new AbstractHandler() { |
Lines 1937-1943
action enablement
Link Here
|
1937 |
toolBar.add(fRerunFailedFirstAction); |
2142 |
toolBar.add(fRerunFailedFirstAction); |
1938 |
toolBar.add(fStopAction); |
2143 |
toolBar.add(fStopAction); |
1939 |
toolBar.add(fViewHistory.createHistoryDropDownAction()); |
2144 |
toolBar.add(fViewHistory.createHistoryDropDownAction()); |
1940 |
|
2145 |
toolBar.add(new Separator()); |
|
|
2146 |
toolBar.add(fLinkWithEditorAction); |
2147 |
|
1941 |
|
2148 |
|
1942 |
viewMenu.add(fShowTestHierarchyAction); |
2149 |
viewMenu.add(fShowTestHierarchyAction); |
1943 |
viewMenu.add(fShowTimeAction); |
2150 |
viewMenu.add(fShowTimeAction); |