|
1 /* |
|
2 * Copyright (c) 2007-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 * LineCountProcessor DataProcessor |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.engine.dataprocessor; |
|
20 |
|
21 import java.util.ArrayList; |
|
22 import java.util.List; |
|
23 |
|
24 import com.nokia.traceviewer.TraceViewerPlugin; |
|
25 import com.nokia.traceviewer.action.TraceViewerActionUtils; |
|
26 import com.nokia.traceviewer.dialog.BasePropertyDialog; |
|
27 import com.nokia.traceviewer.dialog.LineCountDialog; |
|
28 import com.nokia.traceviewer.dialog.treeitem.LineCountTreeBaseItem; |
|
29 import com.nokia.traceviewer.dialog.treeitem.LineCountTreeComponentItem; |
|
30 import com.nokia.traceviewer.dialog.treeitem.LineCountTreeItem; |
|
31 import com.nokia.traceviewer.dialog.treeitem.LineCountTreeTextItem; |
|
32 import com.nokia.traceviewer.dialog.treeitem.TreeItem; |
|
33 import com.nokia.traceviewer.dialog.treeitem.TreeItemContentProvider; |
|
34 import com.nokia.traceviewer.dialog.treeitem.TreeItemListener; |
|
35 import com.nokia.traceviewer.engine.TraceInformation; |
|
36 import com.nokia.traceviewer.engine.TraceProperties; |
|
37 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
38 import com.nokia.traceviewer.engine.TraceViewerPropertyViewInterface; |
|
39 import com.nokia.traceviewer.engine.TraceViewerDialogInterface.Dialog; |
|
40 import com.nokia.traceviewer.engine.preferences.PreferenceConstants; |
|
41 import com.nokia.traceviewer.engine.preferences.XMLLineCountConfigurationImporter; |
|
42 |
|
43 /** |
|
44 * LineCount DataProcessor |
|
45 * |
|
46 */ |
|
47 public final class LineCountProcessor implements DataProcessor { |
|
48 |
|
49 /** |
|
50 * Interval how often to update progressbar |
|
51 */ |
|
52 private static final int PROGRESSBAR_UPDATE_INTERVAL = 100; |
|
53 |
|
54 /** |
|
55 * Line count dialog used in setting rules |
|
56 */ |
|
57 private LineCountDialog lineCountDialog; |
|
58 |
|
59 /** |
|
60 * Content provider for the dialog |
|
61 */ |
|
62 private TreeItemContentProvider contentProvider; |
|
63 |
|
64 /** |
|
65 * First visible object in the dialog tree |
|
66 */ |
|
67 private TreeItem root; |
|
68 |
|
69 /** |
|
70 * Line count items array |
|
71 */ |
|
72 private final List<LineCountItem> lineCountItems; |
|
73 |
|
74 /** |
|
75 * Text rules that are applied |
|
76 */ |
|
77 private final List<LineCountTreeTextItem> textRules; |
|
78 |
|
79 /** |
|
80 * Component rules that are applied |
|
81 */ |
|
82 private final List<LineCountTreeComponentItem> componentRules; |
|
83 |
|
84 /** |
|
85 * Constructor |
|
86 */ |
|
87 public LineCountProcessor() { |
|
88 // Create initial tree |
|
89 createInitialTree(); |
|
90 |
|
91 // Create rule arrays |
|
92 lineCountItems = new ArrayList<LineCountItem>(); |
|
93 textRules = new ArrayList<LineCountTreeTextItem>(); |
|
94 componentRules = new ArrayList<LineCountTreeComponentItem>(); |
|
95 |
|
96 } |
|
97 |
|
98 /** |
|
99 * Creates initial tree |
|
100 */ |
|
101 public void createInitialTree() { |
|
102 contentProvider = new TreeItemContentProvider(); |
|
103 // Create root node |
|
104 TreeItem treeRoot = new LineCountTreeBaseItem(contentProvider, null, |
|
105 "root", //$NON-NLS-1$ |
|
106 LineCountTreeItem.Rule.GROUP); |
|
107 root = new LineCountTreeBaseItem(contentProvider, treeRoot, |
|
108 TraceViewerPlugin.getDefault().getPreferenceStore().getString( |
|
109 PreferenceConstants.CONFIGURATION_FILE), |
|
110 LineCountTreeItem.Rule.GROUP); |
|
111 treeRoot.addChild(root); |
|
112 } |
|
113 |
|
114 /** |
|
115 * Imports line count rules from configuration file |
|
116 */ |
|
117 public void importLineCountRules() { |
|
118 // Import Line Count rules |
|
119 XMLLineCountConfigurationImporter importer = new XMLLineCountConfigurationImporter( |
|
120 root, TraceViewerPlugin.getDefault().getPreferenceStore() |
|
121 .getString(PreferenceConstants.CONFIGURATION_FILE), |
|
122 true); |
|
123 importer.importData(); |
|
124 } |
|
125 |
|
126 /* |
|
127 * (non-Javadoc) |
|
128 * |
|
129 * @see |
|
130 * com.nokia.traceviewer.engine.DataProcessor#processData(com.nokia.traceviewer |
|
131 * .engine.TraceProperties) |
|
132 */ |
|
133 public void processData(TraceProperties properties) { |
|
134 if (!properties.traceConfiguration.isScrolledTrace() |
|
135 && !properties.traceConfiguration.isFilteredOut() |
|
136 && !properties.traceConfiguration.isTriggeredOut()) { |
|
137 if (!lineCountItems.isEmpty()) { |
|
138 boolean ruleHit = false; |
|
139 |
|
140 // Process component rules |
|
141 ruleHit = processComponentRules(properties); |
|
142 |
|
143 // Process text rules |
|
144 if (!ruleHit) { |
|
145 processTextRules(properties); |
|
146 } |
|
147 |
|
148 // Update progressBar if needed |
|
149 updateProgressBar(); |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 /** |
|
155 * Process component rules |
|
156 * |
|
157 * @param properties |
|
158 * trace properties |
|
159 * @return true if rule hits |
|
160 */ |
|
161 private boolean processComponentRules(TraceProperties properties) { |
|
162 boolean ruleHit = false; |
|
163 TraceInformation information = properties.information; |
|
164 |
|
165 // Information must be defined |
|
166 if (information != null && information.isDefined()) { |
|
167 |
|
168 // Loop through component rules |
|
169 int len = componentRules.size(); |
|
170 LineCountTreeComponentItem rule; |
|
171 for (int i = 0; i < len; i++) { |
|
172 rule = componentRules.get(i); |
|
173 // Get component ID |
|
174 int compId = rule.getComponentId(); |
|
175 |
|
176 // Component ID matches |
|
177 if (compId == BasePropertyDialog.WILDCARD_INTEGER |
|
178 || compId == information.getComponentId()) { |
|
179 |
|
180 // Get group ID |
|
181 int groupId = rule.getGroupId(); |
|
182 |
|
183 // Group ID matches |
|
184 if (groupId == BasePropertyDialog.WILDCARD_INTEGER |
|
185 || groupId == information.getGroupId()) { |
|
186 |
|
187 updateLineCountItem(i); |
|
188 ruleHit = true; |
|
189 break; |
|
190 } |
|
191 } |
|
192 } |
|
193 } |
|
194 return ruleHit; |
|
195 } |
|
196 |
|
197 /** |
|
198 * Process text rules |
|
199 * |
|
200 * @param properties |
|
201 * trace properties |
|
202 * @return true if rule hits |
|
203 */ |
|
204 private boolean processTextRules(TraceProperties properties) { |
|
205 boolean ruleHit = false; |
|
206 |
|
207 // Loop through text rules |
|
208 int len = textRules.size(); |
|
209 LineCountTreeTextItem rule; |
|
210 for (int i = 0; i < len; i++) { |
|
211 rule = textRules.get(i); |
|
212 String traceLine = ""; //$NON-NLS-1$ |
|
213 |
|
214 // Traces missing |
|
215 if (properties.bTraceInformation.isTraceMissing()) { |
|
216 traceLine = TraceViewerActionUtils.TRACES_DROPPED_MSG; |
|
217 } |
|
218 if (properties.traceString != null) { |
|
219 traceLine += properties.traceString; |
|
220 } |
|
221 |
|
222 String ruleStr = rule.getTextToCompare(); |
|
223 if (ruleStr == null) { |
|
224 break; |
|
225 } |
|
226 if (!rule.isMatchCase()) { |
|
227 traceLine = traceLine.toLowerCase(); |
|
228 } |
|
229 |
|
230 // Line hits |
|
231 if (traceLine.contains(ruleStr)) { |
|
232 // Get offset of this text rule in lineCountItems list by adding |
|
233 // i to the number of component rules existing |
|
234 updateLineCountItem(componentRules.size() + i); |
|
235 ruleHit = true; |
|
236 } |
|
237 } |
|
238 return ruleHit; |
|
239 } |
|
240 |
|
241 /** |
|
242 * Updates Line Count Item |
|
243 * |
|
244 * @param offset |
|
245 * offset of item to update |
|
246 */ |
|
247 private void updateLineCountItem(int offset) { |
|
248 LineCountItem item = lineCountItems.get(offset); |
|
249 int count = item.getCount(); |
|
250 item.setCount(count + 1); |
|
251 item.setChanged(true); |
|
252 |
|
253 TraceViewerPropertyViewInterface view = TraceViewerGlobals |
|
254 .getTraceViewer().getPropertyView(); |
|
255 if (view != null) { |
|
256 view.setLineCountTableChanged(); |
|
257 } |
|
258 } |
|
259 |
|
260 /** |
|
261 * Update progressBar if needed |
|
262 */ |
|
263 private void updateProgressBar() { |
|
264 // Update possible progressBar |
|
265 if (isProcessingCounting() |
|
266 && TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
267 .getCurrentDataReader().getTraceCount() |
|
268 % PROGRESSBAR_UPDATE_INTERVAL == 0) { |
|
269 lineCountDialog.getProgressBar().updateProgressBar( |
|
270 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
271 .getCurrentDataReader().getTraceCount()); |
|
272 |
|
273 } |
|
274 } |
|
275 |
|
276 /** |
|
277 * Tells if initial counting is in process |
|
278 * |
|
279 * @return true if initial counting is in progress |
|
280 */ |
|
281 public boolean isProcessingCounting() { |
|
282 return (lineCountDialog != null |
|
283 && lineCountDialog.getProgressBar() != null |
|
284 && lineCountDialog.getProgressBar().getShell() != null && !lineCountDialog |
|
285 .getProgressBar().getShell().isDisposed()); |
|
286 } |
|
287 |
|
288 /** |
|
289 * Gets lineCount dialog |
|
290 * |
|
291 * @return filter dialog |
|
292 */ |
|
293 public LineCountDialog getLineCountDialog() { |
|
294 if (lineCountDialog == null) { |
|
295 lineCountDialog = (LineCountDialog) TraceViewerGlobals |
|
296 .getTraceViewer().getDialogs().createDialog( |
|
297 Dialog.COUNTLINES); |
|
298 } |
|
299 return lineCountDialog; |
|
300 } |
|
301 |
|
302 /** |
|
303 * Gets root of the filter tree |
|
304 * |
|
305 * @return root |
|
306 */ |
|
307 public TreeItem getRoot() { |
|
308 return root; |
|
309 } |
|
310 |
|
311 /** |
|
312 * Gets item listener |
|
313 * |
|
314 * @return the contentProvider |
|
315 */ |
|
316 public TreeItemListener getTreeItemListener() { |
|
317 return contentProvider; |
|
318 } |
|
319 |
|
320 /** |
|
321 * Gets lineCountItems |
|
322 * |
|
323 * @return the lineCountItems |
|
324 */ |
|
325 public List<LineCountItem> getLineCountItems() { |
|
326 return lineCountItems; |
|
327 } |
|
328 |
|
329 /** |
|
330 * Gets text rules |
|
331 * |
|
332 * @return text rules |
|
333 */ |
|
334 public List<LineCountTreeTextItem> getTextRules() { |
|
335 return textRules; |
|
336 } |
|
337 |
|
338 /** |
|
339 * Gets component rules |
|
340 * |
|
341 * @return component rules |
|
342 */ |
|
343 public List<LineCountTreeComponentItem> getComponentRules() { |
|
344 return componentRules; |
|
345 } |
|
346 |
|
347 /** |
|
348 * Empty lineCountItems |
|
349 */ |
|
350 public void emptyLineCountItems() { |
|
351 for (int i = 0; i < lineCountItems.size(); i++) { |
|
352 lineCountItems.get(i).setCount(0); |
|
353 lineCountItems.get(i).setChanged(true); |
|
354 } |
|
355 } |
|
356 |
|
357 /** |
|
358 * Enable linecount rule |
|
359 * |
|
360 * @param item |
|
361 * the rule item |
|
362 */ |
|
363 public void enableRule(LineCountTreeItem item) { |
|
364 LineCountItem newItem = new LineCountItem(item.getName(), 0); |
|
365 if (item instanceof LineCountTreeTextItem) { |
|
366 textRules.add((LineCountTreeTextItem) item); |
|
367 lineCountItems.add(newItem); |
|
368 |
|
369 // Add component item to the beginning of the list |
|
370 } else if (item instanceof LineCountTreeComponentItem) { |
|
371 componentRules.add((LineCountTreeComponentItem) item); |
|
372 lineCountItems.add(0, newItem); |
|
373 } |
|
374 if (TraceViewerGlobals.getTraceViewer().getPropertyView() != null) { |
|
375 TraceViewerGlobals.getTraceViewer().getPropertyView() |
|
376 .createNewPropertyTableItems(); |
|
377 } |
|
378 } |
|
379 } |