|
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.s60tools.swmtanalyser.ui.actions; |
|
18 |
|
19 import java.lang.reflect.InvocationTargetException; |
|
20 import java.util.ArrayList; |
|
21 |
|
22 import org.eclipse.core.runtime.IProgressMonitor; |
|
23 import org.eclipse.jface.dialogs.MessageDialog; |
|
24 import org.eclipse.jface.dialogs.ProgressMonitorDialog; |
|
25 import org.eclipse.jface.operation.IRunnableWithProgress; |
|
26 import org.eclipse.swt.widgets.Display; |
|
27 import org.eclipse.swt.widgets.Shell; |
|
28 import org.eclipse.ui.IEditorDescriptor; |
|
29 import org.eclipse.ui.IWorkbench; |
|
30 import org.eclipse.ui.IWorkbenchPage; |
|
31 import org.eclipse.ui.IWorkbenchWindow; |
|
32 import org.eclipse.ui.PartInitException; |
|
33 import org.eclipse.ui.PlatformUI; |
|
34 |
|
35 import com.nokia.s60tools.swmtanalyser.SwmtAnalyserPlugin; |
|
36 import com.nokia.s60tools.swmtanalyser.data.CycleData; |
|
37 import com.nokia.s60tools.swmtanalyser.data.OverviewData; |
|
38 import com.nokia.s60tools.swmtanalyser.data.ParsedData; |
|
39 import com.nokia.s60tools.swmtanalyser.editors.SWMTEditorInput; |
|
40 import com.nokia.s60tools.swmtanalyser.exception.SwmtFormatException; |
|
41 import com.nokia.s60tools.swmtanalyser.model.SWMTLogReaderUtils; |
|
42 import com.nokia.s60tools.swmtanalyser.model.SwmtParser; |
|
43 import com.nokia.s60tools.util.console.IConsolePrintUtility; |
|
44 |
|
45 /** |
|
46 * Interface to start analysis. |
|
47 * |
|
48 */ |
|
49 public class SwmtAnalyser { |
|
50 |
|
51 private static final String SWMT_EDITOR_ID = "com.nokia.s60tools.swmtanalyser.editors.SWMTEditor"; |
|
52 private ArrayList<String> inputs; |
|
53 private ArrayList<CycleData> cycleData; |
|
54 private String status = null; |
|
55 private boolean isCancelled; |
|
56 private SWMTLogReaderUtils logReader = new SWMTLogReaderUtils(); |
|
57 private String parserError; |
|
58 |
|
59 /** |
|
60 * Construction for creating SWMT Analyser to editor area. |
|
61 * @param console |
|
62 */ |
|
63 public SwmtAnalyser(IConsolePrintUtility console) { |
|
64 SwmtAnalyserPlugin.getDefault().setConsole(console); |
|
65 } |
|
66 |
|
67 /** |
|
68 * Analyse given logs files. |
|
69 * @param swmtFiles list of swmt log files to be analysed |
|
70 */ |
|
71 public void analyse(ArrayList<String> swmtFilePaths) |
|
72 { |
|
73 if(swmtFilePaths != null) |
|
74 { |
|
75 inputs = swmtFilePaths; |
|
76 cycleData = new ArrayList<CycleData>(); |
|
77 |
|
78 isCancelled = false; |
|
79 IRunnableWithProgress op = new IRunnableWithProgress() { |
|
80 public void run(IProgressMonitor monitor) { |
|
81 monitor.beginTask("Reading log files..", 10); |
|
82 status = logReader.getCycleDataArrayFromLogFiles(inputs, cycleData, monitor); |
|
83 if(monitor.isCanceled()) |
|
84 isCancelled = true; |
|
85 |
|
86 monitor.done(); |
|
87 } |
|
88 }; |
|
89 |
|
90 IWorkbench wb = PlatformUI.getWorkbench(); |
|
91 IWorkbenchWindow win = wb.getActiveWorkbenchWindow(); |
|
92 |
|
93 Shell shell = win != null ? win.getShell() : null; |
|
94 try { |
|
95 new ProgressMonitorDialog(shell).run(true, true, op); |
|
96 } catch (InvocationTargetException e) { |
|
97 e.printStackTrace(); |
|
98 return; |
|
99 } catch (InterruptedException e) { |
|
100 e.printStackTrace(); |
|
101 return; |
|
102 } |
|
103 |
|
104 if(isCancelled) |
|
105 return; |
|
106 |
|
107 if(status != null) |
|
108 { |
|
109 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", status); |
|
110 return; |
|
111 } |
|
112 else if(cycleData.size()>1) |
|
113 { |
|
114 cycleData = logReader.checkCycleOrder(cycleData); |
|
115 if(cycleData==null) |
|
116 { |
|
117 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", "Invalid order of the log files. The selected files must be in consecutive order and must start from the first cycle."); |
|
118 return; |
|
119 } |
|
120 |
|
121 if(!logReader.checkRomInfo(cycleData)) |
|
122 { |
|
123 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", "Selected logs do not have common ROM Checksum and Version. Hence, they cannot be compared."); |
|
124 return; |
|
125 } |
|
126 int ret = logReader.checkTimeStamp(cycleData); |
|
127 if(ret!= 0) |
|
128 { |
|
129 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", "In selected logs, the time stamp of log cycle "+ ret +" is lesser than log cycle "+ (ret -1)+". Hence, they cannot be analysed together."); |
|
130 return; |
|
131 } |
|
132 } |
|
133 else if(cycleData.size() == 1 && cycleData.get(0).getCycleNumber() != 1) |
|
134 { |
|
135 boolean ok = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "SWMT Analyser", "This is a delta file. It does not contain the complete information. Do you still want to continue ?"); |
|
136 if(!ok) |
|
137 return; |
|
138 } |
|
139 |
|
140 //Files are valid and the cycle numbers are in order. |
|
141 //So, get overview information to be displayed in the editor view |
|
142 OverviewData ov = logReader.getOverviewInformationFromCyclesData(cycleData.toArray(new CycleData[0]),cycleData.size()); |
|
143 |
|
144 Runnable runnable = new Runnable(){ |
|
145 public void run() { |
|
146 for(int i=0; i<cycleData.size(); i++) |
|
147 { |
|
148 CycleData cycle = cycleData.get(i); |
|
149 cycle.clear(); |
|
150 |
|
151 try { |
|
152 SwmtParser.parseSwmtLog(cycle.getFileName(), cycle); |
|
153 } catch (SwmtFormatException e) { |
|
154 parserError = e.getMessage(); |
|
155 Runnable runnable = new Runnable(){ |
|
156 public void run() { |
|
157 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", "Error while parsing the log file " + parserError ); |
|
158 } |
|
159 }; |
|
160 Display.getDefault().asyncExec(runnable); |
|
161 return; |
|
162 } |
|
163 } |
|
164 } |
|
165 }; |
|
166 Display.getDefault().syncExec(runnable); |
|
167 |
|
168 IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); |
|
169 try |
|
170 { |
|
171 IEditorDescriptor descriptor = PlatformUI.getWorkbench().getEditorRegistry().findEditor(SWMT_EDITOR_ID); |
|
172 if(descriptor == null) |
|
173 { |
|
174 MessageDialog.openError(Display.getDefault().getActiveShell(),"SWMT Analyser", "SWMT Editor is not found"); |
|
175 return; |
|
176 } |
|
177 |
|
178 ParsedData logData = new ParsedData(); |
|
179 logData.setParsedData(cycleData); |
|
180 page.openEditor(new SWMTEditorInput(logData,ov), descriptor.getId(), true,IWorkbenchPage.MATCH_INPUT); |
|
181 |
|
182 } catch (PartInitException e) { |
|
183 e.printStackTrace(); |
|
184 } |
|
185 } |
|
186 else |
|
187 { |
|
188 MessageDialog.openError(Display.getCurrent().getActiveShell(), "SWMT Analyser", "Invalid input. Unable to open SWMT Editor"); |
|
189 return; |
|
190 } |
|
191 } |
|
192 |
|
193 } |