|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.testfw.resultview.view; |
|
18 |
|
19 import org.eclipse.swt.SWT; |
|
20 import org.eclipse.swt.widgets.Composite; |
|
21 import org.eclipse.swt.widgets.Shell; |
|
22 import org.eclipse.swt.widgets.Table; |
|
23 import org.eclipse.swt.widgets.TableItem; |
|
24 |
|
25 import com.nokia.testfw.core.model.result.TestResult; |
|
26 |
|
27 /** |
|
28 * A pane that shows a stack trace of a failed test. |
|
29 */ |
|
30 public class FailureTrace { |
|
31 private Table iTable; |
|
32 private TestResult iResult; |
|
33 |
|
34 public FailureTrace(Composite parent) { |
|
35 |
|
36 iTable = new Table(parent, SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); |
|
37 } |
|
38 |
|
39 /** |
|
40 * Returns the composite used to present the trace |
|
41 * |
|
42 * @return The composite |
|
43 */ |
|
44 public Table getTable() { |
|
45 return iTable; |
|
46 } |
|
47 |
|
48 public void setTestResult(TestResult result) { |
|
49 iResult = result; |
|
50 updateTable(); |
|
51 } |
|
52 |
|
53 public TestResult getTestResult() { |
|
54 return iResult; |
|
55 } |
|
56 |
|
57 /** |
|
58 * Refresh the table from the trace. |
|
59 */ |
|
60 public boolean update(TestResult result) { |
|
61 if (iResult != result) |
|
62 return false; |
|
63 updateTable(); |
|
64 return true; |
|
65 } |
|
66 |
|
67 private void updateTable() { |
|
68 iTable.removeAll(); |
|
69 if (iResult == null) { |
|
70 return; |
|
71 } |
|
72 String trace = iResult.getMessage(); |
|
73 if (trace == null || trace.trim().equals("")) { //$NON-NLS-1$ |
|
74 return; |
|
75 } |
|
76 trace = trace.trim(); |
|
77 StringBuilder location = new StringBuilder(); |
|
78 if (iResult.getFile() != null) { |
|
79 location.append(iResult.getFile()); |
|
80 if (iResult.getLine() > -1) { |
|
81 location.append("(").append(iResult.getLine()).append(")"); |
|
82 } |
|
83 } |
|
84 iTable.setRedraw(false); |
|
85 if (trace.length() > 0) { |
|
86 TableItem item = new TableItem(iTable, SWT.None); |
|
87 item.setText("Reason:"); |
|
88 item = new TableItem(iTable, SWT.None); |
|
89 item.setForeground(getShell().getDisplay().getSystemColor( |
|
90 SWT.COLOR_RED)); |
|
91 item.setText(" " + trace); |
|
92 } |
|
93 if (location.length() > 0) { |
|
94 TableItem item = new TableItem(iTable, SWT.None); |
|
95 item.setText("Location:"); |
|
96 item = new TableItem(iTable, SWT.None); |
|
97 item.setForeground(getShell().getDisplay().getSystemColor( |
|
98 SWT.COLOR_BLUE)); |
|
99 item.setText(" " + location.toString()); |
|
100 } |
|
101 iTable.setRedraw(true); |
|
102 } |
|
103 |
|
104 public Shell getShell() { |
|
105 return iTable.getShell(); |
|
106 } |
|
107 } |