KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > TestRunnerViewPart


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  * Julien Ruaux: jruaux@octo.com see bug 25324 Ability to know when tests are finished [junit]
11  * Vincent Massol: vmassol@octo.com 25324 Ability to know when tests are finished [junit]
12  * Sebastian Davids: sdavids@gmx.de 35762 JUnit View wasting a lot of screen space [JUnit]
13  *******************************************************************************/

14 package org.eclipse.jdt.internal.junit.ui;
15
16 import java.io.BufferedWriter JavaDoc;
17 import java.io.File JavaDoc;
18 import java.io.FileWriter JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.text.DateFormat JavaDoc;
21 import java.text.MessageFormat JavaDoc;
22 import java.text.NumberFormat JavaDoc;
23 import java.text.SimpleDateFormat JavaDoc;
24 import java.util.Date JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.eclipse.core.commands.AbstractHandler;
29 import org.eclipse.core.commands.ExecutionEvent;
30 import org.eclipse.core.commands.ExecutionException;
31 import org.eclipse.core.commands.IHandler;
32
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IProgressMonitor;
35 import org.eclipse.core.runtime.IStatus;
36 import org.eclipse.core.runtime.Status;
37 import org.eclipse.core.runtime.jobs.ILock;
38 import org.eclipse.core.runtime.jobs.Job;
39
40 import org.eclipse.swt.SWT;
41 import org.eclipse.swt.custom.CLabel;
42 import org.eclipse.swt.custom.SashForm;
43 import org.eclipse.swt.custom.ViewForm;
44 import org.eclipse.swt.dnd.Clipboard;
45 import org.eclipse.swt.events.ControlEvent;
46 import org.eclipse.swt.events.ControlListener;
47 import org.eclipse.swt.graphics.Image;
48 import org.eclipse.swt.graphics.Point;
49 import org.eclipse.swt.layout.GridData;
50 import org.eclipse.swt.layout.GridLayout;
51 import org.eclipse.swt.widgets.Composite;
52 import org.eclipse.swt.widgets.Display;
53 import org.eclipse.swt.widgets.FileDialog;
54 import org.eclipse.swt.widgets.Layout;
55 import org.eclipse.swt.widgets.Shell;
56 import org.eclipse.swt.widgets.ToolBar;
57
58 import org.eclipse.jface.action.Action;
59 import org.eclipse.jface.action.IAction;
60 import org.eclipse.jface.action.IMenuListener;
61 import org.eclipse.jface.action.IMenuManager;
62 import org.eclipse.jface.action.IStatusLineManager;
63 import org.eclipse.jface.action.IToolBarManager;
64 import org.eclipse.jface.action.MenuManager;
65 import org.eclipse.jface.action.Separator;
66 import org.eclipse.jface.dialogs.ErrorDialog;
67 import org.eclipse.jface.dialogs.MessageDialog;
68 import org.eclipse.jface.preference.IPreferenceStore;
69 import org.eclipse.jface.resource.ImageDescriptor;
70
71 import org.eclipse.ui.IActionBars;
72 import org.eclipse.ui.IEditorActionBarContributor;
73 import org.eclipse.ui.IEditorPart;
74 import org.eclipse.ui.IMemento;
75 import org.eclipse.ui.IPartListener2;
76 import org.eclipse.ui.IViewPart;
77 import org.eclipse.ui.IViewSite;
78 import org.eclipse.ui.IWorkbenchActionConstants;
79 import org.eclipse.ui.IWorkbenchPage;
80 import org.eclipse.ui.IWorkbenchPart;
81 import org.eclipse.ui.IWorkbenchPartReference;
82 import org.eclipse.ui.IWorkbenchWindow;
83 import org.eclipse.ui.PartInitException;
84 import org.eclipse.ui.PlatformUI;
85 import org.eclipse.ui.actions.ActionFactory;
86 import org.eclipse.ui.handlers.IHandlerActivation;
87 import org.eclipse.ui.handlers.IHandlerService;
88 import org.eclipse.ui.part.EditorActionBarContributor;
89 import org.eclipse.ui.part.ViewPart;
90 import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
91 import org.eclipse.ui.progress.UIJob;
92
93 import org.eclipse.debug.core.ILaunch;
94 import org.eclipse.debug.core.ILaunchConfiguration;
95 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
96
97 import org.eclipse.debug.ui.DebugUITools;
98
99 import org.eclipse.jdt.core.ElementChangedEvent;
100 import org.eclipse.jdt.core.IElementChangedListener;
101 import org.eclipse.jdt.core.IJavaElement;
102 import org.eclipse.jdt.core.IJavaElementDelta;
103 import org.eclipse.jdt.core.IJavaProject;
104 import org.eclipse.jdt.core.JavaCore;
105
106 import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
107
108 import org.eclipse.jdt.junit.model.ITestElement.Result;
109
110 import org.eclipse.jdt.internal.junit.Messages;
111 import org.eclipse.jdt.internal.junit.launcher.ITestKind;
112 import org.eclipse.jdt.internal.junit.launcher.JUnitLaunchConfigurationConstants;
113 import org.eclipse.jdt.internal.junit.launcher.TestKindRegistry;
114 import org.eclipse.jdt.internal.junit.model.ITestRunSessionListener;
115 import org.eclipse.jdt.internal.junit.model.ITestSessionListener;
116 import org.eclipse.jdt.internal.junit.model.JUnitModel;
117 import org.eclipse.jdt.internal.junit.model.TestCaseElement;
118 import org.eclipse.jdt.internal.junit.model.TestElement;
119 import org.eclipse.jdt.internal.junit.model.TestRunSession;
120
121 /**
122  * A ViewPart that shows the results of a test run.
123  */

