22 import java.text.MessageFormat; |
22 import java.text.MessageFormat; |
23 import java.util.ArrayList; |
23 import java.util.ArrayList; |
24 import java.util.List; |
24 import java.util.List; |
25 |
25 |
26 import org.eclipse.core.runtime.IPath; |
26 import org.eclipse.core.runtime.IPath; |
|
27 import org.eclipse.core.runtime.IStatus; |
27 import org.eclipse.core.runtime.Path; |
28 import org.eclipse.core.runtime.Path; |
28 import org.eclipse.jface.viewers.ITableLabelProvider; |
29 import org.eclipse.jface.viewers.ITableLabelProvider; |
29 import org.eclipse.jface.viewers.LabelProvider; |
30 import org.eclipse.jface.viewers.LabelProvider; |
30 import org.eclipse.jface.viewers.TableViewer; |
31 import org.eclipse.jface.viewers.TableViewer; |
31 import org.eclipse.jface.viewers.Viewer; |
32 import org.eclipse.jface.viewers.Viewer; |
38 import org.eclipse.swt.widgets.Group; |
39 import org.eclipse.swt.widgets.Group; |
39 import org.eclipse.swt.widgets.Table; |
40 import org.eclipse.swt.widgets.Table; |
40 import org.eclipse.swt.widgets.TableColumn; |
41 import org.eclipse.swt.widgets.TableColumn; |
41 import org.eclipse.swt.widgets.TableItem; |
42 import org.eclipse.swt.widgets.TableItem; |
42 |
43 |
43 import com.nokia.carbide.cpp.internal.pi.analyser.StreamFileParser; |
|
44 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace; |
44 import com.nokia.carbide.cpp.internal.pi.plugin.model.ITrace; |
45 import com.nokia.carbide.cpp.internal.pi.utils.PIUtilities; |
45 import com.nokia.carbide.cpp.internal.pi.utils.PIUtilities; |
46 |
46 |
47 /** |
47 /** |
48 * Base group for the profiler data importers |
48 * Base group for the profiler data importers |
85 } |
85 } |
86 } |
86 } |
87 |
87 |
88 private List<ProfilerDataPlugins> profilerDataFiles = new ArrayList<ProfilerDataPlugins>(); |
88 private List<ProfilerDataPlugins> profilerDataFiles = new ArrayList<ProfilerDataPlugins>(); |
89 protected INewPIWizardSettings wizardSettings; |
89 protected INewPIWizardSettings wizardSettings; |
|
90 private boolean timeAndSizeEnabled; |
90 |
91 |
91 /** |
92 /** |
92 * Constructor |
93 * Constructor |
93 * |
94 * |
94 * @param parent |
95 * @param parent |
95 * instance of parent Composite |
96 * instance of parent Composite |
96 * @param wizardSettings |
97 * @param wizardSettings |
97 * instance of the INewPIWizardSettings |
98 * instance of the INewPIWizardSettings |
|
99 * @param timeAndSizeEnabled is used to store trace data file during the tracing |
98 */ |
100 */ |
99 public AbstractBaseGroup(Composite parent, |
101 public AbstractBaseGroup(Composite parent, |
100 INewPIWizardSettings wizardSettings) { |
102 INewPIWizardSettings wizardSettings, boolean timeAndSizeEnabled) { |
101 super(parent, SWT.NONE); |
103 super(parent, SWT.NONE); |
102 this.wizardSettings = wizardSettings; |
104 this.wizardSettings = wizardSettings; |
|
105 this.timeAndSizeEnabled = timeAndSizeEnabled; |
103 // set default layout |
106 // set default layout |
104 this.setLayout(new GridLayout(1, false)); |
107 this.setLayout(new GridLayout(1, false)); |
105 this.setLayoutData(new GridData(GridData.FILL_BOTH)); |
108 this.setLayoutData(new GridData(GridData.FILL_BOTH)); |
106 createContent(); |
109 createContent(); |
107 |
110 |
114 /** |
117 /** |
115 * Implement content for the group |
118 * Implement content for the group |
116 */ |
119 */ |
117 protected abstract void createContent(); |
120 protected abstract void createContent(); |
118 |
121 |
|
122 public abstract IStatus validateContent(NewPIWizard wizardPage); |
|
123 |
119 protected abstract Table getTable(); |
124 protected abstract Table getTable(); |
120 |
125 |
121 /** |
126 /** |
122 * Set this visible and hide given composite |
127 * Set this visible and hide given composite |
123 * |
128 * |
124 * @param hideComposite |
129 * @param hideComposite |
125 * to hide |
130 * to hide |
126 */ |
131 */ |
127 public void setVisible(Composite hideComposite) { |
132 public void setVisible(Composite hideComposite) { |
128 setVisible(true); |
133 if (hideComposite.getLayoutData() instanceof GridData) { |
|
134 ((GridData) hideComposite.getLayoutData()).exclude = true; |
|
135 } |
|
136 if (this.getLayoutData() instanceof GridData) { |
|
137 ((GridData) this.getLayoutData()).exclude = false; |
|
138 } |
129 setLocation(hideComposite.getLocation()); |
139 setLocation(hideComposite.getLocation()); |
130 setSize(hideComposite.getSize()); |
140 setSize(hideComposite.getSize()); |
|
141 setVisible(true); |
131 hideComposite.setVisible(false); |
142 hideComposite.setVisible(false); |
|
143 wizardSettings.validatePage(); |
132 } |
144 } |
133 |
145 |
134 /** |
146 /** |
135 * Add given profile data file into store |
147 * Add given profile data file into store |
136 * |
148 * |
137 * @param path |
149 * @param path |
138 * selected profile data file |
150 * selected profile data file |
|
151 * @param time of the used to trace |
|
152 * @param size of the trace data file |
139 * @throws IllegalArgumentException |
153 * @throws IllegalArgumentException |
140 * if given file is not valid profile data file |
154 * if given file is not valid profile data file |
141 */ |
155 */ |
142 public void addProfileDataFile(IPath path) throws IllegalArgumentException { |
156 public void addProfilerDataFile(IPath path, long time, long size) throws IllegalArgumentException { |
143 boolean exists = false; |
157 boolean exists = false; |
144 for (ProfilerDataPlugins pdp : profilerDataFiles) { |
158 for (ProfilerDataPlugins pdp : profilerDataFiles) { |
145 if (pdp.getProfilerDataPath().equals(path)) { |
159 if (pdp.getProfilerDataPath().equals(path)) { |
146 exists = true; |
160 exists = true; |
147 } |
161 } |
151 try { |
165 try { |
152 File file = path.toFile(); |
166 File file = path.toFile(); |
153 if (!file.isFile() || file.length() <= 0) { |
167 if (!file.isFile() || file.length() <= 0) { |
154 throw new IllegalArgumentException(); |
168 throw new IllegalArgumentException(); |
155 } |
169 } |
156 new StreamFileParser(file).allTraceType(); |
170 |
157 profilerDataFiles.add(new ProfilerDataPlugins(path, |
171 ProfilerDataPlugins dataPlugins = new ProfilerDataPlugins(path, |
158 getPluginsForTraceFile(path))); |
172 getPluginsForTraceFile(path)); |
|
173 if(timeAndSizeEnabled){ |
|
174 dataPlugins.updateTimeAndSize(time, size); |
|
175 } |
|
176 profilerDataFiles.add(dataPlugins); |
159 } catch (Exception e) { |
177 } catch (Exception e) { |
160 throw new IllegalArgumentException(MessageFormat.format( |
178 throw new IllegalArgumentException( |
161 Messages.getString("AbstractBaseGroup.isNotValidProfilerFile"), path //$NON-NLS-1$ |
179 MessageFormat |
162 .lastSegment())); |
180 .format( |
|
181 Messages |
|
182 .getString("AbstractBaseGroup.isNotValidProfilerFile"), path //$NON-NLS-1$ |
|
183 .lastSegment())); |
163 } |
184 } |
164 } else { |
185 } else { |
165 throw new IllegalArgumentException(MessageFormat.format( |
186 throw new IllegalArgumentException( |
166 Messages.getString("AbstractBaseGroup.profilerFileIsExisted"), path.lastSegment())); //$NON-NLS-1$ |
187 MessageFormat |
|
188 .format( |
|
189 Messages |
|
190 .getString("AbstractBaseGroup.profilerFileIsExisted"), path.lastSegment())); //$NON-NLS-1$ |
|
191 } |
|
192 } |
|
193 |
|
194 /** |
|
195 * Update trace data file during tracing |
|
196 * |
|
197 * @param path of the profiler data file |
|
198 * @param time of the trace run |
|
199 * @param size of the trace data file |
|
200 * @throws IllegalArgumentException |
|
201 */ |
|
202 public void updateProfilerDataFile(IPath path, long time, long size) |
|
203 throws IllegalArgumentException { |
|
204 boolean exists = false; |
|
205 for (ProfilerDataPlugins pdp : profilerDataFiles) { |
|
206 if (pdp.getProfilerDataPath().equals(path)) { |
|
207 pdp.updateTimeAndSize(time, size); |
|
208 exists = true; |
|
209 break; |
|
210 } |
|
211 } |
|
212 if (!exists) { |
|
213 profilerDataFiles.add(new ProfilerDataPlugins(path, null)); |
|
214 |
|
215 } else { |
|
216 if (!timeAndSizeEnabled) { |
|
217 throw new IllegalArgumentException( |
|
218 MessageFormat |
|
219 .format("Failed to update profiler data file", path.lastSegment())); //$NON-NLS-1$ |
|
220 } |
|
221 |
167 } |
222 } |
168 } |
223 } |
169 |
224 |
170 /** |
225 /** |
171 * Add all valid profile data file from given directory's path |
226 * Add all valid profile data file from given directory's path |
193 } |
248 } |
194 }); |
249 }); |
195 |
250 |
196 for (File file : fileArray) { |
251 for (File file : fileArray) { |
197 try { |
252 try { |
198 addProfileDataFile(new Path(file.toString())); |
253 addProfilerDataFile(new Path(file.toString()),0,0); |
199 addedValidFile = true; |
254 addedValidFile = true; |
200 } catch (Exception e) { |
255 } catch (Exception e) { |
201 // do nothing |
256 // do nothing |
202 } |
257 } |
203 } |
258 } |
204 |
259 |
205 } catch (Exception e) { |
260 } catch (Exception e) { |
206 throw new IllegalArgumentException(MessageFormat.format( |
261 throw new IllegalArgumentException( |
207 Messages.getString("AbstractBaseGroup.failedToImportFromFolder"), path //$NON-NLS-1$ |
262 MessageFormat |
208 .toOSString())); |
263 .format( |
|
264 Messages |
|
265 .getString("AbstractBaseGroup.failedToImportFromFolder"), path //$NON-NLS-1$ |
|
266 .toOSString())); |
209 } |
267 } |
210 if (!addedValidFile) { |
268 if (!addedValidFile) { |
211 throw new IllegalArgumentException(MessageFormat.format( |
269 throw new IllegalArgumentException( |
212 Messages.getString("AbstractBaseGroup.notFoundProfilerDataFiles"), path //$NON-NLS-1$ |
270 MessageFormat |
213 .toOSString())); |
271 .format( |
|
272 Messages |
|
273 .getString("AbstractBaseGroup.notFoundProfilerDataFiles"), path //$NON-NLS-1$ |
|
274 .toOSString())); |
214 } |
275 } |
215 } |
276 } |
216 } |
277 } |
217 |
278 |
218 /** |
279 /** |
270 * Updates given TableViewer so that it contains same data that |
348 * Updates given TableViewer so that it contains same data that |
271 * ProfilerDataPlugins list. |
349 * ProfilerDataPlugins list. |
272 * |
350 * |
273 * @param tableViewer |
351 * @param tableViewer |
274 * instance of the TableViewer |
352 * instance of the TableViewer |
275 */ |
353 * @param validatePage is need to be validate |
276 public void refreshTable(TableViewer tableViewer) { |
354 */ |
|
355 public void refreshTable(TableViewer tableViewer, boolean validatePage) { |
277 Table table = tableViewer.getTable(); |
356 Table table = tableViewer.getTable(); |
278 List<IPath> pathList = new ArrayList<IPath>(); |
357 if (timeAndSizeEnabled) { |
279 for (ProfilerDataPlugins pdp : profilerDataFiles) { |
358 tableViewer.setInput(profilerDataFiles); |
280 pathList.add(pdp.getProfilerDataPath()); |
359 } else { |
281 } |
360 List<IPath> pathList = new ArrayList<IPath>(); |
282 tableViewer.setInput(pathList); |
361 for (ProfilerDataPlugins pdp : profilerDataFiles) { |
|
362 pathList.add(pdp.getProfilerDataPath()); |
|
363 } |
|
364 tableViewer.setInput(pathList); |
|
365 |
|
366 } |
283 table.setSelection(0); |
367 table.setSelection(0); |
284 tableViewer.refresh(); |
368 tableViewer.refresh(); |
285 wizardSettings.validatePage(); |
369 if(validatePage){ |
|
370 wizardSettings.validatePage(); |
|
371 } |
|
372 |
|
373 |
286 } |
374 } |
287 |
375 |
288 /** |
376 /** |
289 * Get plugins list from given file |
377 * Get plugins list from given file |
290 * |
378 * |
291 * @param profilerPath profiler data file |
379 * @param profilerPath |
|
380 * profiler data file |
292 * @return available plugins list from given file |
381 * @return available plugins list from given file |
293 * @throws IOException |
382 * @throws IOException |
294 */ |
383 */ |
295 private List<ITrace> getPluginsForTraceFile(IPath profilerPath) |
384 private List<ITrace> getPluginsForTraceFile(IPath profilerPath) |
296 throws IOException { |
385 throws IOException { |