|
1 /* |
|
2 * Copyright (c) 2010 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 |
|
18 package com.nokia.s60tools.crashanalyser.ui.editors; |
|
19 |
|
20 import java.util.List; |
|
21 |
|
22 import org.eclipse.jface.resource.FontRegistry; |
|
23 import org.eclipse.swt.SWT; |
|
24 import org.eclipse.swt.custom.SashForm; |
|
25 import org.eclipse.swt.graphics.FontData; |
|
26 import org.eclipse.swt.layout.GridData; |
|
27 import org.eclipse.swt.layout.GridLayout; |
|
28 import org.eclipse.swt.widgets.Composite; |
|
29 import org.eclipse.swt.widgets.Display; |
|
30 import org.eclipse.swt.widgets.Group; |
|
31 import org.eclipse.swt.widgets.Table; |
|
32 import org.eclipse.swt.widgets.TableColumn; |
|
33 import org.eclipse.swt.widgets.TableItem; |
|
34 import org.eclipse.ui.PlatformUI; |
|
35 |
|
36 import com.nokia.s60tools.crashanalyser.containers.EventLog; |
|
37 import com.nokia.s60tools.crashanalyser.containers.OstTrace; |
|
38 import com.nokia.s60tools.crashanalyser.containers.OstTraceLine; |
|
39 import com.nokia.s60tools.crashanalyser.files.CrashFile; |
|
40 import com.nokia.s60tools.crashanalyser.files.SummaryFile; |
|
41 import com.nokia.s60tools.crashanalyser.resources.HelpContextIDs; |
|
42 |
|
43 public class TracesPage { |
|
44 |
|
45 // event log group UI items |
|
46 Table tableEventLog; |
|
47 |
|
48 // OST traces group UI items |
|
49 Table tableOstTraces; |
|
50 |
|
51 FontRegistry fontRegistry; |
|
52 SummaryFile crashFile; |
|
53 |
|
54 /** |
|
55 * Creates the page |
|
56 * @param parent composite |
|
57 * @param file summary file |
|
58 * @return composite |
|
59 */ |
|
60 public Composite createPage(Composite parent, SummaryFile file) { |
|
61 crashFile = file; |
|
62 return doCreatePage(parent); |
|
63 } |
|
64 |
|
65 /** |
|
66 * Creates the page |
|
67 * @param parent composite |
|
68 * @return composite |
|
69 */ |
|
70 public Composite createPage(Composite parent) { |
|
71 return doCreatePage(parent); |
|
72 } |
|
73 |
|
74 /** |
|
75 * Loads data from given file into UI elements. |
|
76 * @param file crash file |
|
77 */ |
|
78 public void setFile(CrashFile file) { |
|
79 if (file != null) { |
|
80 crashFile = file; |
|
81 loadEventLogTable(); |
|
82 } |
|
83 } |
|
84 |
|
85 /** |
|
86 * Creates all UI elements to the page |
|
87 * @param parent |
|
88 * @return composite |
|
89 */ |
|
90 Composite doCreatePage(Composite parent) { |
|
91 GridLayout layout = new GridLayout(); |
|
92 layout.numColumns = 1; |
|
93 parent.setLayout(layout); |
|
94 parent.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
95 |
|
96 fontRegistry = new FontRegistry(Display.getCurrent()); |
|
97 fontRegistry.put("monospace", new FontData[]{new FontData("Courier", 8, SWT.NORMAL)}); |
|
98 |
|
99 SashForm sashFormMain = new SashForm(parent, SWT.VERTICAL); |
|
100 sashFormMain.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
101 createOstTracesGroup(sashFormMain); |
|
102 createEventLogGroup(sashFormMain); |
|
103 |
|
104 setHelps(); |
|
105 |
|
106 return parent; |
|
107 } |
|
108 |
|
109 /** |
|
110 * Creates event log group |
|
111 * @param parent |
|
112 */ |
|
113 void createEventLogGroup(Composite parent) { |
|
114 Group groupEventLog = new Group(parent, SWT.NONE); |
|
115 GridLayout layout = new GridLayout(); |
|
116 layout.numColumns = 1; |
|
117 groupEventLog.setLayout(layout); |
|
118 groupEventLog.setText("Event Log (latest events on top)"); |
|
119 GridData groupGD = new GridData(GridData.FILL_BOTH); |
|
120 groupEventLog.setLayoutData(groupGD); |
|
121 |
|
122 tableEventLog = new Table(groupEventLog, SWT.BORDER); |
|
123 tableEventLog.setHeaderVisible(true); |
|
124 TableColumn col = new TableColumn(tableEventLog, SWT.LEFT); |
|
125 col.setWidth(200); |
|
126 col.setText("Type"); |
|
127 col = new TableColumn(tableEventLog, SWT.LEFT); |
|
128 col.setWidth(200); |
|
129 col.setText("Value"); |
|
130 tableEventLog.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
131 tableEventLog.setFont(fontRegistry.get("monospace")); |
|
132 |
|
133 loadEventLogTable(); |
|
134 } |
|
135 |
|
136 /** |
|
137 * Creates OST traces group |
|
138 * @param parent |
|
139 */ |
|
140 void createOstTracesGroup(Composite parent) { |
|
141 Group groupOstTraces = new Group(parent, SWT.NONE); |
|
142 GridLayout layout = new GridLayout(); |
|
143 layout.numColumns = 1; |
|
144 groupOstTraces.setLayout(layout); |
|
145 groupOstTraces.setText("OST Traces"); |
|
146 GridData groupGD = new GridData(GridData.FILL_BOTH); |
|
147 groupOstTraces.setLayoutData(groupGD); |
|
148 |
|
149 tableOstTraces = new Table(groupOstTraces, SWT.BORDER); |
|
150 tableOstTraces.setHeaderVisible(true); |
|
151 TableColumn col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
152 col.setWidth(90); |
|
153 col.setText("Timestamp"); |
|
154 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
155 col.setWidth(600); |
|
156 col.setText("Text"); |
|
157 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
158 col.setWidth(200); |
|
159 col.setText("File"); |
|
160 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
161 col.setWidth(50); |
|
162 col.setText("Line"); |
|
163 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
164 col.setWidth(100); |
|
165 col.setText("Type"); |
|
166 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
167 col.setWidth(50); |
|
168 col.setText("Context ID"); |
|
169 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
170 col.setWidth(100); |
|
171 col.setText("Prefix"); |
|
172 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
173 col.setWidth(50); |
|
174 col.setText("Component"); |
|
175 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
176 col.setWidth(50); |
|
177 col.setText("Group"); |
|
178 col = new TableColumn(tableOstTraces, SWT.LEFT); |
|
179 col.setWidth(50); |
|
180 col.setText("ID"); |
|
181 |
|
182 tableOstTraces.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
183 tableOstTraces.setFont(fontRegistry.get("monospace")); |
|
184 |
|
185 loadOstTracesTable(); |
|
186 } |
|
187 |
|
188 /** |
|
189 * Loads all event log events to table |
|
190 */ |
|
191 void loadEventLogTable() { |
|
192 if (crashFile == null) |
|
193 return; |
|
194 |
|
195 EventLog eventLog = crashFile.getEventLog(); |
|
196 if (eventLog != null) { |
|
197 List<String[]> events = eventLog.getLogEvents(); |
|
198 if (events != null && !events.isEmpty()) { |
|
199 for (int i = 0; i < events.size(); i++) { |
|
200 String[] event = events.get(i); |
|
201 newEventTableItem(event[0], event[1]); |
|
202 } |
|
203 AutoSizeTableCells(tableEventLog); |
|
204 } |
|
205 } |
|
206 } |
|
207 |
|
208 /** |
|
209 * Loads all OST traces to table |
|
210 */ |
|
211 void loadOstTracesTable() { |
|
212 if (crashFile == null) |
|
213 return; |
|
214 |
|
215 OstTrace ostTrace = crashFile.getOstTrace(); |
|
216 |
|
217 if(ostTrace == null || ostTrace.getTraces() == null || ostTrace.getTraces().size() == 0) { |
|
218 newOstTableItem("", "No traces available. Set output traces to Mobile Crash in TraceSwitch tool to enable traces.", "", "", "", "", "", "", "", ""); |
|
219 } |
|
220 |
|
221 if (ostTrace != null) { |
|
222 for(OstTraceLine traceLine : ostTrace.getTraces()) { |
|
223 newOstTableItem(traceLine.getTimestamp(), traceLine.getTraceText(), |
|
224 traceLine.getFile(), traceLine.getLineNumber(), traceLine.getType(), |
|
225 traceLine.getContextId(), traceLine.getPrefix(), |
|
226 traceLine.getComponent(), traceLine.getGroup(), traceLine.getId()); |
|
227 } |
|
228 AutoSizeTableCells(tableOstTraces); |
|
229 } |
|
230 } |
|
231 |
|
232 |
|
233 |
|
234 /** |
|
235 * Adds a new table row for event log table |
|
236 * @param header header text |
|
237 * @param value value text |
|
238 */ |
|
239 void newEventTableItem(String header, String value) { |
|
240 TableItem item = new TableItem(tableEventLog, SWT.NONE); |
|
241 item.setText(new String[] {header, value}); |
|
242 } |
|
243 |
|
244 /** |
|
245 * Adds a new table row for event log table |
|
246 * @param header header text |
|
247 * @param value value text |
|
248 */ |
|
249 void newOstTableItem(String timestamp, String text, String file, String line, String type, String contextId, String prefix, String component, String group, String id) { |
|
250 TableItem item = new TableItem(tableOstTraces, SWT.NONE); |
|
251 item.setText(new String[] {timestamp, text, file, line, type, contextId, prefix, component, group, id}); |
|
252 } |
|
253 |
|
254 /** |
|
255 * Packs all columns for given table |
|
256 * @param table table which columns are to be packed |
|
257 */ |
|
258 void AutoSizeTableCells(Table table) { |
|
259 for (int i = 0; i < table.getColumnCount(); i++) { |
|
260 table.getColumn(i).pack(); |
|
261 } |
|
262 } |
|
263 |
|
264 /** |
|
265 * Sets context sensitive help ids to UI elements |
|
266 */ |
|
267 void setHelps() { |
|
268 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableEventLog, |
|
269 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
270 } |
|
271 |
|
272 } |