124 public class TestRunnerViewPart extends ViewPart {
125
126     public static final String JavaDoc NAME= "org.eclipse.jdt.junit.ResultView"; //$NON-NLS-1$
127

128     private static final String JavaDoc RERUN_LAST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunLast"; //$NON-NLS-1$
129
private static final String JavaDoc RERUN_FAILED_FIRST_COMMAND= "org.eclipse.jdt.junit.junitShortcut.rerunFailedFirst"; //$NON-NLS-1$
130

131     static final int REFRESH_INTERVAL= 200;
132     
133     static final int LAYOUT_FLAT= 0;
134     static final int LAYOUT_HIERARCHICAL= 1;
135     
136     /**
137      * Whether the output scrolls and reveals tests as they are executed.
138      */

139     protected boolean fAutoScroll = true;
140     /**
141      * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
142      * <code>VIEW_ORIENTATION_VERTICAL</code>, or <code>VIEW_ORIENTATION_AUTOMATIC</code>.
143      */

144     private int fOrientation= VIEW_ORIENTATION_AUTOMATIC;
145     /**
146      * The current orientation; either <code>VIEW_ORIENTATION_HORIZONTAL</code>
147      * <code>VIEW_ORIENTATION_VERTICAL</code>.
148      */

149     private int fCurrentOrientation;
150     /**
151      * The current layout mode (LAYOUT_FLAT or LAYOUT_HIERARCHICAL).
152      */

153     private int fLayout= LAYOUT_HIERARCHICAL;
154     
155 // private boolean fTestIsRunning= false;
156

157     protected JUnitProgressBar fProgressBar;
158     protected ProgressImages fProgressImages;
159     protected Image fViewImage;
160     protected CounterPanel fCounterPanel;
161     protected boolean fShowOnErrorOnly= false;
162     protected Clipboard fClipboard;
163     protected volatile String JavaDoc fInfoMessage;
164
165     private FailureTrace fFailureTrace;
166     
167     private TestViewer fTestViewer;
168     /**
169      * Is the UI disposed?
170      */

171     private boolean fIsDisposed= false;
172     
173     /**
174      * Actions
175      */

176     private Action fNextAction;
177     private Action fPreviousAction;
178     
179     private StopAction fStopAction;
180     private JUnitCopyAction fCopyAction;
181     
182     private Action fRerunLastTestAction;
183     private IHandlerActivation fRerunLastActivation;
184     private Action fRerunFailedFirstAction;
185     private IHandlerActivation fRerunFailedFirstActivation;
186     
187     private Action fFailuresOnlyFilterAction;
188     private ScrollLockAction fScrollLockAction;
189     private ToggleOrientationAction[] fToggleOrientationActions;
190     private ShowTestHierarchyAction fShowTestHierarchyAction;
191     private ActivateOnErrorAction fActivateOnErrorAction;
192     private IMenuListener fViewMenuListener;
193
194     private TestRunSession fTestRunSession;
195     private TestSessionListener fTestSessionListener;
196     
197     private RunnerViewHistory fViewHistory;
198     private TestRunSessionListener fTestRunSessionListener;
199
200     final Image fStackViewIcon= TestRunnerViewPart.createImage("eview16/stackframe.gif");//$NON-NLS-1$
201
final Image fTestRunOKIcon= TestRunnerViewPart.createImage("eview16/junitsucc.gif"); //$NON-NLS-1$
202
final Image fTestRunFailIcon= TestRunnerViewPart.createImage("eview16/juniterr.gif"); //$NON-NLS-1$
203
final Image fTestRunOKDirtyIcon= TestRunnerViewPart.createImage("eview16/junitsuccq.gif"); //$NON-NLS-1$
204
final Image fTestRunFailDirtyIcon= TestRunnerViewPart.createImage("eview16/juniterrq.gif"); //$NON-NLS-1$
205

206     final Image fTestIcon= TestRunnerViewPart.createImage("obj16/test.gif"); //$NON-NLS-1$
207
final Image fTestOkIcon= TestRunnerViewPart.createImage("obj16/testok.gif"); //$NON-NLS-1$
208
final Image fTestErrorIcon= TestRunnerViewPart.createImage("obj16/testerr.gif"); //$NON-NLS-1$
209
final Image fTestFailIcon= TestRunnerViewPart.createImage("obj16/testfail.gif"); //$NON-NLS-1$
210
final Image fTestRunningIcon= TestRunnerViewPart.createImage("obj16/testrun.gif"); //$NON-NLS-1$
211
final Image fTestIgnoredIcon= TestRunnerViewPart.createImage("obj16/testignored.gif"); //$NON-NLS-1$
212

213     final ImageDescriptor fSuiteIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuite.gif"); //$NON-NLS-1$
214
final ImageDescriptor fSuiteOkIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteok.gif"); //$NON-NLS-1$
215
final ImageDescriptor fSuiteErrorIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiteerror.gif"); //$NON-NLS-1$
216
final ImageDescriptor fSuiteFailIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuitefail.gif"); //$NON-NLS-1$
217
final ImageDescriptor fSuiteRunningIconDescriptor= JUnitPlugin.getImageDescriptor("obj16/tsuiterun.gif"); //$NON-NLS-1$
218

219     final Image fSuiteIcon= fSuiteIconDescriptor.createImage();
220     final Image fSuiteOkIcon= fSuiteOkIconDescriptor.createImage();
221     final Image fSuiteErrorIcon= fSuiteErrorIconDescriptor.createImage();
222     final Image fSuiteFailIcon= fSuiteFailIconDescriptor.createImage();
223     final Image fSuiteRunningIcon= fSuiteRunningIconDescriptor.createImage();
224     
225     // Persistence tags.
226
static final String JavaDoc TAG_PAGE= "page"; //$NON-NLS-1$
227
static final String JavaDoc TAG_RATIO= "ratio"; //$NON-NLS-1$
228
static final String JavaDoc TAG_TRACEFILTER= "tracefilter"; //$NON-NLS-1$
229
static final String JavaDoc TAG_ORIENTATION= "orientation"; //$NON-NLS-1$
230
static final String JavaDoc TAG_SCROLL= "scroll"; //$NON-NLS-1$
231
/**
232      * @since 3.2
233      */

234     static final String JavaDoc TAG_LAYOUT= "layout"; //$NON-NLS-1$
235
/**
236      * @since 3.2
237      */

238     static final String JavaDoc TAG_FAILURES_ONLY= "failuresOnly"; //$NON-NLS-1$
239

240     //orientations
241
static final int VIEW_ORIENTATION_VERTICAL= 0;
242     static final int VIEW_ORIENTATION_HORIZONTAL= 1;
243     static final int VIEW_ORIENTATION_AUTOMATIC= 2;
244     
245     private IMemento fMemento;
246
247     Image fOriginalViewImage;
248     IElementChangedListener fDirtyListener;
249     
250     
251 // private CTabFolder fTabFolder;
252
private SashForm fSashForm;
253     
254     private Composite fCounterComposite;
255     private Composite fParent;
256     
257     /**
258      * A Job that periodically updates view description, counters, and progress bar.
259      */

260     private UpdateUIJob fUpdateJob;
261     
262     /**
263      * A Job that runs as long as a test run is running.
264      * It is used to show busyness for running jobs in the view (title in italics).
265      */

266     private JUnitIsRunningJob fJUnitIsRunningJob;
267     private ILock fJUnitIsRunningLock;
268     public static final Object JavaDoc FAMILY_JUNIT_RUN = new Object JavaDoc();
269
270     private IPartListener2 fPartListener= new IPartListener2() {
271         public void partActivated(IWorkbenchPartReference ref) { }
272         public void partBroughtToTop(IWorkbenchPartReference ref) { }
273         public void partInputChanged(IWorkbenchPartReference ref) { }
274         public void partClosed(IWorkbenchPartReference ref) { }
275         public void partDeactivated(IWorkbenchPartReference ref) { }
276         public void partOpened(IWorkbenchPartReference ref) { }
277         
278         public void partVisible(IWorkbenchPartReference ref) {
279             if (getSite().getId().equals(ref.getId())) {
280                 fPartIsVisible= true;
281             }
282         }
283         
284         public void partHidden(IWorkbenchPartReference ref) {
285             if (getSite().getId().equals(ref.getId())) {
286                 fPartIsVisible= false;
287             }
288         }
289     };
290     
291     protected boolean fPartIsVisible= false;
292
293     
294     private class RunnerViewHistory extends ViewHistory {
295
296         public void configureHistoryListAction(IAction action) {
297             action.setText(JUnitMessages.TestRunnerViewPart_history);
298         }
299
300         public void configureHistoryDropDownAction(IAction action) {
301             action.setToolTipText(JUnitMessages.TestRunnerViewPart_test_run_history);
302             JUnitPlugin.setLocalImageDescriptors(action, "history_list.gif"); //$NON-NLS-1$
303
}
304         
305         public Action getClearAction() {
306             return new ClearAction();
307         }
308
309         public String JavaDoc getHistoryListDialogTitle() {
310             return JUnitMessages.TestRunnerViewPart_test_runs;
311         }
312
313         public String JavaDoc getHistoryListDialogMessage() {
314             return JUnitMessages.TestRunnerViewPart_select_test_run;
315         }
316
317         public Shell getShell() {
318             return fParent.getShell();
319         }
320
321         public List JavaDoc getHistoryEntries() {
322             return JUnitPlugin.getModel().getTestRunSessions();
323         }
324
325         public Object JavaDoc getCurrentEntry() {
326             return fTestRunSession;
327         }
328
329         public void setActiveEntry(Object JavaDoc entry) {
330             TestRunSession deactivatedSession= setActiveTestRunSession((TestRunSession) entry);
331             if (deactivatedSession != null)
332                 deactivatedSession.swapOut();
333         }
334
335         public void setHistoryEntries(List JavaDoc remainingEntries, Object JavaDoc activeEntry) {
336             setActiveTestRunSession((TestRunSession) activeEntry);
337             
338             List JavaDoc testRunSessions= JUnitPlugin.getModel().getTestRunSessions();
339             testRunSessions.removeAll(remainingEntries);
340             for (Iterator JavaDoc iter= testRunSessions.iterator(); iter.hasNext();) {
341                 JUnitPlugin.getModel().removeTestRunSession((TestRunSession) iter.next());
342             }
343             for (Iterator JavaDoc iter= remainingEntries.iterator(); iter.hasNext();) {
344                 TestRunSession remaining= (TestRunSession) iter.next();
345                 remaining.swapOut();
346             }
347         }
348
349         public ImageDescriptor getImageDescriptor(Object JavaDoc element) {
350             TestRunSession session= (TestRunSession) element;
351             if (session.isStopped())
352                 return fSuiteIconDescriptor;
353             
354             if (session.isRunning())
355                 return fSuiteRunningIconDescriptor;
356                 
357             Result result= session.getTestResult(true);
358             if (result == Result.OK)
359                 return fSuiteOkIconDescriptor;
360             else if (result == Result.ERROR)
361                 return fSuiteErrorIconDescriptor;
362             else if (result == Result.FAILURE)
363                 return fSuiteFailIconDescriptor;
364             else
365                 return fSuiteIconDescriptor;
366         }
367
368         public String JavaDoc getText(Object JavaDoc element) {
369             TestRunSession session= (TestRunSession) element;
370             if (session.getStartTime() == 0) {
371                 return session.getTestRunName();
372             } else {
373                 String JavaDoc startTime= DateFormat.getDateTimeInstance().format(new Date JavaDoc(session.getStartTime()));
374                 return Messages.format(JUnitMessages.TestRunnerViewPart_testName_startTime, new Object JavaDoc[] { session.getTestRunName(), startTime });
375             }
376         }
377         
378         public void addMenuEntries(MenuManager manager) {
379             manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new ImportTestRunSessionAction(fParent.getShell()));
380             if (fTestRunSession != null)
381                 manager.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new ExportTestRunSessionAction(fParent.getShell(), fTestRunSession));
382         }
383
384         public String JavaDoc getMaxEntriesMessage() {
385             return JUnitMessages.TestRunnerViewPart_max_remembered;
386         }
387
388         public int getMaxEntries() {
389             IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
390             return store.getInt(JUnitPreferencesConstants.MAX_TEST_RUNS);
391         }
392
393         public void setMaxEntries(int maxEntries) {
394             IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
395             store.setValue(JUnitPreferencesConstants.MAX_TEST_RUNS, maxEntries);
396         }
397     }
398     
399     private static class ImportTestRunSessionAction extends Action {
400         private final Shell fShell;
401
402         public ImportTestRunSessionAction(Shell shell) {
403             super(JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_name);
404             fShell= shell;
405         }
406         
407         public void run() {
408             FileDialog importDialog= new FileDialog(fShell, SWT.OPEN);
409             importDialog.setText(JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_title);
410             importDialog.setFilterExtensions(new String JavaDoc[] {"*.xml", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
411
String JavaDoc path= importDialog.open();
412             if (path == null)
413                 return;
414             
415             //TODO: MULTI: getFileNames()
416
File JavaDoc file= new File JavaDoc(path);
417             
418             try {
419                 JUnitModel.importTestRunSession(file);
420             } catch (CoreException e) {
421                 JUnitPlugin.log(e);
422                 ErrorDialog.openError(fShell, JUnitMessages.TestRunnerViewPart_ImportTestRunSessionAction_error_title, e.getStatus().getMessage(), e.getStatus());
423             }
424         }
425     }
426     
427     private static class ExportTestRunSessionAction extends Action {
428         private final TestRunSession fTestRunSession;
429         private final Shell fShell;
430
431         public ExportTestRunSessionAction(Shell shell, TestRunSession testRunSession) {
432             super(JUnitMessages.TestRunnerViewPart_ExportTestRunSessionAction_name);
433             fShell= shell;
434             fTestRunSession= testRunSession;
435         }
436         
437         public void run() {
438             FileDialog exportDialog= new FileDialog(fShell, SWT.SAVE);
439             exportDialog.setText(JUnitMessages.TestRunnerViewPart_ExportTestRunSessionAction_title);
440             exportDialog.setFileName(getFileName());
441             exportDialog.setFilterExtensions(new String JavaDoc[] {"*.xml", "*.*"}); //$NON-NLS-1$ //$NON-NLS-2$
442
String JavaDoc path= exportDialog.open();
443             if (path == null)
444                 return;
445             
446             //TODO: MULTI: getFileNames()
447
File JavaDoc file= new File JavaDoc(path);
448             
449             try {
450                 JUnitModel.exportTestRunSession(fTestRunSession, file);
451             } catch (CoreException e) {
452                 JUnitPlugin.log(e);
453                 ErrorDialog.openError(fShell, JUnitMessages.TestRunnerViewPart_ExportTestRunSessionAction_error_title, e.getStatus().getMessage(), e.getStatus());
454             }
455         }
456
457         private String JavaDoc getFileName() {
458             String JavaDoc testRunName= fTestRunSession.getTestRunName();
459             long startTime= fTestRunSession.getStartTime();
460             if (startTime == 0)
461                 return testRunName;
462             
463             String JavaDoc isoTime= new SimpleDateFormat JavaDoc("yyyyMMdd-HHmmss").format(new Date JavaDoc(startTime)); //$NON-NLS-1$
464
return testRunName + " " + isoTime + ".xml"; //$NON-NLS-1$ //$NON-NLS-2$
465
}
466     }
467
468     private class TestRunSessionListener implements ITestRunSessionListener {
469         public void sessionAdded(TestRunSession testRunSession) {
470             if (getSite().getWorkbenchWindow() == JUnitPlugin.getActiveWorkbenchWindow()) {
471                 TestRunSession deactivatedSession= setActiveTestRunSession(testRunSession);
472                 if (deactivatedSession != null)
473                     deactivatedSession.swapOut();
474                 String JavaDoc testRunName= fTestRunSession.getTestRunName();
475                 String JavaDoc msg;
476                 if (testRunSession.getLaunch() != null) {
477                     msg= Messages.format(JUnitMessages.TestRunnerViewPart_Launching, new Object JavaDoc[]{ testRunName });
478                 } else {
479                     msg= testRunName;
480                 }
481                 setContentDescription(msg);
482             }
483         }
484         public void sessionRemoved(TestRunSession testRunSession) {
485             if (testRunSession.equals(fTestRunSession)) {
486                 List JavaDoc testRunSessions= JUnitPlugin.getModel().getTestRunSessions();
487                 TestRunSession deactivatedSession;
488                 if (! testRunSessions.isEmpty()) {
489                     deactivatedSession= setActiveTestRunSession((TestRunSession) testRunSessions.get(0));
490                 } else {
491                     deactivatedSession= setActiveTestRunSession(null);
492                 }
493                 if (deactivatedSession != null)
494                     deactivatedSession.swapOut();
495             }
496         }
497     }
498     
499     private class TestSessionListener implements ITestSessionListener {
500         public void sessionStarted(){
501             fTestViewer.registerViewersRefresh();
502             fShowOnErrorOnly= getShowOnErrorOnly();
503             
504             startUpdateJobs();
505             
506             fStopAction.setEnabled(true);
507             fRerunLastTestAction.setEnabled(true);
508         }
509
510         public void sessionEnded(long elapsedTime){
511             fTestViewer.registerAutoScrollTarget(null);
512             
513             String JavaDoc[] keys= {elapsedTimeAsString(elapsedTime)};
514             String JavaDoc msg= Messages.format(JUnitMessages.TestRunnerViewPart_message_finish, keys);
515             registerInfoMessage(msg);
516                 
517             postSyncRunnable(new Runnable JavaDoc() {
518                 public void run() {
519                     if (isDisposed())
520                         return;
521                     fStopAction.setEnabled(lastLaunchIsKeptAlive());
522                     updateRerunFailedFirstAction();
523                     processChangesInUI();
524                     if (hasErrorsOrFailures()) {
525                         selectFirstFailure();
526                     }
527                     if (fDirtyListener == null) {
528                         fDirtyListener= new DirtyListener();
529                         JavaCore.addElementChangedListener(fDirtyListener);
530                     }
531                     warnOfContentChange();
532                 }
533             });
534             stopUpdateJobs();
535         }
536
537         public void sessionStopped(final long elapsedTime) {
538             fTestViewer.registerAutoScrollTarget(null);
539
540             registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_stopped);
541             handleStopped();
542         }
543
544         public void sessionTerminated() {
545             fTestViewer.registerAutoScrollTarget(null);
546
547             registerInfoMessage(JUnitMessages.TestRunnerViewPart_message_terminated);
548             handleStopped();
549         }
550         
551         public void runningBegins() {
552             if (!fShowOnErrorOnly)
553                 postShowTestResultsView();
554         }
555
556         public void testStarted(TestCaseElement testCaseElement) {
557             fTestViewer.registerAutoScrollTarget(testCaseElement);
558             fTestViewer.registerViewerUpdate(testCaseElement);
559
560             String JavaDoc className= testCaseElement.getClassName();
561             String JavaDoc method= testCaseElement.getTestMethodName();
562             String JavaDoc status= Messages.format(JUnitMessages.TestRunnerViewPart_message_started, new String JavaDoc[] { className, method });
563             registerInfoMessage(status);
564         }
565
566         public void testFailed(TestElement testElement, TestElement.Status status, String JavaDoc trace, String JavaDoc expected, String JavaDoc actual) {
567             if (isAutoScroll()) {
568                 fTestViewer.registerFailedForAutoScroll(testElement);
569             }
570             fTestViewer.registerViewerUpdate(testElement);
571
572             // show the view on the first error only
573
if (fShowOnErrorOnly && (getErrorsPlusFailures() == 1))
574                 postShowTestResultsView();
575             
576             //TODO:
577
// [Bug 35590] JUnit window doesn't report errors from junit.extensions.TestSetup [JUnit]
578
// when a failure occurs in test setup then no test is running
579
// to update the views we artificially signal the end of a test run
580
// if (!fTestIsRunning) {
581
// fTestIsRunning= false;
582
// testEnded(testCaseElement);
583
// }
584
}
585         
586         public void testEnded(TestCaseElement testCaseElement){
587             fTestViewer.registerViewerUpdate(testCaseElement);
588         }
589
590         public void testReran(TestCaseElement testCaseElement, TestElement.Status status, String JavaDoc trace, String JavaDoc expectedResult, String JavaDoc actualResult) {
591             fTestViewer.registerViewerUpdate(testCaseElement); //TODO: autoExpand?
592
postSyncProcessChanges();
593             showFailure(testCaseElement);
594         }
595         
596         public void testAdded(TestElement testElement) {
597             fTestViewer.registerTestAdded(testElement);
598         }
599         
600         public boolean acceptsSwapToDisk() {
601             return false;
602         }
603     }
604     
605     private class UpdateUIJob extends UIJob {
606         private boolean fRunning= true;
607         
608         public UpdateUIJob(String JavaDoc name) {
609             super(name);
610             setSystem(true);
611         }
612         public IStatus runInUIThread(IProgressMonitor monitor) {
613             if (!isDisposed()) {
614                 processChangesInUI();
615             }
616             schedule(REFRESH_INTERVAL);
617             return Status.OK_STATUS;
618         }
619         
620         public void stop() {
621             fRunning= false;
622         }
623         public boolean shouldSchedule() {
624             return fRunning;
625         }
626     }
627
628     private class JUnitIsRunningJob extends Job {
629         public JUnitIsRunningJob(String JavaDoc name) {
630             super(name);
631             setSystem(true);
632         }
633         public IStatus run(IProgressMonitor monitor) {
634             // wait until the test run terminates
635
fJUnitIsRunningLock.acquire();
636             return Status.OK_STATUS;
637         }
638         public boolean belongsTo(Object JavaDoc family) {
639             return family == TestRunnerViewPart.FAMILY_JUNIT_RUN;
640         }
641     }
642
643     private class ClearAction extends Action {
644         public ClearAction() {
645             setText(JUnitMessages.TestRunnerViewPart_clear_history_label);
646             
647             boolean enabled= false;
648             List JavaDoc testRunSessions= JUnitPlugin.getModel().getTestRunSessions();
649             for (Iterator JavaDoc iter= testRunSessions.iterator(); iter.hasNext();) {
650                 TestRunSession testRunSession= (TestRunSession) iter.next();
651                 if (! testRunSession.isRunning()) {
652                     enabled= true;
653                     break;
654                 }
655             }
656             setEnabled(enabled);
657         }
658         
659         public void run() {
660             List JavaDoc testRunSessions= getRunningSessions();
661             Object JavaDoc first= testRunSessions.isEmpty() ? null : testRunSessions.get(0);
662             fViewHistory.setHistoryEntries(testRunSessions, first);
663         }
664
665         private List JavaDoc getRunningSessions() {
666             List JavaDoc testRunSessions= JUnitPlugin.getModel().getTestRunSessions();
667             for (Iterator JavaDoc iter= testRunSessions.iterator(); iter.hasNext();) {
668                 TestRunSession testRunSession= (TestRunSession) iter.next();
669                 if (! testRunSession.isRunning()) {
670                     iter.remove();
671                 }
672             }
673             return testRunSessions;
674         }
675     }
676
677     private class StopAction extends Action {
678         public StopAction() {
679             setText(JUnitMessages.TestRunnerViewPart_stopaction_text);
680             setToolTipText(JUnitMessages.TestRunnerViewPart_stopaction_tooltip);
681             JUnitPlugin.setLocalImageDescriptors(this, "stop.gif"); //$NON-NLS-1$
682
}
683
684         public void run() {
685             stopTest();
686             setEnabled(false);
687         }
688     }
689
690     private class RerunLastAction extends Action {
691         public RerunLastAction() {
692             setText(JUnitMessages.TestRunnerViewPart_rerunaction_label);
693             setToolTipText(JUnitMessages.TestRunnerViewPart_rerunaction_tooltip);
694             JUnitPlugin.setLocalImageDescriptors(this, "relaunch.gif"); //$NON-NLS-1$
695
setEnabled(false);
696             setActionDefinitionId(RERUN_LAST_COMMAND);
697         }
698         
699         public void run(){
700             rerunTestRun();
701         }
702     }
703     
704     private class RerunLastFailedFirstAction extends Action {
705         public RerunLastFailedFirstAction() {
706             setText(JUnitMessages.TestRunnerViewPart_rerunfailuresaction_label);
707             setToolTipText(JUnitMessages.TestRunnerViewPart_rerunfailuresaction_tooltip);
708             JUnitPlugin.setLocalImageDescriptors(this, "relaunchf.gif"); //$NON-NLS-1$
709
setEnabled(false);
710             setActionDefinitionId(RERUN_FAILED_FIRST_COMMAND);
711         }
712         
713         public void run(){
714             rerunTestFailedFirst();
715         }
716     }
717
718     private class ToggleOrientationAction extends Action {
719         private final int fActionOrientation;
720         
721         public ToggleOrientationAction(TestRunnerViewPart v, int orientation) {
722             super("", AS_RADIO_BUTTON); //$NON-NLS-1$
723
if (orientation == TestRunnerViewPart.VIEW_ORIENTATION_HORIZONTAL) {
724                 setText(JUnitMessages.TestRunnerViewPart_toggle_horizontal_label);
725                 setImageDescriptor(JUnitPlugin.getImageDescriptor("elcl16/th_horizontal.gif")); //$NON-NLS-1$
726
} else if (orientation == TestRunnerViewPart.VIEW_ORIENTATION_VERTICAL) {
727                 setText(JUnitMessages.TestRunnerViewPart_toggle_vertical_label);
728                 setImageDescriptor(JUnitPlugin.getImageDescriptor("elcl16/th_vertical.gif")); //$NON-NLS-1$
729
} else if (orientation == TestRunnerViewPart.VIEW_ORIENTATION_AUTOMATIC) {
730                 setText(JUnitMessages.TestRunnerViewPart_toggle_automatic_label);
731                 setImageDescriptor(JUnitPlugin.getImageDescriptor("elcl16/th_automatic.gif")); //$NON-NLS-1$
732
}
733             fActionOrientation= orientation;
734             PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJUnitHelpContextIds.RESULTS_VIEW_TOGGLE_ORIENTATION_ACTION);
735         }
736         
737         public int getOrientation() {
738             return fActionOrientation;
739         }
740         
741         public void run() {
742             if (isChecked()) {
743                 fOrientation= fActionOrientation;
744                 computeOrientation();
745             }
746         }
747     }
748
749     /**
750      * Listen for for modifications to Java elements
751      */

