|
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 package com.nokia.s60tools.crashanalyser.ui.editors; |
|
18 |
|
19 import java.util.List; |
|
20 |
|
21 import org.eclipse.jface.resource.FontRegistry; |
|
22 import org.eclipse.swt.SWT; |
|
23 import org.eclipse.swt.custom.SashForm; |
|
24 import org.eclipse.swt.graphics.FontData; |
|
25 import org.eclipse.swt.layout.GridData; |
|
26 import org.eclipse.swt.layout.GridLayout; |
|
27 import org.eclipse.swt.widgets.Composite; |
|
28 import org.eclipse.swt.widgets.Display; |
|
29 import org.eclipse.swt.widgets.Group; |
|
30 import org.eclipse.swt.widgets.Table; |
|
31 import org.eclipse.swt.widgets.TableItem; |
|
32 import org.eclipse.ui.PlatformUI; |
|
33 |
|
34 import com.nokia.s60tools.crashanalyser.containers.CodeSegment; |
|
35 import com.nokia.s60tools.crashanalyser.containers.Process; |
|
36 //import com.nokia.s60tools.crashanalyser.containers.Thread; |
|
37 import com.nokia.s60tools.crashanalyser.files.CrashFile; |
|
38 import com.nokia.s60tools.crashanalyser.files.SummaryFile; |
|
39 import com.nokia.s60tools.crashanalyser.resources.HelpContextIDs; |
|
40 import com.nokia.s60tools.crashanalyser.ui.viewers.CodeSegmentsTableViewer; |
|
41 |
|
42 public class CodesegmentsPage { |
|
43 |
|
44 // code segments group UI items |
|
45 Table tableCodeSegments; |
|
46 CodeSegmentsTableViewer tableViewerCodeSegments; |
|
47 |
|
48 FontRegistry fontRegistry; |
|
49 SummaryFile crashFile; |
|
50 Process selectedProcess = null; |
|
51 // Thread selectedThread = null; |
|
52 |
|
53 /** |
|
54 * Creates the page |
|
55 * @param parent composite |
|
56 * @param file summary file |
|
57 * @return composite |
|
58 */ |
|
59 public Composite createPage(Composite parent, SummaryFile file) { |
|
60 crashFile = file; |
|
61 return doCreatePage(parent); |
|
62 } |
|
63 |
|
64 /** |
|
65 * Creates the page |
|
66 * @param parent composite |
|
67 * @return composite |
|
68 */ |
|
69 public Composite createPage(Composite parent) { |
|
70 return doCreatePage(parent); |
|
71 } |
|
72 |
|
73 /** |
|
74 * Loads data from given file into UI elements. |
|
75 * @param file crash file |
|
76 */ |
|
77 public void setFile(CrashFile file) { |
|
78 if (file != null) { |
|
79 crashFile = file; |
|
80 // initialUserRegistersTableLoad(); |
|
81 loadCodeSegmentsTable(); |
|
82 // loadEventLogTable(); |
|
83 // initialCpsrDetailsTableLoad(); |
|
84 } |
|
85 } |
|
86 |
|
87 /** |
|
88 * Creates all UI elements to the page |
|
89 * @param parent |
|
90 * @return composite |
|
91 */ |
|
92 Composite doCreatePage(Composite parent) { |
|
93 GridLayout layout = new GridLayout(); |
|
94 layout.numColumns = 1; |
|
95 parent.setLayout(layout); |
|
96 parent.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
97 |
|
98 fontRegistry = new FontRegistry(Display.getCurrent()); |
|
99 fontRegistry.put("monospace", new FontData[]{new FontData("Courier", 8, SWT.NORMAL)}); |
|
100 |
|
101 SashForm sashFormMain = new SashForm(parent, SWT.VERTICAL); |
|
102 sashFormMain.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
103 createCodeSegmentsGroup(sashFormMain); |
|
104 |
|
105 /* |
|
106 SashForm sashFormTop = new SashForm(sashFormMain, SWT.HORIZONTAL); |
|
107 createRegistersGroup(sashFormTop); |
|
108 createCodeSegmentsGroup(sashFormTop); |
|
109 SashForm sashFormBottom = new SashForm(sashFormMain, SWT.HORIZONTAL); |
|
110 createEventLogGroup(sashFormBottom); |
|
111 createCpsrDetailsGroup(sashFormBottom); |
|
112 |
|
113 sashFormTop.setWeights(new int[]{3,2}); |
|
114 sashFormBottom.setWeights(new int[]{3,7}); |
|
115 */ |
|
116 setHelps(); |
|
117 |
|
118 return parent; |
|
119 } |
|
120 |
|
121 |
|
122 /** |
|
123 * Creates code segments group |
|
124 * @param parent |
|
125 */ |
|
126 void createCodeSegmentsGroup(Composite parent) { |
|
127 Group groupCodeSegments = new Group(parent, SWT.NONE); |
|
128 GridLayout layout = new GridLayout(); |
|
129 layout.numColumns = 1; |
|
130 groupCodeSegments.setLayout(layout); |
|
131 groupCodeSegments.setText("Code Segments"); |
|
132 GridData groupGD = new GridData(); |
|
133 groupCodeSegments.setLayoutData(groupGD); |
|
134 |
|
135 tableCodeSegments = new Table(groupCodeSegments, SWT.BORDER); |
|
136 tableCodeSegments.setHeaderVisible(true); |
|
137 GridData tableGd = new GridData(GridData.FILL_BOTH); |
|
138 tableCodeSegments.setLayoutData(tableGd); |
|
139 |
|
140 tableViewerCodeSegments = new CodeSegmentsTableViewer(tableCodeSegments); |
|
141 tableCodeSegments.setFont(fontRegistry.get("monospace")); |
|
142 |
|
143 loadCodeSegmentsTable(); |
|
144 AutoSizeTableCells(tableCodeSegments); |
|
145 |
|
146 } |
|
147 |
|
148 /** |
|
149 * Loads code segments to table |
|
150 */ |
|
151 void loadCodeSegmentsTable() { |
|
152 if (crashFile == null) { |
|
153 return; |
|
154 } |
|
155 |
|
156 if (crashFile.getThread() != null) { |
|
157 selectedProcess = crashFile.getProcessByThread(crashFile.getThread().getId()); |
|
158 } else { |
|
159 selectedProcess = crashFile.getCrashedProcess(); |
|
160 } |
|
161 |
|
162 if (selectedProcess == null) |
|
163 return; |
|
164 |
|
165 List<CodeSegment> codeSegments = selectedProcess.getCodeSegments(); |
|
166 if (codeSegments != null && !codeSegments.isEmpty()) { |
|
167 for (int i = 0; i < codeSegments.size(); i++) { |
|
168 CodeSegment codeSegment = codeSegments.get(i); |
|
169 newCodeSegmentsTableItem(codeSegment); |
|
170 } |
|
171 } |
|
172 |
|
173 AutoSizeTableCells(tableCodeSegments); |
|
174 } |
|
175 |
|
176 /** |
|
177 * Adds a new table row for code segments table |
|
178 * @param codeSegment |
|
179 */ |
|
180 void newCodeSegmentsTableItem(CodeSegment codeSegment) { |
|
181 TableItem item = new TableItem(tableCodeSegments, SWT.NONE); |
|
182 String segmentRange = codeSegment.getSegmentRange(); |
|
183 String base = ""; |
|
184 String top = ""; |
|
185 try { |
|
186 // segment range is of format: XXXXX-YYYYY, parse this to XXXXX and YYYYY |
|
187 if (segmentRange.contains("-")) { |
|
188 top = segmentRange.substring(segmentRange.indexOf('-')+1); |
|
189 base = segmentRange.substring(0, segmentRange.indexOf('-')); |
|
190 } |
|
191 } catch (Exception e) { |
|
192 e.printStackTrace(); |
|
193 } |
|
194 item.setText(new String[] {base, top, codeSegment.getSegmentName()}); |
|
195 |
|
196 // code segment should be highlighted if there was some problem with the code section |
|
197 // while creating data |
|
198 if (codeSegment.shouldBeHighlighted()) { |
|
199 item.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_MAGENTA)); |
|
200 } |
|
201 item.setData(codeSegment); |
|
202 } |
|
203 |
|
204 /** |
|
205 * Packs all columns for given table |
|
206 * @param table table which columns are to be packed |
|
207 */ |
|
208 void AutoSizeTableCells(Table table) { |
|
209 for (int i = 0; i < table.getColumnCount(); i++) { |
|
210 table.getColumn(i).pack(); |
|
211 } |
|
212 } |
|
213 |
|
214 /** |
|
215 * Sets context sensitive help ids to UI elements |
|
216 */ |
|
217 void setHelps() { |
|
218 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableCodeSegments, |
|
219 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
220 /* |
|
221 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableCpsrDetails, |
|
222 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
223 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableEventLog, |
|
224 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
225 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableRegisters, |
|
226 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
227 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableEventLog, |
|
228 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
229 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableRegisters, |
|
230 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
231 PlatformUI.getWorkbench().getHelpSystem().setHelp(comboCpsrDetails, |
|
232 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
233 PlatformUI.getWorkbench().getHelpSystem().setHelp(comboRegisters, |
|
234 HelpContextIDs.CRASH_ANALYSER_HELP_CRASH_VISUALISER); |
|
235 */ |
|
236 } |
|
237 |
|
238 } |