|
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 * Variable tracing Dialog class |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.dialog; |
|
20 |
|
21 import java.util.List; |
|
22 |
|
23 import org.eclipse.jface.dialogs.InputDialog; |
|
24 import org.eclipse.jface.viewers.StructuredSelection; |
|
25 import org.eclipse.jface.window.Window; |
|
26 import org.eclipse.swt.widgets.Shell; |
|
27 |
|
28 import com.nokia.traceviewer.TraceViewerPlugin; |
|
29 import com.nokia.traceviewer.action.TraceViewerActionUtils; |
|
30 import com.nokia.traceviewer.dialog.treeitem.TreeItem; |
|
31 import com.nokia.traceviewer.dialog.treeitem.TreeItemContentProvider; |
|
32 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeBaseItem; |
|
33 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeItem; |
|
34 import com.nokia.traceviewer.dialog.treeitem.VariableTracingTreeTextItem; |
|
35 import com.nokia.traceviewer.engine.TraceViewerGlobals; |
|
36 import com.nokia.traceviewer.engine.TraceViewerPropertyViewInterface; |
|
37 import com.nokia.traceviewer.engine.TraceViewerDialogInterface.Dialog; |
|
38 import com.nokia.traceviewer.engine.dataprocessor.VariableTracingItem; |
|
39 import com.nokia.traceviewer.engine.preferences.PreferenceConstants; |
|
40 import com.nokia.traceviewer.engine.preferences.XMLVariableTracingConfigurationExporter; |
|
41 |
|
42 /** |
|
43 * Variable tracing Dialog class |
|
44 */ |
|
45 public final class VariableTracingDialog extends BaseTreeDialog { |
|
46 |
|
47 /** |
|
48 * Processing reason to give to progressBar dialog |
|
49 */ |
|
50 private static final String processReason = Messages |
|
51 .getString("VariableTracingDialog.ProcessReason"); //$NON-NLS-1$ |
|
52 |
|
53 /** |
|
54 * Add item image |
|
55 */ |
|
56 private static final String itemAddImageLocation = "/icons/filteradd.gif"; //$NON-NLS-1$ |
|
57 |
|
58 /** |
|
59 * Edit item image |
|
60 */ |
|
61 private static final String itemEditImageLocation = "/icons/filteredit.gif"; //$NON-NLS-1$ |
|
62 |
|
63 /** |
|
64 * Remove item image |
|
65 */ |
|
66 private static final String itemRemoveImageLocation = "/icons/filterremove.gif"; //$NON-NLS-1$ |
|
67 |
|
68 /** |
|
69 * Dialog name |
|
70 */ |
|
71 private static final String dialogName = Messages |
|
72 .getString("VariableTracingDialog.DialogName"); //$NON-NLS-1$ |
|
73 |
|
74 /** |
|
75 * Constructor |
|
76 * |
|
77 * @param parent |
|
78 * parent shell |
|
79 * @param contentProvider |
|
80 * contentprovider for the tree |
|
81 * @param treeRoot |
|
82 * tree root |
|
83 */ |
|
84 public VariableTracingDialog(Shell parent, |
|
85 TreeItemContentProvider contentProvider, TreeItem treeRoot) { |
|
86 super(parent, contentProvider, treeRoot); |
|
87 } |
|
88 |
|
89 /* |
|
90 * (non-Javadoc) |
|
91 * |
|
92 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#export() |
|
93 */ |
|
94 @Override |
|
95 public void export() { |
|
96 |
|
97 // Export rules to XML file |
|
98 XMLVariableTracingConfigurationExporter exporter; |
|
99 |
|
100 // Default configuration file |
|
101 if (!TraceViewerPlugin.getDefault().getPreferenceStore().getString( |
|
102 PreferenceConstants.CONFIGURATION_FILE).equals( |
|
103 PreferenceConstants.DEFAULT_CONFIGURATION_FILE)) { |
|
104 exporter = new XMLVariableTracingConfigurationExporter(root, |
|
105 TraceViewerPlugin.getDefault().getPreferenceStore() |
|
106 .getString(PreferenceConstants.CONFIGURATION_FILE), |
|
107 false); |
|
108 } else { |
|
109 exporter = new XMLVariableTracingConfigurationExporter(root, |
|
110 PreferenceConstants.DEFAULT_CONFIGURATION_FILE, true); |
|
111 } |
|
112 |
|
113 exporter.export(); |
|
114 } |
|
115 |
|
116 /* |
|
117 * (non-Javadoc) |
|
118 * |
|
119 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#saveSettings() |
|
120 */ |
|
121 @Override |
|
122 public void saveSettings() { |
|
123 // Save the old location |
|
124 super.saveSettings(); |
|
125 |
|
126 // Save VariableTracingItems if something changed |
|
127 if (somethingChanged && !viewer.getControl().isDisposed()) { |
|
128 Object[] arr = viewer.getCheckedElements(); |
|
129 |
|
130 // Get arrays and empty them |
|
131 List<VariableTracingItem> variableTracingItems = TraceViewerGlobals |
|
132 .getTraceViewer().getDataProcessorAccess() |
|
133 .getVariableTracingProcessor().getVariableTracingItems(); |
|
134 List<VariableTracingTreeTextItem> textRules = TraceViewerGlobals |
|
135 .getTraceViewer().getDataProcessorAccess() |
|
136 .getVariableTracingProcessor().getTextRules(); |
|
137 |
|
138 variableTracingItems.clear(); |
|
139 textRules.clear(); |
|
140 |
|
141 // Create new items |
|
142 for (int i = 0; i < arr.length; i++) { |
|
143 VariableTracingTreeItem listItem = (VariableTracingTreeItem) arr[i]; |
|
144 |
|
145 // Text rule |
|
146 if (listItem.getRule() == VariableTracingTreeItem.Rule.TEXT_RULE) { |
|
147 VariableTracingTreeTextItem listItem2 = (VariableTracingTreeTextItem) listItem; |
|
148 textRules.add(listItem2); |
|
149 VariableTracingItem item = new VariableTracingItem( |
|
150 listItem2.getName(), listItem2.getText(), listItem2 |
|
151 .isMatchCase(), listItem2.getHistoryCount()); |
|
152 variableTracingItems.add(item); |
|
153 } |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 /* |
|
159 * (non-Javadoc) |
|
160 * |
|
161 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#restoreSettings() |
|
162 */ |
|
163 @Override |
|
164 protected void restoreSettings() { |
|
165 super.restoreSettings(); |
|
166 |
|
167 // Get text rule array |
|
168 List<VariableTracingTreeTextItem> textRules = TraceViewerGlobals |
|
169 .getTraceViewer().getDataProcessorAccess() |
|
170 .getVariableTracingProcessor().getTextRules(); |
|
171 |
|
172 // Tree has to be re-checked |
|
173 for (int i = 0; i < textRules.size(); i++) { |
|
174 VariableTracingTreeItem item = textRules.get(i); |
|
175 viewer.setChecked(item, true); |
|
176 checkboxStateListener.checkStateChanged(item); |
|
177 } |
|
178 } |
|
179 |
|
180 /* |
|
181 * (non-Javadoc) |
|
182 * |
|
183 * @see com.nokia.traceviewer.dialog.BaseDialog#createDialogContents() |
|
184 */ |
|
185 @Override |
|
186 protected void createDialogContents() { |
|
187 super.createDialogContents(dialogName); |
|
188 } |
|
189 |
|
190 /* |
|
191 * (non-Javadoc) |
|
192 * |
|
193 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#createToolBar() |
|
194 */ |
|
195 @Override |
|
196 public void createToolBar() { |
|
197 super.createToolBar(itemAddImageLocation, itemEditImageLocation, |
|
198 itemRemoveImageLocation); |
|
199 } |
|
200 |
|
201 /* |
|
202 * (non-Javadoc) |
|
203 * |
|
204 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#processAddGroupAction() |
|
205 */ |
|
206 @Override |
|
207 protected void processAddGroupAction() { |
|
208 String name = Messages.getString("VariableTracingDialog.NewGroupText"); //$NON-NLS-1$ |
|
209 InputDialog dialog = new InputDialog( |
|
210 getShell(), |
|
211 name, |
|
212 Messages.getString("VariableTracingDialog.NewGroupDialogInfo"), name, null); //$NON-NLS-1$ |
|
213 int ret = dialog.open(); |
|
214 if (ret == Window.OK) { |
|
215 name = dialog.getValue(); |
|
216 |
|
217 // Get parent node |
|
218 Object selection = getSelectedGroup(); |
|
219 VariableTracingTreeItem item = new VariableTracingTreeBaseItem( |
|
220 contentProvider, selection, name, |
|
221 VariableTracingTreeItem.Rule.GROUP, 0); |
|
222 ((VariableTracingTreeItem) selection).addChild(item); |
|
223 viewer.expandToLevel(item, 0); |
|
224 |
|
225 somethingChanged = true; |
|
226 } |
|
227 } |
|
228 |
|
229 /* |
|
230 * (non-Javadoc) |
|
231 * |
|
232 * @see |
|
233 * com.nokia.traceviewer.dialog.BaseTreeDialog#processApplyButtonAction() |
|
234 */ |
|
235 @Override |
|
236 protected void processApplyButtonAction() { |
|
237 saveSettings(); |
|
238 |
|
239 List<VariableTracingItem> items = TraceViewerGlobals.getTraceViewer() |
|
240 .getDataProcessorAccess().getVariableTracingProcessor() |
|
241 .getVariableTracingItems(); |
|
242 |
|
243 // Start variable tracing from beginning |
|
244 if (!items.isEmpty() && somethingChanged) { |
|
245 |
|
246 TraceViewerPropertyViewInterface propView = TraceViewerGlobals |
|
247 .getTraceViewer().getPropertyView(); |
|
248 if (propView != null && !propView.isDisposed()) { |
|
249 propView.clearAll(); |
|
250 propView.createNewPropertyTableItems(); |
|
251 // View is not open, empty items from processors |
|
252 } else { |
|
253 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
254 .getLineCountProcessor().emptyLineCountItems(); |
|
255 |
|
256 TraceViewerGlobals.getTraceViewer().getDataProcessorAccess() |
|
257 .getVariableTracingProcessor() |
|
258 .emptyVariableTracingItems(); |
|
259 } |
|
260 |
|
261 // Set traces not to be shown in the view |
|
262 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
263 .getCurrentDataReader().getTraceConfiguration() |
|
264 .setShowInView(false); |
|
265 |
|
266 int maxLines = TraceViewerGlobals.getTraceViewer() |
|
267 .getDataReaderAccess().getCurrentDataReader() |
|
268 .getTraceCount(); |
|
269 |
|
270 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
271 .getCurrentDataReader().setFilePosition(0); |
|
272 |
|
273 // Open property view |
|
274 TraceViewerActionUtils.openPropertyView(); |
|
275 |
|
276 // Hide dialog and open progressbar only if there is at least one |
|
277 // trace |
|
278 if (maxLines > 0) { |
|
279 getShell().setVisible(false); |
|
280 progressBarDialog = (ProgressBarDialog) TraceViewerGlobals |
|
281 .getTraceViewer().getDialogs().createDialog( |
|
282 Dialog.PROGRESSBAR); |
|
283 progressBarDialog.open(maxLines, processReason); |
|
284 } |
|
285 |
|
286 // Set traces back to be shown in the view |
|
287 TraceViewerGlobals.getTraceViewer().getDataReaderAccess() |
|
288 .getCurrentDataReader().getTraceConfiguration() |
|
289 .setShowInView(true); |
|
290 |
|
291 // Removed all count line rules |
|
292 } else if (somethingChanged) { |
|
293 TraceViewerPropertyViewInterface view = TraceViewerGlobals |
|
294 .getTraceViewer().getPropertyView(); |
|
295 |
|
296 if (view != null && !view.isDisposed()) { |
|
297 view.createNewPropertyTableItems(); |
|
298 } |
|
299 } |
|
300 |
|
301 // Insert this to NOT run saveSettings again |
|
302 somethingChanged = false; |
|
303 } |
|
304 |
|
305 /* |
|
306 * (non-Javadoc) |
|
307 * |
|
308 * @see com.nokia.traceviewer.dialog.BaseTreeDialog#okPressed() |
|
309 */ |
|
310 @Override |
|
311 protected void okPressed() { |
|
312 TraceViewerGlobals.postUiEvent("OkButton", "1"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
313 saveSettings(); |
|
314 super.okPressed(); |
|
315 TraceViewerGlobals.postUiEvent("OkButton", "0"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
316 } |
|
317 |
|
318 /* |
|
319 * (non-Javadoc) |
|
320 * |
|
321 * @see |
|
322 * com.nokia.traceviewer.dialog.BaseTreeDialog#getPropertyDialog(java.lang |
|
323 * .Object, boolean) |
|
324 */ |
|
325 @Override |
|
326 protected BasePropertyDialog getPropertyDialog(Object selection, |
|
327 boolean editOldItem) { |
|
328 VariableTracingTreeItem oldItem = null; |
|
329 if (editOldItem) { |
|
330 oldItem = (VariableTracingTreeItem) selection; |
|
331 } |
|
332 VariableTracingPropertyDialog dialog = new VariableTracingPropertyDialog( |
|
333 getShell(), oldItem, contentProvider, selection); |
|
334 return dialog; |
|
335 } |
|
336 |
|
337 /** |
|
338 * Edits existing item or adds new one |
|
339 * |
|
340 * @param itemIndex |
|
341 * item index to be edited. If -1, create new one |
|
342 */ |
|
343 public void editOrAddItem(int itemIndex) { |
|
344 TreeItem item = null; |
|
345 |
|
346 // Create the dialog |
|
347 create(); |
|
348 |
|
349 // Restore selected items to the tree |
|
350 restoreSettings(); |
|
351 |
|
352 // Create new item |
|
353 if (itemIndex == -1) { |
|
354 item = processAddItemAction(); |
|
355 |
|
356 // Edit old one |
|
357 } else { |
|
358 List<VariableTracingTreeTextItem> textRules = TraceViewerGlobals |
|
359 .getTraceViewer().getDataProcessorAccess() |
|
360 .getVariableTracingProcessor().getTextRules(); |
|
361 |
|
362 viewer.setSelection(new StructuredSelection(textRules |
|
363 .get(itemIndex))); |
|
364 |
|
365 item = processEditItemAction(); |
|
366 } |
|
367 |
|
368 if (item != null) { |
|
369 // Apply the changes |
|
370 somethingChanged = true; |
|
371 okPressed(); |
|
372 } else { |
|
373 cancelPressed(); |
|
374 } |
|
375 } |
|
376 } |