752     private class DirtyListener implements IElementChangedListener {
753         public void elementChanged(ElementChangedEvent event) {
754             processDelta(event.getDelta());
755         }
756         
757         private boolean processDelta(IJavaElementDelta delta) {
758             int kind= delta.getKind();
759             int details= delta.getFlags();
760             int type= delta.getElement().getElementType();
761             
762             switch (type) {
763                 // Consider containers for class files.
764
case IJavaElement.JAVA_MODEL:
765                 case IJavaElement.JAVA_PROJECT:
766                 case IJavaElement.PACKAGE_FRAGMENT_ROOT:
767                 case IJavaElement.PACKAGE_FRAGMENT:
768                     // If we did something different than changing a child we flush the undo / redo stack.
769
if (kind != IJavaElementDelta.CHANGED || details != IJavaElementDelta.F_CHILDREN) {
770                         codeHasChanged();
771                         return false;
772                     }
773                     break;
774                 case IJavaElement.COMPILATION_UNIT:
775                     // if we have changed a primary working copy (e.g created, removed, ...)
776
// then we do nothing.
777
if ((details & IJavaElementDelta.F_PRIMARY_WORKING_COPY) != 0)
778                         return true;
779                     codeHasChanged();
780                     return false;
781                     
782                 case IJavaElement.CLASS_FILE:
783                     // Don't examine children of a class file but keep on examining siblings.
784
return true;
785                 default:
786                     codeHasChanged();
787                     return false;
788             }
789                 
790             IJavaElementDelta[] affectedChildren= delta.getAffectedChildren();
791             if (affectedChildren == null)
792                 return true;
793     
794             for (int i= 0; i < affectedChildren.length; i++) {
795                 if (!processDelta(affectedChildren[i]))
796                     return false;
797             }
798             return true;
799         }
800     }
801     
802     private class FailuresOnlyFilterAction extends Action {
803         public FailuresOnlyFilterAction() {
804             super(JUnitMessages.TestRunnerViewPart_show_failures_only, AS_CHECK_BOX);
805             setToolTipText(JUnitMessages.TestRunnerViewPart_show_failures_only);
806             setImageDescriptor(JUnitPlugin.getImageDescriptor("obj16/failures.gif")); //$NON-NLS-1$
807
}
808
809         public void run() {
810             setShowFailuresOnly(isChecked());
811         }
812     }
813
814     private class ShowTestHierarchyAction extends Action {
815
816         public ShowTestHierarchyAction() {
817             super(JUnitMessages.TestRunnerViewPart_hierarchical_layout, IAction.AS_CHECK_BOX);
818             setImageDescriptor(JUnitPlugin.getImageDescriptor("elcl16/hierarchicalLayout.gif")); //$NON-NLS-1$
819
}
820         
821         public void run() {
822             int mode= isChecked() ? LAYOUT_HIERARCHICAL : LAYOUT_FLAT;
823             setLayoutMode(mode);
824         }
825     }
826     
827     private class ActivateOnErrorAction extends Action {
828         public ActivateOnErrorAction() {
829             super(JUnitMessages.TestRunnerViewPart_activate_on_failure_only, IAction.AS_CHECK_BOX);
830             //setImageDescriptor(JUnitPlugin.getImageDescriptor("obj16/failures.gif")); //$NON-NLS-1$
831
update();
832         }
833         public void update() {
834             setChecked(getShowOnErrorOnly());
835         }
836         public void run() {
837             boolean checked= isChecked();
838             fShowOnErrorOnly= checked;
839             IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
840             store.setValue(JUnitPreferencesConstants.SHOW_ON_ERROR_ONLY, checked);
841         }
842     }
843     
844     public void init(IViewSite site, IMemento memento) throws PartInitException {
845         super.init(site, memento);
846         fMemento= memento;
847         IWorkbenchSiteProgressService progressService= getProgressService();
848         if (progressService != null)
849             progressService.showBusyForFamily(TestRunnerViewPart.FAMILY_JUNIT_RUN);
850     }
851     
852     private IWorkbenchSiteProgressService getProgressService() {
853         Object JavaDoc siteService= getSite().getAdapter(IWorkbenchSiteProgressService.class);
854         if (siteService != null)
855             return (IWorkbenchSiteProgressService) siteService;
856         return null;
857     }
858
859
860     public void saveState(IMemento memento) {
861         if (fSashForm == null) {
862             // part has not been created
863
if (fMemento != null) //Keep the old state;
864
memento.putMemento(fMemento);
865             return;
866         }
867         
868 // int activePage= fTabFolder.getSelectionIndex();
869
// memento.putInteger(TAG_PAGE, activePage);
870
memento.putString(TAG_SCROLL, fScrollLockAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
871
int weigths[]= fSashForm.getWeights();
872         int ratio= (weigths[0] * 1000) / (weigths[0] + weigths[1]);
873         memento.putInteger(TAG_RATIO, ratio);
874         memento.putInteger(TAG_ORIENTATION, fOrientation);
875         
876         memento.putString(TAG_FAILURES_ONLY, fFailuresOnlyFilterAction.isChecked() ? "true" : "false"); //$NON-NLS-1$ //$NON-NLS-2$
877
memento.putInteger(TAG_LAYOUT, fLayout);
878     }
879     
880     private void restoreLayoutState(IMemento memento) {
881 // Integer page= memento.getInteger(TAG_PAGE);
882
// if (page != null) {
883
// int p= page.intValue();
884
// if (p < fTestRunTabs.size()) { // tab count can decrease if a contributing plug-in is removed
885
// fTabFolder.setSelection(p);
886
// fActiveRunTab= (TestRunTab)fTestRunTabs.get(p);
887
// }
888
// }
889
Integer JavaDoc ratio= memento.getInteger(TAG_RATIO);
890         if (ratio != null)
891             fSashForm.setWeights(new int[] { ratio.intValue(), 1000 - ratio.intValue()} );
892         Integer JavaDoc orientation= memento.getInteger(TAG_ORIENTATION);
893         if (orientation != null)
894             fOrientation= orientation.intValue();
895         computeOrientation();
896         String JavaDoc scrollLock= memento.getString(TAG_SCROLL);
897         if (scrollLock != null) {
898             fScrollLockAction.setChecked(scrollLock.equals("true")); //$NON-NLS-1$
899
setAutoScroll(!fScrollLockAction.isChecked());
900         }
901         
902         Integer JavaDoc layout= memento.getInteger(TAG_LAYOUT);
903         int layoutValue= LAYOUT_HIERARCHICAL;
904         if (layout != null)
905             layoutValue= layout.intValue();
906         
907         String JavaDoc failuresOnly= memento.getString(TAG_FAILURES_ONLY);
908         boolean showFailuresOnly= false;
909         if (failuresOnly != null)
910             showFailuresOnly= failuresOnly.equals("true"); //$NON-NLS-1$
911

912         setFilterAndLayout(showFailuresOnly, layoutValue);
913     }
914     
915     /**
916      * Stops the currently running test and shuts down the RemoteTestRunner
917      */

918     public void stopTest() {
919         if (fTestRunSession != null) {
920             if (fTestRunSession.isRunning()) {
921                 setContentDescription(JUnitMessages.TestRunnerViewPart_message_stopping);
922             }
923             fTestRunSession.stopTestRun();
924         }
925     }
926
927     private void startUpdateJobs() {
928         postSyncProcessChanges();
929         
930         if (fUpdateJob != null) {
931             return;
932         }
933         fJUnitIsRunningJob= new JUnitIsRunningJob(JUnitMessages.TestRunnerViewPart_wrapperJobName);
934         fJUnitIsRunningLock= Job.getJobManager().newLock();
935         // acquire lock while a test run is running
936
// the lock is released when the test run terminates
937
// the wrapper job will wait on this lock.
938
fJUnitIsRunningLock.acquire();
939         getProgressService().schedule(fJUnitIsRunningJob);
940         
941         fUpdateJob= new UpdateUIJob(JUnitMessages.TestRunnerViewPart_jobName);
942         fUpdateJob.schedule(REFRESH_INTERVAL);
943     }
944     
945     private void stopUpdateJobs() {
946         if (fUpdateJob != null) {
947             fUpdateJob.stop();
948             fUpdateJob= null;
949         }
950         if (fJUnitIsRunningJob != null && fJUnitIsRunningLock != null) {
951             fJUnitIsRunningLock.release();
952             fJUnitIsRunningJob= null;
953         }
954         postSyncProcessChanges();
955     }
956     
957     private void processChangesInUI() {
958         if (fSashForm.isDisposed())
959             return;
960         
961         doShowInfoMessage();
962         refreshCounters();
963         
964         if (! fPartIsVisible)
965             updateViewTitleProgress();
966         else {
967             updateViewIcon();
968         }
969         boolean hasErrorsOrFailures= hasErrorsOrFailures();
970         fNextAction.setEnabled(hasErrorsOrFailures);
971         fPreviousAction.setEnabled(hasErrorsOrFailures);
972         
973         fTestViewer.processChangesInUI();
974     }
975     
976     /**
977      * Stops the currently running test and shuts down the RemoteTestRunner
978      */

979     public void rerunTestRun() {
980         if (lastLaunchIsKeptAlive()) {
981             // prompt for terminating the existing run
982
if (MessageDialog.openQuestion(getSite().getShell(), JUnitMessages.TestRunnerViewPart_terminate_title, JUnitMessages.TestRunnerViewPart_terminate_message)) {
983                 stopTest(); // TODO: wait for termination
984
}
985         }
986         
987         if (fTestRunSession == null)
988             return;
989         ILaunch launch= fTestRunSession.getLaunch();
990         if (launch == null)
991             return;
992         ILaunchConfiguration launchConfiguration= launch.getLaunchConfiguration();
993         if (launchConfiguration == null)
994             return;
995         
996         ILaunchConfiguration configuration= prepareLaunchConfigForRelaunch(launchConfiguration);
997         DebugUITools.launch(configuration, launch.getLaunchMode());
998     }
999
1000    private ILaunchConfiguration prepareLaunchConfigForRelaunch(ILaunchConfiguration configuration) {
1001        try {
1002            String JavaDoc attribute= configuration.getAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, ""); //$NON-NLS-1$
1003
if (attribute.length() != 0) {
1004                String JavaDoc configName= Messages.format(JUnitMessages.TestRunnerViewPart_configName, configuration.getName());
1005                ILaunchConfigurationWorkingCopy tmp= configuration.copy(configName);
1006                tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, ""); //$NON-NLS-1$
1007
return tmp;
1008            }
1009        } catch (CoreException e) {
1010            // fall through
1011
}
1012        return configuration;
1013    }
1014
1015    public void rerunTestFailedFirst() {
1016        if (lastLaunchIsKeptAlive()) {
1017            // prompt for terminating the existing run
1018
if (MessageDialog.openQuestion(getSite().getShell(), JUnitMessages.TestRunnerViewPart_terminate_title, JUnitMessages.TestRunnerViewPart_terminate_message)) {
1019                if (fTestRunSession != null)
1020                    fTestRunSession.stopTestRun();
1021            }
1022        }
1023        ILaunch launch= fTestRunSession.getLaunch();
1024        if (launch != null && launch.getLaunchConfiguration() != null) {
1025                ILaunchConfiguration launchConfiguration= launch.getLaunchConfiguration();
1026                if (launchConfiguration != null) {
1027                    try {
1028                        String JavaDoc oldName= launchConfiguration.getName();
1029                        String JavaDoc oldFailuresFilename= launchConfiguration.getAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, (String JavaDoc) null);
1030                        String JavaDoc configName;
1031                        if (oldFailuresFilename != null) {
1032                            configName= oldName;
1033                        } else {
1034                            configName= Messages.format(JUnitMessages.TestRunnerViewPart_rerunFailedFirstLaunchConfigName, oldName);
1035                        }
1036                        ILaunchConfigurationWorkingCopy tmp= launchConfiguration.copy(configName);
1037                        tmp.setAttribute(JUnitLaunchConfigurationConstants.ATTR_FAILURES_NAMES, createFailureNamesFile());
1038                        tmp.launch(launch.getLaunchMode(), null);
1039                        return;
1040                    } catch (CoreException e) {
1041                        ErrorDialog.openError(getSite().getShell(),
1042                            JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
1043                        );
1044                    }
1045                }
1046                MessageDialog.openInformation(getSite().getShell(),
1047                    JUnitMessages.TestRunnerViewPart_cannotrerun_title,
1048                    JUnitMessages.TestRunnerViewPart_cannotrerurn_message
1049                );
1050        }
1051    }
1052
1053    private String JavaDoc createFailureNamesFile() throws CoreException {
1054        try {
1055            File JavaDoc file= File.createTempFile("testFailures", ".txt"); //$NON-NLS-1$ //$NON-NLS-2$
1056
file.deleteOnExit();
1057            TestElement[] failures= fTestRunSession.getAllFailedTestElements();
1058            BufferedWriter JavaDoc bw= null;
1059            try {
1060                bw= new BufferedWriter JavaDoc(new FileWriter JavaDoc(file));
1061                for (int i= 0; i < failures.length; i++) {
1062                    TestElement testElement= failures[i];
1063                    bw.write(testElement.getTestName());
1064                    bw.newLine();
1065                }
1066            } finally {
1067                if (bw != null) {
1068                    bw.close();
1069                }
1070            }
1071            return file.getAbsolutePath();
1072        } catch (IOException JavaDoc e) {
1073            throw new CoreException(new Status(IStatus.ERROR, JUnitPlugin.PLUGIN_ID, IStatus.ERROR, "", e)); //$NON-NLS-1$
1074
}
1075    }
1076
1077    public void setAutoScroll(boolean scroll) {
1078        fAutoScroll = scroll;
1079    }
1080    
1081    public boolean isAutoScroll() {
1082        return fAutoScroll;
1083    }
1084    
1085    public void selectNextFailure() {
1086        fTestViewer.selectFailure(true);
1087    }
1088    
1089    public void selectPreviousFailure() {
1090        fTestViewer.selectFailure(false);
1091    }
1092
1093    protected void selectFirstFailure() {
1094        fTestViewer.selectFirstFailure();
1095    }
1096
1097    private boolean hasErrorsOrFailures() {
1098        return getErrorsPlusFailures() > 0;
1099    }
1100
1101    private int getErrorsPlusFailures() {
1102        if (fTestRunSession == null)
1103            return 0;
1104        else
1105            return fTestRunSession.getErrorCount() + fTestRunSession.getFailureCount();
1106    }
1107    
1108    private String JavaDoc elapsedTimeAsString(long runTime) {
1109        return NumberFormat.getInstance().format((double)runTime/1000);
1110    }
1111
1112    private void handleStopped() {
1113        postSyncRunnable(new Runnable JavaDoc() {
1114            public void run() {
1115                if (isDisposed())
1116                    return;
1117                resetViewIcon();
1118                fStopAction.setEnabled(false);
1119                updateRerunFailedFirstAction();
1120            }
1121        });
1122        stopUpdateJobs();
1123    }
1124
1125    private void resetViewIcon() {
1126        fViewImage= fOriginalViewImage;
1127        firePropertyChange(IWorkbenchPart.PROP_TITLE);
1128    }
1129
1130    private void updateViewIcon() {
1131        if (fTestRunSession == null || fTestRunSession.isStopped() || fTestRunSession.isRunning() || fTestRunSession.getStartedCount() == 0)
1132            fViewImage= fOriginalViewImage;
1133        else if (hasErrorsOrFailures())
1134            fViewImage= fTestRunFailIcon;
1135        else
1136            fViewImage= fTestRunOKIcon;
1137        firePropertyChange(IWorkbenchPart.PROP_TITLE);
1138    }
1139
1140    private void updateViewTitleProgress() {
1141        if (fTestRunSession != null) {
1142            if (fTestRunSession.isRunning()) {
1143                Image progress= fProgressImages.getImage(
1144                        fTestRunSession.getStartedCount(),
1145                        fTestRunSession.getTotalCount(),
1146                        fTestRunSession.getErrorCount(),
1147                        fTestRunSession.getFailureCount());
1148                if (progress != fViewImage) {
1149                    fViewImage= progress;
1150                    firePropertyChange(IWorkbenchPart.PROP_TITLE);
1151                }
1152            } else {
1153                updateViewIcon();
1154            }
1155        } else {
1156            resetViewIcon();
1157        }
1158    }
1159    
1160    /**
1161     * @param testRunSession new active test run session
1162     * @return deactivated session, or <code>null</code> iff no session got deactivated
1163     */

