|
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 |
|
18 package com.nokia.s60tools.memspy.ui.dialogs; |
|
19 |
|
20 import java.util.ArrayList; |
|
21 |
|
22 import org.eclipse.jface.dialogs.IDialogConstants; |
|
23 import org.eclipse.jface.dialogs.IMessageProvider; |
|
24 import org.eclipse.jface.dialogs.TitleAreaDialog; |
|
25 import org.eclipse.jface.viewers.CheckboxTableViewer; |
|
26 import org.eclipse.jface.viewers.ISelectionChangedListener; |
|
27 import org.eclipse.jface.viewers.IStructuredContentProvider; |
|
28 import org.eclipse.jface.viewers.ITableLabelProvider; |
|
29 import org.eclipse.jface.viewers.LabelProvider; |
|
30 import org.eclipse.jface.viewers.SelectionChangedEvent; |
|
31 import org.eclipse.jface.viewers.Viewer; |
|
32 import org.eclipse.swt.SWT; |
|
33 import org.eclipse.swt.events.SelectionEvent; |
|
34 import org.eclipse.swt.events.SelectionListener; |
|
35 import org.eclipse.swt.graphics.Image; |
|
36 import org.eclipse.swt.graphics.Point; |
|
37 import org.eclipse.swt.layout.GridData; |
|
38 import org.eclipse.swt.layout.GridLayout; |
|
39 import org.eclipse.swt.widgets.Button; |
|
40 import org.eclipse.swt.widgets.Composite; |
|
41 import org.eclipse.swt.widgets.Control; |
|
42 import org.eclipse.swt.widgets.Group; |
|
43 import org.eclipse.swt.widgets.Label; |
|
44 import org.eclipse.swt.widgets.MessageBox; |
|
45 import org.eclipse.swt.widgets.Shell; |
|
46 import org.eclipse.swt.widgets.Text; |
|
47 import org.eclipse.ui.PlatformUI; |
|
48 |
|
49 import com.nokia.s60tools.memspy.model.SWMTCategoryConstants; |
|
50 import com.nokia.s60tools.memspy.model.SWMTCategorys; |
|
51 import com.nokia.s60tools.memspy.preferences.MemSpyPreferences; |
|
52 import com.nokia.s60tools.memspy.resources.HelpContextIDs; |
|
53 import com.nokia.s60tools.memspy.resources.ImageKeys; |
|
54 import com.nokia.s60tools.memspy.resources.ImageResourceManager; |
|
55 import com.nokia.s60tools.memspy.util.MemSpyConsole; |
|
56 import com.nokia.s60tools.ui.S60ToolsTable; |
|
57 import com.nokia.s60tools.ui.S60ToolsTableColumnData; |
|
58 import com.nokia.s60tools.ui.S60ToolsTableFactory; |
|
59 import com.nokia.s60tools.ui.S60ToolsUIConstants; |
|
60 |
|
61 |
|
62 |
|
63 /** |
|
64 * Dialog for selecting SWMT categories to be tracked. |
|
65 */ |
|
66 public class SWMTCategoriesDialog extends TitleAreaDialog{ |
|
67 |
|
68 |
|
69 |
|
70 // |
|
71 // Private classes |
|
72 // |
|
73 |
|
74 private static final String HEAP_DATA_THREAD_FILTER_TXT = "Heap Data Thread Filter"; |
|
75 |
|
76 /** |
|
77 * Label provider for table viewer component. |
|
78 */ |
|
79 class SWMTCategoryViewerLabelProvider extends LabelProvider implements ITableLabelProvider{ |
|
80 |
|
81 /* (non-Javadoc) |
|
82 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang.Object, int) |
|
83 */ |
|
84 public Image getColumnImage(Object element, int columnIndex) { |
|
85 return null; // No images used |
|
86 } |
|
87 |
|
88 /* (non-Javadoc) |
|
89 * @see org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang.Object, int) |
|
90 */ |
|
91 public String getColumnText(Object element, int columnIndex) { |
|
92 String label = element.toString(); |
|
93 |
|
94 SWMTCategoryEntry entryData = (SWMTCategoryEntry) element; |
|
95 |
|
96 switch (columnIndex) { |
|
97 |
|
98 case SWMTCategoryEntry.NAME_COLUMN_INDEX: |
|
99 label = entryData.getCategoryName(); |
|
100 break; |
|
101 |
|
102 default: |
|
103 MemSpyConsole.getInstance().println("Unexpected column index: " + columnIndex, MemSpyConsole.MSG_ERROR); //$NON-NLS-1$ //$NON-NLS-2$ |
|
104 break; |
|
105 } |
|
106 |
|
107 return label; |
|
108 } |
|
109 |
|
110 } |
|
111 |
|
112 // |
|
113 // Private constants |
|
114 // |
|
115 |
|
116 /** |
|
117 * Columns in the container area. |
|
118 */ |
|
119 private static final int COLUMN_COUNT = 1; |
|
120 |
|
121 /** |
|
122 * Dialog width. |
|
123 */ |
|
124 private static final int DIALOG_WIDTH = 425; |
|
125 |
|
126 /** |
|
127 * Dialog height. |
|
128 */ |
|
129 private static final int DIALOG_HEIGHT = 550; |
|
130 |
|
131 /** |
|
132 * Percentage as decimal number how much table viewer is taking space horizontally. |
|
133 */ |
|
134 private static final double TABLE_VIEWER_WIDTH_PERCENTAGE = 0.8; |
|
135 |
|
136 /** |
|
137 * Default guiding message shown to the user in add new mode. |
|
138 */ |
|
139 private static final String DEFAULT_MESSAGE = "Set advanced options and tracked SWMT categories."; |
|
140 |
|
141 /** |
|
142 * Complete message shown to the user in add new mode. |
|
143 */ |
|
144 private static final String COMPLETE_MESSAGE = "Press OK to save advanced options and set categories to be tracked"; |
|
145 |
|
146 /** |
|
147 * Error message shown to the user in case no categories are selected. |
|
148 */ |
|
149 private static final String ERROR_MESSAGE = "At least single category must be selected"; |
|
150 |
|
151 /** |
|
152 * UI text for closing Symbian agent |
|
153 */ |
|
154 private static final String CLOSE_MEM_SPY_BETWEEN_CYCLES_TEXT = "Close MemSpy Symbian Agent Between Cycles"; |
|
155 |
|
156 /** |
|
157 * Tip text for closing Symbian agent |
|
158 */ |
|
159 private static final String CLOSE_MEM_SPY_BETWEEN_CYCLES_TIP_TEXT = "Choose if the MemSpy Symbian agent in S60 target is closed between cycles. That is more realistic use case for memory usage point of view."; |
|
160 |
|
161 |
|
162 // |
|
163 // Member data |
|
164 // |
|
165 |
|
166 /** |
|
167 * Flag used to make sure that create() and open() are called in correct order. |
|
168 */ |
|
169 private boolean isCreateCalled = false; |
|
170 |
|
171 |
|
172 // |
|
173 // UI Controls |
|
174 // |
|
175 |
|
176 /** |
|
177 * Container area for individual fields for the user for entering information. |
|
178 */ |
|
179 private Composite container; |
|
180 |
|
181 /** |
|
182 * Reference to OK button that can be disabled/enabled |
|
183 * due to current category selection- |
|
184 */ |
|
185 private Button okActionBtn; |
|
186 |
|
187 /** |
|
188 * Viewer showing currently selected category file entries. |
|
189 */ |
|
190 private CheckboxTableViewer categoryViewer; |
|
191 |
|
192 /** |
|
193 * Selected categories as a result of bitwise OR. |
|
194 */ |
|
195 private int categorySelection = SWMTCategoryConstants.CATEGORY_ALL; |
|
196 |
|
197 //User Heap filter text field |
|
198 private Text heapText; |
|
199 |
|
200 private Button closeBetweenCyclesButton; |
|
201 |
|
202 private Button heapDumpBtn; |
|
203 |
|
204 /** |
|
205 * Constructor. Used to open dialog in order to add new entry. |
|
206 * @param parentShell Parent shell for the dialog. |
|
207 * @param categorySelection integer containing initially selected categories as a result of bitwise OR. |
|
208 */ |
|
209 public SWMTCategoriesDialog(Shell parentShell, int categorySelection) { |
|
210 super(parentShell); |
|
211 this.categorySelection = categorySelection; |
|
212 // Setting banner image |
|
213 String bannerImage = ImageKeys.IMG_WIZARD; |
|
214 setTitleImage(ImageResourceManager.getImage(bannerImage)); |
|
215 } |
|
216 |
|
217 |
|
218 |
|
219 /* (non-Javadoc) |
|
220 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite) |
|
221 */ |
|
222 protected void createButtonsForButtonBar(Composite parent) { |
|
223 createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, |
|
224 true); |
|
225 createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, |
|
226 true); |
|
227 okActionBtn = getButton(IDialogConstants.OK_ID); |
|
228 } |
|
229 |
|
230 /* (non-Javadoc) |
|
231 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) |
|
232 */ |
|
233 protected void configureShell(Shell shell) { |
|
234 super.configureShell(shell); |
|
235 shell.setText("SWMT Categories and Advanced Options"); |
|
236 } |
|
237 |
|
238 /* (non-Javadoc) |
|
239 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) |
|
240 */ |
|
241 protected Control createDialogArea(Composite parent) { |
|
242 |
|
243 Composite dialogAreaComposite = (Composite) super.createDialogArea(parent); |
|
244 |
|
245 // |
|
246 // Creating container and layout for it |
|
247 // |
|
248 container = new Composite(dialogAreaComposite, SWT.NONE); |
|
249 GridLayout gdl = new GridLayout(COLUMN_COUNT, false); |
|
250 // Settings margins according Carbide branding guideline |
|
251 gdl.marginLeft = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
252 gdl.marginRight = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
253 gdl.marginTop = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
254 gdl.marginBottom = S60ToolsUIConstants.MARGIN_BTW_FRAME_AND_CONTENTS; |
|
255 container.setLayout(gdl); |
|
256 container.setLayoutData(new GridData(GridData.FILL_BOTH)); |
|
257 |
|
258 // |
|
259 // Symbian agent options group |
|
260 // |
|
261 |
|
262 createSymbianAgentOptionsGroup(); |
|
263 |
|
264 // |
|
265 // Head dump group |
|
266 // |
|
267 createHeapDumpGroup(); |
|
268 |
|
269 |
|
270 // |
|
271 // Creating table viewer for showing category file entries |
|
272 // |
|
273 |
|
274 categoryViewer = createCategoryCheckBoxTableViewer(container); |
|
275 GridData categoryViewerGd = new GridData(GridData.FILL_BOTH); |
|
276 // Spanning as many rows as there are actions buttons on the right |
|
277 categoryViewerGd.verticalSpan = 3; |
|
278 categoryViewerGd.widthHint = (int) (TABLE_VIEWER_WIDTH_PERCENTAGE * DIALOG_WIDTH); |
|
279 categoryViewer.getControl().setLayoutData(categoryViewerGd); |
|
280 categoryViewer.setSorter(new SWMTCategoryEntryTableViewerSorter()); |
|
281 // Adding selection change listener |
|
282 categoryViewer.addSelectionChangedListener(new ISelectionChangedListener(){ |
|
283 |
|
284 /* (non-Javadoc) |
|
285 * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent) |
|
286 */ |
|
287 public void selectionChanged(SelectionChangedEvent event) { |
|
288 notifySelectionChanged(); |
|
289 } |
|
290 |
|
291 }); |
|
292 |
|
293 // |
|
294 // Setting providers for table viewer |
|
295 // |
|
296 |
|
297 // Creating content provider |
|
298 GategoryProvider categoryViewerContentProvider = new GategoryProvider(); |
|
299 // Setting content provider |
|
300 categoryViewer.setContentProvider(categoryViewerContentProvider); |
|
301 categoryViewer.setInput(categoryViewerContentProvider); |
|
302 |
|
303 // Label provider |
|
304 categoryViewer.setLabelProvider(new SWMTCategoryViewerLabelProvider()); |
|
305 |
|
306 // Setting initial category selection state |
|
307 InitializeSelectionState(); |
|
308 |
|
309 // Setting context-sensitive help ID |
|
310 PlatformUI.getWorkbench().getHelpSystem().setHelp( dialogAreaComposite, HelpContextIDs.MEMSPY_IMPORT_SWMT_CATEGORIES_DIALOG); |
|
311 |
|
312 // Dialog are composite ready |
|
313 return dialogAreaComposite; |
|
314 } |
|
315 |
|
316 |
|
317 /** |
|
318 * Private class to provide content for category viewer |
|
319 */ |
|
320 class GategoryProvider implements IStructuredContentProvider { |
|
321 |
|
322 /* (non-Javadoc) |
|
323 * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object) |
|
324 */ |
|
325 public Object[] getElements(Object inputElement) { |
|
326 return SWMTCategorys.getInstance().getCategoryEntries().toArray(); |
|
327 } |
|
328 |
|
329 /* (non-Javadoc) |
|
330 * @see org.eclipse.jface.viewers.IContentProvider#dispose() |
|
331 */ |
|
332 public void dispose() { |
|
333 // Not needed but needs to be implemented |
|
334 } |
|
335 |
|
336 public void inputChanged(Viewer viewer, Object oldInput, |
|
337 Object newInput) { |
|
338 // Not used but needs to be implemented |
|
339 } |
|
340 |
|
341 }; |
|
342 |
|
343 /** |
|
344 * Creates group for Symbian agent options |
|
345 */ |
|
346 private void createSymbianAgentOptionsGroup() { |
|
347 Group closeSymbianGroup = new Group(container, SWT.SHADOW_NONE); |
|
348 closeSymbianGroup.setText("Symbian Agent Options"); |
|
349 GridLayout closegl = new GridLayout(2, false); |
|
350 GridData closegd = new GridData(GridData.FILL_BOTH); |
|
351 closeSymbianGroup.setLayout(closegl); |
|
352 closeSymbianGroup.setLayoutData(closegd); |
|
353 |
|
354 closeBetweenCyclesButton = new Button(closeSymbianGroup, SWT.CHECK); |
|
355 GridData closeLayoutData = new GridData(GridData.VERTICAL_ALIGN_END); |
|
356 closeBetweenCyclesButton.setLayoutData( closeLayoutData); |
|
357 closeBetweenCyclesButton.setToolTipText(CLOSE_MEM_SPY_BETWEEN_CYCLES_TIP_TEXT); |
|
358 boolean isToBeClosedBetweenCycles = MemSpyPreferences.isCloseSymbianAgentBetweenCyclesSelected(); |
|
359 closeBetweenCyclesButton.setSelection(isToBeClosedBetweenCycles); |
|
360 |
|
361 //Label for button, separate label is used because setting text to button wont align text to same vertical |
|
362 //position than next label. |
|
363 Label closeBetweenIntervalsLabel = new Label(closeSymbianGroup, SWT.LEFT ); |
|
364 GridData closeBetweenLabelData = new GridData(GridData.VERTICAL_ALIGN_CENTER); |
|
365 closeBetweenIntervalsLabel.setText( CLOSE_MEM_SPY_BETWEEN_CYCLES_TEXT ); |
|
366 closeBetweenIntervalsLabel.setLayoutData(closeBetweenLabelData); |
|
367 |
|
368 } |
|
369 |
|
370 |
|
371 /** |
|
372 * Creates group for Head Dumps |
|
373 */ |
|
374 private void createHeapDumpGroup() { |
|
375 // |
|
376 // Head dump group |
|
377 // |
|
378 Group headDumpGroup = new Group(container, SWT.SHADOW_NONE); |
|
379 headDumpGroup.setText("Heap Dumps During SWMT Logging"); |
|
380 GridLayout hdgl = new GridLayout(2, false); |
|
381 GridData hdgd = new GridData(GridData.FILL_BOTH); |
|
382 headDumpGroup.setLayout(hdgl); |
|
383 headDumpGroup.setLayoutData(hdgd); |
|
384 |
|
385 heapDumpBtn = new Button(headDumpGroup, SWT.CHECK); |
|
386 heapDumpBtn.setText("Get Heap Dumps for Threads to Analyse with Heap Analyser"); |
|
387 heapDumpBtn.setToolTipText("Set if Heap Dumps is to be received for Threads during SWMT logging"); |
|
388 heapDumpBtn.addSelectionListener(new HeadDumpSelectionListener()); |
|
389 heapDumpBtn.setSelection(MemSpyPreferences.isSWMTHeapDumpSelected()); |
|
390 GridData hdBtnGd = new GridData(); |
|
391 hdBtnGd.horizontalSpan = 2; |
|
392 heapDumpBtn.setLayoutData(hdBtnGd); |
|
393 |
|
394 //Label for Heap gategory limit |
|
395 Label heapTextLabel = new Label(headDumpGroup, SWT.LEFT ); |
|
396 heapTextLabel.setText(HEAP_DATA_THREAD_FILTER_TXT + ":"); |
|
397 String heapFilterToolTipText = "When filter string is specified, only Threads that contain text specified will be tracked."; |
|
398 heapTextLabel.setToolTipText(heapFilterToolTipText); |
|
399 GridData heapTextLimitLayoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER); |
|
400 heapTextLabel.setLayoutData( heapTextLimitLayoutData ); |
|
401 |
|
402 //heap limit text |
|
403 heapText = new Text(headDumpGroup, SWT.LEFT | SWT.BORDER | SWT.BORDER); |
|
404 heapText.setTextLimit(120);//Text limit 128 specified in S60 side |
|
405 GridData heapTextLayoutData = new GridData(GridData.VERTICAL_ALIGN_CENTER); |
|
406 heapTextLayoutData.widthHint = 140; |
|
407 heapText.setLayoutData( heapTextLayoutData ); |
|
408 heapText.setToolTipText(heapFilterToolTipText); |
|
409 if(heapDumpBtn.getSelection()){ |
|
410 heapText.setText(MemSpyPreferences.getSWMTHeapNameFilter()); |
|
411 }else{ |
|
412 heapText.setEnabled(false); |
|
413 } |
|
414 } |
|
415 |
|
416 /** |
|
417 * Listener for Heap Dumps button, updates preferences and text in Heap Dumps group. |
|
418 */ |
|
419 private class HeadDumpSelectionListener implements SelectionListener{ |
|
420 |
|
421 /* (non-Javadoc) |
|
422 * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent) |
|
423 */ |
|
424 public void widgetDefaultSelected(SelectionEvent e) { |
|
425 // not needed |
|
426 |
|
427 } |
|
428 |
|
429 /* |
|
430 * Change heapText and save preferences |
|
431 * (non-Javadoc) |
|
432 * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent) |
|
433 */ |
|
434 public void widgetSelected(SelectionEvent e) { |
|
435 boolean selection = heapDumpBtn.getSelection(); |
|
436 if(selection){ |
|
437 heapText.setEnabled(true); |
|
438 heapText.setText(MemSpyPreferences.getSWMTHeapNameFilter()); |
|
439 }else{ |
|
440 heapText.setText(""); |
|
441 heapText.setEnabled(false); |
|
442 } |
|
443 } |
|
444 |
|
445 |
|
446 } |
|
447 |
|
448 /** |
|
449 * Save the heap filter text if enabled |
|
450 */ |
|
451 private void saveHeapFilterText() { |
|
452 //Check if heaptext is enabled, if it is, saving text to preferences |
|
453 if(heapText.isEnabled()){ |
|
454 String heapFilterText = heapText.getText().trim(); |
|
455 MemSpyPreferences.setSWMTHeapNameFilter(heapFilterText); |
|
456 } |
|
457 } |
|
458 /** |
|
459 * Save the Close between cycles selection |
|
460 */ |
|
461 private void saveCloseS60AgentBetweenCycles() { |
|
462 boolean selection = closeBetweenCyclesButton.getSelection(); |
|
463 // User selects to close MemSpy S60 application between cycles |
|
464 MemSpyPreferences.setCloseSymbianAgentBetweenCycles(selection); |
|
465 } |
|
466 /** |
|
467 * Save the heap dump selection |
|
468 */ |
|
469 private void saveHeapDumpSelection() { |
|
470 boolean selection = heapDumpBtn.getSelection(); |
|
471 MemSpyPreferences.setSWMTHeapDumpSelected(selection); |
|
472 } |
|
473 |
|
474 |
|
475 |
|
476 /** |
|
477 * Sets initial selection state for entries |
|
478 */ |
|
479 private void InitializeSelectionState() { |
|
480 int size = SWMTCategorys.getInstance().getCategoryEntries().size(); |
|
481 for (int i = 0; i < size; i++) { |
|
482 SWMTCategoryEntry entry = (SWMTCategoryEntry) categoryViewer.getElementAt(i); |
|
483 int isCategoryBitUp = categorySelection & entry.getCategoryId(); |
|
484 if(isCategoryBitUp != 0){ |
|
485 categoryViewer.setChecked(entry, true); |
|
486 } |
|
487 } |
|
488 } |
|
489 |
|
490 /* (non-Javadoc) |
|
491 * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize() |
|
492 */ |
|
493 protected Point getInitialSize() { |
|
494 return new Point(DIALOG_WIDTH, DIALOG_HEIGHT); |
|
495 } |
|
496 |
|
497 /* (non-Javadoc) |
|
498 * @see org.eclipse.jface.dialogs.Dialog#create() |
|
499 */ |
|
500 public void create() { |
|
501 super.create(); |
|
502 // Currently just does creation by super call and stores status |
|
503 isCreateCalled = true; |
|
504 } |
|
505 |
|
506 /* (non-Javadoc) |
|
507 * @see org.eclipse.jface.dialogs.Dialog#okPressed() |
|
508 */ |
|
509 protected void okPressed() { |
|
510 |
|
511 if(heapDumpBtn.getSelection()){ |
|
512 if(heapText.getText().trim().equals("")){ |
|
513 System.out.println("DEBUG: WARNING! Empty heap filter text!"); |
|
514 MessageBox box = new MessageBox(getShell(),SWT.ICON_WARNING | SWT.YES | SWT.NO); |
|
515 String warningMsg = "Empty \"" +HEAP_DATA_THREAD_FILTER_TXT |
|
516 + "\" field causes huge amount of data to be traced and tracing may take a very long time. " |
|
517 +"It is highly recommended to use \"" +HEAP_DATA_THREAD_FILTER_TXT |
|
518 + "\"." |
|
519 +"\n\nDo you want to continue anyway?"; |
|
520 box.setMessage(warningMsg); |
|
521 box.setText("Using \"" +HEAP_DATA_THREAD_FILTER_TXT |
|
522 + "\" is recommended"); |
|
523 int yes_no = box.open(); |
|
524 //If user does not want to continue but cancel, returning, otherwise just continue to save all data and exit |
|
525 if(yes_no == SWT.NO){ |
|
526 return; |
|
527 } |
|
528 |
|
529 } |
|
530 } |
|
531 |
|
532 saveHeapFilterText(); |
|
533 saveCloseS60AgentBetweenCycles(); |
|
534 saveHeapDumpSelection(); |
|
535 super.close(); |
|
536 } |
|
537 |
|
538 /* (non-Javadoc) |
|
539 * @see org.eclipse.jface.window.Window#open() |
|
540 */ |
|
541 public int open(){ |
|
542 try { |
|
543 // Making sure that create is called |
|
544 if(!isCreateCalled){ |
|
545 create(); |
|
546 } |
|
547 showDefaultMessage(); |
|
548 } catch (Exception e) { |
|
549 e.printStackTrace(); |
|
550 } |
|
551 return super.open(); |
|
552 } |
|
553 |
|
554 /** |
|
555 * Resets possible error messages and show the default message. |
|
556 */ |
|
557 private void showDefaultMessage() { |
|
558 setErrorMessage(null); |
|
559 setMessage(DEFAULT_MESSAGE, IMessageProvider.INFORMATION); |
|
560 } |
|
561 |
|
562 /** |
|
563 * Informs user that parameters are valid and dialog can be |
|
564 * dismissed with OK button.. |
|
565 */ |
|
566 private void setCompleteOkMessage() { |
|
567 setErrorMessage(null); |
|
568 setMessage(COMPLETE_MESSAGE, IMessageProvider.INFORMATION); |
|
569 } |
|
570 |
|
571 /** |
|
572 * Shows error message in case no categories are selected. |
|
573 */ |
|
574 private void showErrorMessage() { |
|
575 setErrorMessage(ERROR_MESSAGE); |
|
576 setMessage(null); |
|
577 } |
|
578 |
|
579 /** |
|
580 * Disables OK button. |
|
581 * This method is guarded against call during construction |
|
582 * when button row has not been created yet and widget is <code>null</code>. |
|
583 */ |
|
584 private void disableOk() { |
|
585 if(okActionBtn != null){ |
|
586 okActionBtn.setEnabled(false); |
|
587 } |
|
588 } |
|
589 |
|
590 /** |
|
591 * Enables OK button. |
|
592 * This method is guarded against call during construction |
|
593 * when button row has not been created yet and widget is <code>null</code>. |
|
594 */ |
|
595 private void enableOk() { |
|
596 if(okActionBtn != null){ |
|
597 okActionBtn.setEnabled(true); |
|
598 } |
|
599 } |
|
600 |
|
601 /** |
|
602 * Updates buttons statuses according the current selection |
|
603 * status of table entry viewer contents and refreshes contents. |
|
604 */ |
|
605 private void notifySelectionChanged() { |
|
606 Object[] selectedCategoryEntries = getSelectedCategoryEntries(); |
|
607 if(selectedCategoryEntries.length > 0){ |
|
608 updateSelectedCategories(selectedCategoryEntries); |
|
609 enableOk(); |
|
610 setCompleteOkMessage(); |
|
611 } |
|
612 else{ |
|
613 disableOk(); |
|
614 showErrorMessage(); |
|
615 } |
|
616 categoryViewer.refresh(); |
|
617 } |
|
618 |
|
619 /** |
|
620 * Creates checkbox viewer component for showing available SWMT categories. |
|
621 * @param parent Parent composite for the created composite. |
|
622 * @return New <code>CheckboxTableViewer</code> object instance. |
|
623 */ |
|
624 protected CheckboxTableViewer createCategoryCheckBoxTableViewer(Composite parent) { |
|
625 |
|
626 ArrayList<S60ToolsTableColumnData> columnDataArr = new ArrayList<S60ToolsTableColumnData>(); |
|
627 |
|
628 // |
|
629 // NOTE: Column indices must start from zero (0) and |
|
630 // the columns must be added in ascending numeric |
|
631 // order. |
|
632 // |
|
633 columnDataArr.add(new S60ToolsTableColumnData("Category", //$NON-NLS-1$ |
|
634 350, |
|
635 SWMTCategoryEntry.NAME_COLUMN_INDEX, |
|
636 SWMTCategoryEntryTableViewerSorter.CRITERIA_NAME)); |
|
637 |
|
638 S60ToolsTableColumnData[] arr |
|
639 = columnDataArr.toArray( |
|
640 new S60ToolsTableColumnData[0]); |
|
641 |
|
642 S60ToolsTable tbl = S60ToolsTableFactory.createCheckboxTable(parent, arr); |
|
643 |
|
644 CheckboxTableViewer tblViewer = new CheckboxTableViewer(tbl.getTableInstance()); |
|
645 tbl.setHostingViewer(tblViewer); |
|
646 |
|
647 return tblViewer; |
|
648 } |
|
649 |
|
650 /** |
|
651 * Returns currently selected categories. |
|
652 * @return currently selected categories |
|
653 */ |
|
654 private Object[] getSelectedCategoryEntries() { |
|
655 return categoryViewer.getCheckedElements(); |
|
656 } |
|
657 |
|
658 /** |
|
659 * Stores currently selected categories combined with bitwise as a single integer. |
|
660 * @param selectedCategoryEntries array of selected category entries |
|
661 */ |
|
662 private void updateSelectedCategories(Object[] selectedCategoryEntries) { |
|
663 // Re-initializing category selection |
|
664 categorySelection = SWMTCategoryConstants.CATEGORY_NONE; |
|
665 for (int i = 0; i < selectedCategoryEntries.length; i++) { |
|
666 SWMTCategoryEntry categoryEntry = (SWMTCategoryEntry) selectedCategoryEntries[i]; |
|
667 categorySelection = categorySelection | categoryEntry.getCategoryId(); |
|
668 } |
|
669 } |
|
670 |
|
671 /** |
|
672 * Returns currently selected categories combined with bitwise as a single integer. |
|
673 * @return currently selected categories combined with bitwise as a single integer. |
|
674 */ |
|
675 public int getSelectedCategories() { |
|
676 return categorySelection; |
|
677 } |
|
678 |
|
679 } |