|
1 /* |
|
2 * Copyright (c) 2008 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 org.eclipse.core.resources.IResourceChangeEvent; |
|
21 import org.eclipse.core.resources.IResourceChangeListener; |
|
22 import org.eclipse.core.resources.ResourcesPlugin; |
|
23 import org.eclipse.core.runtime.IProgressMonitor; |
|
24 import org.eclipse.swt.SWT; |
|
25 import org.eclipse.swt.widgets.Composite; |
|
26 import org.eclipse.swt.widgets.Display; |
|
27 import org.eclipse.ui.*; |
|
28 import org.eclipse.ui.ide.FileStoreEditorInput; |
|
29 import org.eclipse.ui.part.MultiPageEditorPart; |
|
30 import com.nokia.s60tools.crashanalyser.data.ErrorLibrary; |
|
31 import com.nokia.s60tools.crashanalyser.files.*; |
|
32 import com.nokia.s60tools.crashanalyser.interfaces.*; |
|
33 import com.nokia.s60tools.crashanalyser.resources.ImageKeys; |
|
34 import com.nokia.s60tools.crashanalyser.resources.ImageResourceManager; |
|
35 import com.nokia.s60tools.crashanalyser.model.*; |
|
36 import java.io.*; |
|
37 |
|
38 /** |
|
39 * A Crash Visualiser editor. Editor contains four tab pages: |
|
40 * Crash Data, Advanced, Errors & Warnings and XML. |
|
41 * |
|
42 * Crash Data page contains summary data of the crash and crash reason |
|
43 * and description. Crash Data page also contain stack data if available. |
|
44 * |
|
45 * Advanced page contains more advanced details about the crash, such as |
|
46 * registers values, code segments, event log and cpsr details. |
|
47 * |
|
48 * Errors & Warnings page contains all error and warning messages which |
|
49 * may have occurred during the xml file creation. |
|
50 * |
|
51 * XML tab page contains the raw xml data as an xml tree. |
|
52 * |
|
53 */ |
|
54 public class MultiPageEditor extends MultiPageEditorPart implements IResourceChangeListener, |
|
55 IErrorLibraryObserver { |
|
56 // editor pages |
|
57 private SummaryPage summaryPage; |
|
58 private AdvancedPage advancedPage; |
|
59 private ErrorPage errorPage; |
|
60 private XmlPage xmlPage; |
|
61 |
|
62 // editor data consists of either crashFile or summaryFile |
|
63 private CrashFile crashFile = null; |
|
64 private SummaryFile summaryFile = null; |
|
65 |
|
66 private ErrorLibrary errorLibrary = null; |
|
67 private String crashFilePath = ""; |
|
68 static final int ERROR_PAGE_INDEX = 2; |
|
69 |
|
70 public MultiPageEditor() { |
|
71 super(); |
|
72 ResourcesPlugin.getWorkspace().addResourceChangeListener(this); |
|
73 } |
|
74 |
|
75 /** |
|
76 * Creates Crash Data page |
|
77 */ |
|
78 void createSummaryPage() { |
|
79 summaryPage = new SummaryPage(); |
|
80 |
|
81 // output.crashxml is opened via CrashAnalyser View |
|
82 if (crashFile != null) { |
|
83 int index = |
|
84 addPage(summaryPage.createPage(new Composite(getContainer(), SWT.NONE), crashFile)); |
|
85 setPageText(index, "Crash Data"); |
|
86 // Summary xml is opened via CrashAnalyser View |
|
87 } else if (summaryFile != null) { |
|
88 int index = |
|
89 addPage(summaryPage.createPage(new Composite(getContainer(), SWT.NONE), summaryFile)); |
|
90 setPageText(index, "Crash Summary"); |
|
91 // output.crashxml file opened from File > Open |
|
92 } else { |
|
93 int index = |
|
94 addPage(summaryPage.createPage(new Composite(getContainer(), SWT.NONE))); |
|
95 setPageText(index, "Crash Data"); |
|
96 } |
|
97 } |
|
98 |
|
99 /** |
|
100 * Creates advanced page |
|
101 */ |
|
102 void createAdvancedPage() { |
|
103 advancedPage = new AdvancedPage(); |
|
104 |
|
105 // output.crashxml is opened via CrashAnalyser View |
|
106 if (crashFile != null) { |
|
107 int index = addPage(advancedPage.createPage(new Composite(getContainer(), SWT.NONE), crashFile)); |
|
108 setPageText(index, "Advanced"); |
|
109 // Summary xml is opened via CrashAnalyser View |
|
110 } else if (summaryFile != null) { |
|
111 int index = addPage(advancedPage.createPage(new Composite(getContainer(), SWT.NONE), summaryFile)); |
|
112 setPageText(index, "Advanced"); |
|
113 // output.crashxml file opened from File > Open |
|
114 } else { |
|
115 int index = addPage(advancedPage.createPage(new Composite(getContainer(), SWT.NONE))); |
|
116 setPageText(index, "Advanced"); |
|
117 } |
|
118 } |
|
119 |
|
120 /** |
|
121 * Creates Errors & Warnings page |
|
122 */ |
|
123 void createErrorPage() { |
|
124 errorPage = new ErrorPage(); |
|
125 |
|
126 // output.crashxml is opened via CrashAnalyser View |
|
127 if (crashFile != null) { |
|
128 if (crashFile.containsErrorsOrWarnings()) { |
|
129 int index = addPage(errorPage.createPage(new Composite(getContainer(), SWT.NONE), crashFile)); |
|
130 setPageText(index, "Errors && Warnings"); |
|
131 } |
|
132 // Summary xml is opened via CrashAnalyser View |
|
133 } else if (summaryFile != null) { |
|
134 if (summaryFile.containsErrorsOrWarnings()) { |
|
135 int index = addPage(errorPage.createPage(new Composite(getContainer(), SWT.NONE), summaryFile)); |
|
136 setPageText(index, "Errors && Warnings"); |
|
137 } |
|
138 // output.crashxml file opened from File > Open |
|
139 } else { |
|
140 int index = addPage(errorPage.createPage(new Composite(getContainer(), SWT.NONE))); |
|
141 setPageText(index, "Errors && Warnings"); |
|
142 } |
|
143 |
|
144 } |
|
145 |
|
146 /** |
|
147 * Creates XML page |
|
148 */ |
|
149 void createXmlPage() { |
|
150 xmlPage = new XmlPage(); |
|
151 |
|
152 // output.crashxml is opened via CrashAnalyser View |
|
153 if (crashFile != null) { |
|
154 int index = addPage(xmlPage.createPage(new Composite(getContainer(), SWT.NONE), crashFile)); |
|
155 setPageText(index, "XML"); |
|
156 // Summary xml is opened via CrashAnalyser View |
|
157 } else if (summaryFile != null) { |
|
158 int index = addPage(xmlPage.createPage(new Composite(getContainer(), SWT.NONE), summaryFile)); |
|
159 setPageText(index, "XML"); |
|
160 // output.crashxml file opened from File > Open |
|
161 } else { |
|
162 int index = addPage(xmlPage.createPage(new Composite(getContainer(), SWT.NONE), crashFile)); |
|
163 setPageText(index, "XML"); |
|
164 } |
|
165 } |
|
166 |
|
167 /** |
|
168 * Creates the pages of the multi-page editor. |
|
169 */ |
|
170 protected void createPages() { |
|
171 createSummaryPage(); |
|
172 createAdvancedPage(); |
|
173 createErrorPage(); |
|
174 createXmlPage(); |
|
175 |
|
176 // output.crashxml file was opened via File > Open |
|
177 // we need to read error library and CrashFile |
|
178 if (crashFilePath != null && !"".equals(crashFilePath)) { |
|
179 errorLibrary = ErrorLibrary.getInstance(this); |
|
180 } else { |
|
181 updatePages(); |
|
182 } |
|
183 } |
|
184 |
|
185 public void errorLibraryReady() { |
|
186 Runnable refreshRunnable = new Runnable(){ |
|
187 public void run(){ |
|
188 crashFile = CrashFile.read(new File(crashFilePath), errorLibrary); |
|
189 summaryPage.setFile(crashFile); |
|
190 advancedPage.setFile(crashFile); |
|
191 if (crashFile.containsErrorsOrWarnings()) { |
|
192 errorPage.setFile(crashFile); |
|
193 } else { |
|
194 removePage(ERROR_PAGE_INDEX); |
|
195 } |
|
196 xmlPage.setFile(crashFile); |
|
197 } |
|
198 }; |
|
199 |
|
200 Display.getDefault().asyncExec(refreshRunnable); |
|
201 } |
|
202 |
|
203 public void updatePages() { |
|
204 Runnable refreshRunnable = new Runnable(){ |
|
205 public void run(){ |
|
206 summaryPage.update(); |
|
207 } |
|
208 }; |
|
209 |
|
210 Display.getDefault().asyncExec(refreshRunnable); |
|
211 } |
|
212 |
|
213 |
|
214 /** |
|
215 * The <code>MultiPageEditorPart</code> implementation of this |
|
216 * <code>IWorkbenchPart</code> method disposes all nested editors. |
|
217 * Subclasses may extend. |
|
218 */ |
|
219 public void dispose() { |
|
220 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); |
|
221 super.dispose(); |
|
222 } |
|
223 /** |
|
224 * Saves the multi-page editor's document. |
|
225 */ |
|
226 public void doSave(IProgressMonitor monitor) { |
|
227 // not supported |
|
228 } |
|
229 |
|
230 /** |
|
231 * editor's data can be saved as xml, html or txt. |
|
232 */ |
|
233 public void doSaveAs() { |
|
234 String[] filter = null; |
|
235 // we have a fully decoded file |
|
236 if (crashFile != null) { |
|
237 filter = new String[] { "*.crashxml", |
|
238 "*.html", |
|
239 "*.txt"}; |
|
240 // we have a summary file |
|
241 } else { |
|
242 filter = new String[] { "*.xml", |
|
243 "*.html", |
|
244 "*.txt"}; |
|
245 } |
|
246 String result = FileOperations.saveAsDialog("Crash Analyser - Save Crash File As", filter, getEditorSite().getShell()); |
|
247 if (result != null && result.length() > 0) { |
|
248 // crash file exists and user did not select the current crash file |
|
249 if (crashFile != null && !result.equalsIgnoreCase(crashFile.getFilePath())) |
|
250 crashFile.writeTo(new File(result)); |
|
251 // summary file exists and user did not select the current summary file |
|
252 else if (summaryFile != null && !result.equalsIgnoreCase(summaryFile.getFilePath())) |
|
253 summaryFile.writeTo(new File(result)); |
|
254 } |
|
255 } |
|
256 |
|
257 public void init(IEditorSite site, IEditorInput editorInput) |
|
258 throws PartInitException { |
|
259 |
|
260 String fileName = "Crash Analyser"; |
|
261 |
|
262 // We don't support files, must be CrashFile or SummaryFile object |
|
263 if (editorInput instanceof IFileEditorInput) { |
|
264 throw new PartInitException("Not Valid Crash Analyser File."); |
|
265 |
|
266 // CrashFile or SummaryFile |
|
267 } else { |
|
268 |
|
269 // output.crashxml file opened from Crash Analyser Main View |
|
270 if (editorInput instanceof CrashFile) { |
|
271 crashFile = (CrashFile)editorInput; |
|
272 fileName = crashFile.getFileName(); |
|
273 super.setTitleImage(ImageResourceManager.getImage(ImageKeys.DECODED_FILE)); |
|
274 |
|
275 // Summary xml file opened from Crash Analyser Main View |
|
276 } else if (editorInput instanceof SummaryFile) { |
|
277 summaryFile = (SummaryFile)editorInput; |
|
278 fileName = summaryFile.getFileName(); |
|
279 super.setTitleImage(ImageResourceManager.getImage(ImageKeys.PARTIALLY_DECODED_FILE)); |
|
280 |
|
281 // output.crashxml file opened from Carbide File menu |
|
282 } else { |
|
283 crashFilePath = ((FileStoreEditorInput)editorInput).getURI().getPath(); |
|
284 fileName = editorInput.getName(); |
|
285 super.setTitleImage(ImageResourceManager.getImage(ImageKeys.DECODED_FILE)); |
|
286 } |
|
287 } |
|
288 super.init(site, editorInput); |
|
289 super.setPartName(fileName); |
|
290 } |
|
291 |
|
292 public boolean isSaveAsAllowed() { |
|
293 return true; |
|
294 } |
|
295 |
|
296 public void resourceChanged(final IResourceChangeEvent event){ |
|
297 // nothing to be done |
|
298 } |
|
299 |
|
300 } |