1164    private TestRunSession setActiveTestRunSession(TestRunSession testRunSession) {
1165/*
1166- State:
1167fTestRunSession
1168fTestSessionListener
1169Jobs
1170fTestViewer.processChangesInUI();
1171- UI:
1172fCounterPanel
1173fProgressBar
1174setContentDescription / fInfoMessage
1175setTitleToolTip
1176view icons
1177statusLine
1178fFailureTrace
1179
1180action enablement
1181 */

1182        if (fTestRunSession == testRunSession)
1183            return null;
1184        
1185        if (fTestRunSession != null && fTestSessionListener != null) {
1186            fTestRunSession.removeTestSessionListener(fTestSessionListener);
1187            fTestSessionListener= null;
1188        }
1189        
1190        TestRunSession deactivatedSession= fTestRunSession;
1191        
1192        fTestRunSession= testRunSession;
1193        fTestViewer.registerActiveSession(testRunSession);
1194        
1195        if (fSashForm.isDisposed()) {
1196            stopUpdateJobs();
1197            return deactivatedSession;
1198        }
1199        
1200        if (testRunSession == null) {
1201            setTitleToolTip(null);
1202            resetViewIcon();
1203            clearStatus();
1204            fFailureTrace.clear();
1205            
1206            registerInfoMessage(" "); //$NON-NLS-1$
1207
stopUpdateJobs();
1208            
1209            fStopAction.setEnabled(false);
1210            fRerunFailedFirstAction.setEnabled(false);
1211            fRerunLastTestAction.setEnabled(false);
1212            
1213        } else {
1214            fTestSessionListener= new TestSessionListener();
1215            fTestRunSession.addTestSessionListener(fTestSessionListener);
1216            
1217            setTitleToolTip();
1218                        
1219            clearStatus();
1220            fFailureTrace.clear();
1221            registerInfoMessage(fTestRunSession.getTestRunName());
1222            
1223            updateRerunFailedFirstAction();
1224            fRerunLastTestAction.setEnabled(fTestRunSession.getLaunch() != null);
1225            
1226            if (fTestRunSession.isRunning()) {
1227                startUpdateJobs();
1228                
1229                fStopAction.setEnabled(true);
1230                
1231            } else /* old or fresh session: don't want jobs at this stage */ {
1232                stopUpdateJobs();
1233                
1234                fStopAction.setEnabled(fTestRunSession.isKeptAlive());
1235                fTestViewer.expandFirstLevel();
1236            }
1237        }
1238        return deactivatedSession;
1239    }
1240
1241    private void updateRerunFailedFirstAction() {
1242        boolean state= isJUnit3() && hasErrorsOrFailures() && fTestRunSession.getLaunch() != null;
1243        fRerunFailedFirstAction.setEnabled(state);
1244    }
1245    
1246    private boolean isJUnit3() {
1247        if (fTestRunSession == null)
1248            return true; // optimistic
1249

1250        return TestKindRegistry.JUNIT3_TEST_KIND_ID.equals(fTestRunSession.getTestRunnerKind().getId());
1251    }
1252
1253    /**
1254     * @return the display name of the current test run sessions kind, or <code>null</code>
1255     */

1256    public String JavaDoc getTestKindDisplayName() {
1257        ITestKind kind= fTestRunSession.getTestRunnerKind();
1258        if (!kind.isNull()) {
1259            return kind.getDisplayName();
1260        }
1261        return null;
1262    }
1263    
1264    private void setTitleToolTip() {
1265        String JavaDoc testKindDisplayStr= getTestKindDisplayName();
1266        
1267        if (testKindDisplayStr != null)
1268            setTitleToolTip(MessageFormat.format(JUnitMessages.TestRunnerViewPart_titleToolTip, new String JavaDoc[] {fTestRunSession.getTestRunName(), testKindDisplayStr}));
1269        else
1270            setTitleToolTip(fTestRunSession.getTestRunName());
1271    }
1272    
1273    public synchronized void dispose(){
1274        fIsDisposed= true;
1275        if (fTestRunSessionListener != null)
1276            JUnitPlugin.getModel().removeTestRunSessionListener(fTestRunSessionListener);
1277        
1278        IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class);
1279        handlerService.deactivateHandler(fRerunLastActivation);
1280        handlerService.deactivateHandler(fRerunFailedFirstActivation);
1281        setActiveTestRunSession(null);
1282        
1283        if (fProgressImages != null)
1284            fProgressImages.dispose();
1285        getViewSite().getPage().removePartListener(fPartListener);
1286        
1287        disposeImages();
1288        if (fClipboard != null)
1289            fClipboard.dispose();
1290        if (fViewMenuListener != null) {
1291            getViewSite().getActionBars().getMenuManager().removeMenuListener(fViewMenuListener);
1292        }
1293    }
1294
1295    private void disposeImages() {
1296        fTestRunOKIcon.dispose();
1297        fTestRunFailIcon.dispose();
1298        fStackViewIcon.dispose();
1299        fTestRunOKDirtyIcon.dispose();
1300        fTestRunFailDirtyIcon.dispose();
1301        
1302        fTestIcon.dispose();
1303        fTestRunningIcon.dispose();
1304        fTestOkIcon.dispose();
1305        fTestErrorIcon.dispose();
1306        fTestFailIcon.dispose();
1307        fTestIgnoredIcon.dispose();
1308        
1309        fSuiteIcon.dispose();
1310        fSuiteRunningIcon.dispose();
1311        fSuiteErrorIcon.dispose();
1312        fSuiteFailIcon.dispose();
1313    }
1314
1315    private void postSyncRunnable(Runnable JavaDoc r) {
1316        if (!isDisposed())
1317            getDisplay().syncExec(r);
1318    }
1319
1320    private void refreshCounters() {
1321         // TODO: Inefficient. Either
1322
// - keep a boolean fHasTestRun and update only on changes, or
1323
// - improve components to only redraw on changes (once!).
1324

1325        int startedCount;
1326        int ignoredCount;
1327        int totalCount;
1328        int errorCount;
1329        int failureCount;
1330        boolean hasErrorsOrFailures;
1331        boolean stopped;
1332        
1333        if (fTestRunSession != null) {
1334            startedCount= fTestRunSession.getStartedCount();
1335            ignoredCount= fTestRunSession.getIgnoredCount();
1336            totalCount= fTestRunSession.getTotalCount();
1337            errorCount= fTestRunSession.getErrorCount();
1338            failureCount= fTestRunSession.getFailureCount();
1339            hasErrorsOrFailures= errorCount + failureCount > 0;
1340            stopped= fTestRunSession.isStopped();
1341        } else {
1342            startedCount= 0;
1343            ignoredCount= 0;
1344            totalCount= 0;
1345            errorCount= 0;
1346            failureCount= 0;
1347            hasErrorsOrFailures= false;
1348            stopped= false;
1349        }
1350        
1351        fCounterPanel.setTotal(totalCount);
1352        fCounterPanel.setRunValue(startedCount, ignoredCount);
1353        fCounterPanel.setErrorValue(errorCount);
1354        fCounterPanel.setFailureValue(failureCount);
1355        
1356        int ticksDone;
1357        if (startedCount == 0)
1358            ticksDone= 0;
1359        else if (startedCount == totalCount && ! fTestRunSession.isRunning())
1360            ticksDone= totalCount;
1361        else
1362            ticksDone= startedCount - 1;
1363        
1364        fProgressBar.reset(hasErrorsOrFailures, stopped, ticksDone, totalCount);
1365    }
1366    
1367    protected void postShowTestResultsView() {
1368        postSyncRunnable(new Runnable JavaDoc() {
1369            public void run() {
1370                if (isDisposed())
1371                    return;
1372                showTestResultsView();
1373            }
1374        });
1375    }
1376
1377    public void showTestResultsView() {
1378        IWorkbenchWindow window= getSite().getWorkbenchWindow();
1379        IWorkbenchPage page= window.getActivePage();
1380        TestRunnerViewPart testRunner= null;
1381        
1382        if (page != null) {
1383            try { // show the result view
1384
testRunner= (TestRunnerViewPart)page.findView(TestRunnerViewPart.NAME);
1385                if(testRunner == null) {
1386                    IWorkbenchPart activePart= page.getActivePart();
1387                    testRunner= (TestRunnerViewPart)page.showView(TestRunnerViewPart.NAME);
1388                    //restore focus
1389
page.activate(activePart);
1390                } else {
1391                    page.bringToTop(testRunner);
1392                }
1393            } catch (PartInitException pie) {
1394                JUnitPlugin.log(pie);
1395            }
1396        }
1397    }
1398    
1399    protected void doShowInfoMessage() {
1400        if (fInfoMessage != null) {
1401            setContentDescription(fInfoMessage);
1402            fInfoMessage= null;
1403        }
1404    }
1405
1406    protected void registerInfoMessage(String JavaDoc message) {
1407        fInfoMessage= message;
1408    }
1409    
1410    private SashForm createSashForm(Composite parent) {
1411        fSashForm= new SashForm(parent, SWT.VERTICAL);
1412        
1413        ViewForm top= new ViewForm(fSashForm, SWT.NONE);
1414        
1415        Composite empty= new Composite(top, SWT.NONE);
1416        empty.setLayout(new Layout() {
1417            protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
1418                return new Point(1, 1); // (0, 0) does not work with super-intelligent ViewForm
1419
}
1420            protected void layout(Composite composite, boolean flushCache) {
1421            }
1422        });
1423        top.setTopLeft(empty); // makes ViewForm draw the horizontal separator line ...
1424
fTestViewer= new TestViewer(top, fClipboard, this);
1425        top.setContent(fTestViewer.getTestViewerControl());
1426        
1427        ViewForm bottom= new ViewForm(fSashForm, SWT.NONE);
1428        
1429        CLabel label= new CLabel(bottom, SWT.NONE);
1430        label.setText(JUnitMessages.TestRunnerViewPart_label_failure);
1431        label.setImage(fStackViewIcon);
1432        bottom.setTopLeft(label);
1433        ToolBar failureToolBar= new ToolBar(bottom, SWT.FLAT | SWT.WRAP);
1434        bottom.setTopCenter(failureToolBar);
1435        fFailureTrace= new FailureTrace(bottom, fClipboard, this, failureToolBar);
1436        bottom.setContent(fFailureTrace.getComposite());
1437        
1438        fSashForm.setWeights(new int[]{50, 50});
1439        return fSashForm;
1440    }
1441
1442    private void clearStatus() {
1443        getStatusLine().setMessage(null);
1444        getStatusLine().setErrorMessage(null);
1445    }
1446    
1447    public void setFocus() {
1448        if (fTestViewer != null)
1449            fTestViewer.getTestViewerControl().setFocus();
1450    }
1451    
1452    public void createPartControl(Composite parent) {
1453        fParent= parent;
1454        addResizeListener(parent);
1455        fClipboard= new Clipboard(parent.getDisplay());
1456
1457        GridLayout gridLayout= new GridLayout();
1458        gridLayout.marginWidth= 0;
1459        gridLayout.marginHeight= 0;
1460        parent.setLayout(gridLayout);
1461        
1462        fViewHistory= new RunnerViewHistory();
1463        configureToolBar();
1464        
1465        fCounterComposite= createProgressCountPanel(parent);
1466        fCounterComposite.setLayoutData(new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
1467        SashForm sashForm= createSashForm(parent);
1468        sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
1469        
1470        IActionBars actionBars= getViewSite().getActionBars();
1471        fCopyAction = new JUnitCopyAction(fFailureTrace, fClipboard);
1472        actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), fCopyAction);
1473        
1474        fOriginalViewImage= getTitleImage();
1475        fProgressImages= new ProgressImages();
1476        PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IJUnitHelpContextIds.RESULTS_VIEW);
1477        
1478        getViewSite().getPage().addPartListener(fPartListener);
1479
1480        setFilterAndLayout(false, LAYOUT_HIERARCHICAL);
1481        if (fMemento != null) {
1482            restoreLayoutState(fMemento);
1483        }
1484        fMemento= null;
1485        
1486        fTestRunSessionListener= new TestRunSessionListener();
1487        JUnitPlugin.getModel().addTestRunSessionListener(fTestRunSessionListener);
1488    }
1489
1490    private void addResizeListener(Composite parent) {
1491        parent.addControlListener(new ControlListener() {
1492            public void controlMoved(ControlEvent e) {
1493            }
1494            public void controlResized(ControlEvent e) {
1495                computeOrientation();
1496            }
1497        });
1498    }
1499
1500    void computeOrientation() {
1501        if (fOrientation != VIEW_ORIENTATION_AUTOMATIC) {
1502            fCurrentOrientation= fOrientation;
1503            setOrientation(fCurrentOrientation);
1504        }
1505        else {
1506            Point size= fParent.getSize();
1507            if (size.x != 0 && size.y != 0) {
1508                if (size.x > size.y)
1509                    setOrientation(VIEW_ORIENTATION_HORIZONTAL);
1510                else
1511                    setOrientation(VIEW_ORIENTATION_VERTICAL);
1512            }
1513        }
1514    }
1515
1516    private void configureToolBar() {
1517        IActionBars actionBars= getViewSite().getActionBars();
1518        IToolBarManager toolBar= actionBars.getToolBarManager();
1519        IMenuManager viewMenu = actionBars.getMenuManager();
1520        
1521        fNextAction= new ShowNextFailureAction(this);
1522        fNextAction.setEnabled(false);
1523        actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNextAction);
1524        
1525        fPreviousAction= new ShowPreviousFailureAction(this);
1526        fPreviousAction.setEnabled(false);
1527        actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAction);
1528        
1529        fStopAction= new StopAction();
1530        fStopAction.setEnabled(false);
1531        
1532        fRerunLastTestAction= new RerunLastAction();
1533        IHandlerService handlerService= (IHandlerService) getSite().getWorkbenchWindow().getService(IHandlerService.class);
1534        IHandler handler = new AbstractHandler() {
1535            public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
1536                fRerunLastTestAction.run();
1537                return null;
1538            }
1539            public boolean isEnabled() {
1540                return fRerunLastTestAction.isEnabled();
1541            }
1542        };
1543        fRerunLastActivation= handlerService.activateHandler(RERUN_LAST_COMMAND, handler);
1544
1545        fRerunFailedFirstAction= new RerunLastFailedFirstAction();
1546        handler = new AbstractHandler() {
1547            public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
1548                fRerunFailedFirstAction.run();
1549                return null;
1550            }
1551            public boolean isEnabled() {
1552                return fRerunFailedFirstAction.isEnabled();
1553            }
1554        };
1555        fRerunFailedFirstActivation= handlerService.activateHandler(RERUN_FAILED_FIRST_COMMAND, handler);
1556        
1557        fFailuresOnlyFilterAction= new FailuresOnlyFilterAction();
1558        
1559        fScrollLockAction= new ScrollLockAction(this);
1560        fScrollLockAction.setChecked(!fAutoScroll);
1561        
1562        fToggleOrientationActions =
1563            new ToggleOrientationAction[] {
1564                new ToggleOrientationAction(this, VIEW_ORIENTATION_VERTICAL),
1565                new ToggleOrientationAction(this, VIEW_ORIENTATION_HORIZONTAL),
1566                new ToggleOrientationAction(this, VIEW_ORIENTATION_AUTOMATIC)};
1567        
1568        fShowTestHierarchyAction= new ShowTestHierarchyAction();
1569        
1570        toolBar.add(fNextAction);
1571        toolBar.add(fPreviousAction);
1572        toolBar.add(fFailuresOnlyFilterAction);
1573        toolBar.add(fScrollLockAction);
1574        toolBar.add(new Separator());
1575        toolBar.add(fRerunLastTestAction);
1576        toolBar.add(fRerunFailedFirstAction);
1577        toolBar.add(fStopAction);
1578        toolBar.add(fViewHistory.createHistoryDropDownAction());
1579        
1580        
1581        viewMenu.add(fShowTestHierarchyAction);
1582        viewMenu.add(new Separator());
1583        
1584        MenuManager layoutSubMenu= new MenuManager(JUnitMessages.TestRunnerViewPart_layout_menu);
1585        for (int i = 0; i < fToggleOrientationActions.length; ++i) {
1586            layoutSubMenu.add(fToggleOrientationActions[i]);
1587        }
1588        viewMenu.add(layoutSubMenu);
1589        viewMenu.add(new Separator());
1590        
1591        viewMenu.add(fFailuresOnlyFilterAction);
1592        
1593        
1594        fActivateOnErrorAction= new ActivateOnErrorAction();
1595        viewMenu.add(fActivateOnErrorAction);
1596        fViewMenuListener= new IMenuListener() {
1597            public void menuAboutToShow(IMenuManager manager) {
1598                fActivateOnErrorAction.update();
1599            }
1600        };
1601
1602        viewMenu.addMenuListener(fViewMenuListener);
1603
1604        actionBars.updateActionBars();
1605    }
1606
1607    private IStatusLineManager getStatusLine() {
1608        // we want to show messages globally hence we
1609
// have to go through the active part
1610
IViewSite site= getViewSite();
1611        IWorkbenchPage page= site.getPage();
1612        IWorkbenchPart activePart= page.getActivePart();
1613    
1614        if (activePart instanceof IViewPart) {
1615            IViewPart activeViewPart= (IViewPart)activePart;
1616            IViewSite activeViewSite= activeViewPart.getViewSite();
1617            return activeViewSite.getActionBars().getStatusLineManager();
1618        }
1619        
1620        if (activePart instanceof IEditorPart) {
1621            IEditorPart activeEditorPart= (IEditorPart)activePart;
1622            IEditorActionBarContributor contributor= activeEditorPart.getEditorSite().getActionBarContributor();
1623            if (contributor instanceof EditorActionBarContributor)
1624                return ((EditorActionBarContributor) contributor).getActionBars().getStatusLineManager();
1625        }
1626        // no active part
1627
return getViewSite().getActionBars().getStatusLineManager();
1628    }
1629
1630    protected Composite createProgressCountPanel(Composite parent) {
1631        Composite composite= new Composite(parent, SWT.NONE);
1632        GridLayout layout= new GridLayout();
1633        composite.setLayout(layout);
1634        setCounterColumns(layout);
1635        
1636        fCounterPanel = new CounterPanel(composite);
1637        fCounterPanel.setLayoutData(
1638            new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
1639        fProgressBar = new JUnitProgressBar(composite);
1640        fProgressBar.setLayoutData(
1641                new GridData(GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL));
1642        return composite;
1643    }
1644
1645    public void handleTestSelected(TestElement test) {
1646        showFailure(test);
1647        fCopyAction.handleTestSelected(test);
1648    }
1649    
1650    private void showFailure(final TestElement test) {
1651        postSyncRunnable(new Runnable JavaDoc() {
1652            public void run() {
1653                if (!isDisposed())
1654                    fFailureTrace.showFailure(test);
1655            }
1656        });
1657    }
1658
1659    /**
1660     * @return the Java project, or <code>null</code>
1661     */

1662    public IJavaProject getLaunchedProject() {
1663        return fTestRunSession == null ? null : fTestRunSession.getLaunchedProject();
1664    }
1665    
1666    public static Image createImage(String JavaDoc path) {
1667        return JUnitPlugin.getImageDescriptor(path).createImage();
1668    }
1669
1670    private boolean isDisposed() {
1671        return fIsDisposed || fCounterPanel.isDisposed();
1672    }
1673
1674    private Display getDisplay() {
1675        return getViewSite().getShell().getDisplay();
1676    }
1677    
1678    /*
1679     * @see IWorkbenchPart#getTitleImage()
1680     */

1681    public Image getTitleImage() {
1682        if (fOriginalViewImage == null)
1683            fOriginalViewImage= super.getTitleImage();
1684            
1685        if (fViewImage == null)
1686            return super.getTitleImage();
1687        return fViewImage;
1688    }
1689
1690    void codeHasChanged() {
1691        if (fDirtyListener != null) {
1692            JavaCore.removeElementChangedListener(fDirtyListener);
1693            fDirtyListener= null;
1694        }
1695        if (fViewImage == fTestRunOKIcon)
1696            fViewImage= fTestRunOKDirtyIcon;
1697        else if (fViewImage == fTestRunFailIcon)
1698            fViewImage= fTestRunFailDirtyIcon;
1699        
1700        Runnable JavaDoc r= new Runnable JavaDoc() {
1701            public void run() {
1702                if (isDisposed())
1703                    return;
1704                firePropertyChange(IWorkbenchPart.PROP_TITLE);
1705            }
1706        };
1707        if (!isDisposed())
1708            getDisplay().asyncExec(r);
1709    }
1710    
1711    public boolean isCreated() {
1712        return fCounterPanel != null;
1713    }
1714
1715    public void rerunTest(String JavaDoc testId, String JavaDoc className, String JavaDoc testName, String JavaDoc launchMode) {
1716        DebugUITools.saveAndBuildBeforeLaunch();
1717        try {
1718            boolean couldLaunch= fTestRunSession.rerunTest(testId, className, testName, launchMode);
1719            if (! couldLaunch) {
1720                MessageDialog.openInformation(getSite().getShell(),
1721                        JUnitMessages.TestRunnerViewPart_cannotrerun_title,
1722                        JUnitMessages.TestRunnerViewPart_cannotrerurn_message);
1723            } else if (fTestRunSession.isKeptAlive()) {
1724                TestCaseElement testCaseElement= (TestCaseElement) fTestRunSession.getTestElement(testId);
1725                testCaseElement.setStatus(TestElement.Status.RUNNING, null, null, null);
1726                fTestViewer.registerViewerUpdate(testCaseElement);
1727                postSyncProcessChanges();
1728            }
1729
1730        } catch (CoreException e) {
1731            ErrorDialog.openError(getSite().getShell(),
1732                JUnitMessages.TestRunnerViewPart_error_cannotrerun, e.getMessage(), e.getStatus()
1733            );
1734        }
1735    }
1736
1737    private void postSyncProcessChanges() {
1738        postSyncRunnable(new Runnable JavaDoc() {
1739            public void run() {
1740                processChangesInUI();
1741            }
1742        });
1743    }
1744
1745    public void warnOfContentChange() {
1746        IWorkbenchSiteProgressService service= getProgressService();
1747        if (service != null)
1748            service.warnOfContentChange();
1749    }
1750
1751    public boolean lastLaunchIsKeptAlive() {
1752        return fTestRunSession != null && fTestRunSession.isKeptAlive();
1753    }
1754
1755    private void setOrientation(int orientation) {
1756        if ((fSashForm == null) || fSashForm.isDisposed())
1757            return;
1758        boolean horizontal = orientation == VIEW_ORIENTATION_HORIZONTAL;
1759        fSashForm.setOrientation(horizontal ? SWT.HORIZONTAL : SWT.VERTICAL);
1760        for (int i = 0; i < fToggleOrientationActions.length; ++i)
1761            fToggleOrientationActions[i].setChecked(fOrientation == fToggleOrientationActions[i].getOrientation());
1762        fCurrentOrientation = orientation;
1763        GridLayout layout= (GridLayout) fCounterComposite.getLayout();
1764        setCounterColumns(layout);
1765        fParent.layout();
1766    }
1767
1768    private void setCounterColumns(GridLayout layout) {
1769        if (fCurrentOrientation == VIEW_ORIENTATION_HORIZONTAL)
1770            layout.numColumns= 2;
1771        else
1772            layout.numColumns= 1;
1773    }
1774
1775    private static boolean getShowOnErrorOnly() {
1776        IPreferenceStore store= JUnitPlugin.getDefault().getPreferenceStore();
1777        return store.getBoolean(JUnitPreferencesConstants.SHOW_ON_ERROR_ONLY);
1778    }
1779
1780    public FailureTrace getFailureTrace() {
1781        return fFailureTrace;
1782    }
1783    
1784    
1785    void setShowFailuresOnly(boolean failuresOnly) {
1786        setFilterAndLayout(failuresOnly, fLayout);
1787    }
1788    
1789    private void setLayoutMode(int mode) {
1790        setFilterAndLayout(fFailuresOnlyFilterAction.isChecked(), mode);
1791    }
1792    
1793    private void setFilterAndLayout(boolean failuresOnly, int layoutMode) {
1794        fShowTestHierarchyAction.setChecked(layoutMode == LAYOUT_HIERARCHICAL);
1795        fLayout= layoutMode;
1796        fFailuresOnlyFilterAction.setChecked(failuresOnly);
1797        fTestViewer.setShowFailuresOnly(failuresOnly, layoutMode);
1798    }
1799
1800    TestElement[] getAllFailures() {
1801        return fTestRunSession.getAllFailedTestElements();
1802    }
1803}
1804
Popular Tags