18 package com.nokia.s60tools.crashanalyser.ui.views; |
18 package com.nokia.s60tools.crashanalyser.ui.views; |
19 |
19 |
20 import org.eclipse.swt.widgets.Shell; |
20 import org.eclipse.swt.widgets.Shell; |
21 import org.eclipse.swt.widgets.Composite; |
21 import org.eclipse.swt.widgets.Composite; |
22 import org.eclipse.swt.widgets.Display; |
22 import org.eclipse.swt.widgets.Display; |
|
23 import org.eclipse.swt.widgets.Tree; |
|
24 import org.eclipse.swt.widgets.TreeColumn; |
23 import org.eclipse.swt.browser.Browser; |
25 import org.eclipse.swt.browser.Browser; |
24 import org.eclipse.swt.widgets.Menu; |
26 import org.eclipse.swt.widgets.Menu; |
25 import org.eclipse.swt.widgets.MessageBox; |
27 import org.eclipse.swt.widgets.MessageBox; |
26 import org.eclipse.swt.SWT; |
28 import org.eclipse.swt.SWT; |
27 import org.eclipse.swt.custom.SashForm; |
29 import org.eclipse.swt.custom.SashForm; |
32 import org.eclipse.jface.wizard.WizardDialog; |
34 import org.eclipse.jface.wizard.WizardDialog; |
33 import org.eclipse.ui.*; |
35 import org.eclipse.ui.*; |
34 import org.eclipse.ui.part.*; |
36 import org.eclipse.ui.part.*; |
35 import org.eclipse.swt.dnd.*; |
37 import org.eclipse.swt.dnd.*; |
36 |
38 |
37 import com.nokia.s60tools.ui.*; |
39 import com.nokia.s60tools.ui.actions.OpenPreferencePageAction; |
38 import com.nokia.s60tools.util.resource.*; |
40 import com.nokia.s60tools.util.resource.*; |
39 import com.nokia.s60tools.crashanalyser.model.*; |
41 import com.nokia.s60tools.crashanalyser.model.*; |
40 import com.nokia.s60tools.crashanalyser.plugin.*; |
42 import com.nokia.s60tools.crashanalyser.plugin.*; |
41 import com.nokia.s60tools.crashanalyser.resources.*; |
43 import com.nokia.s60tools.crashanalyser.resources.*; |
42 import com.nokia.s60tools.crashanalyser.files.*; |
44 import com.nokia.s60tools.crashanalyser.files.*; |
|
45 import com.nokia.s60tools.crashanalyser.ui.preferences.CrashAnalyserPreferences; |
43 import com.nokia.s60tools.crashanalyser.ui.wizards.*; |
46 import com.nokia.s60tools.crashanalyser.ui.wizards.*; |
44 import com.nokia.s60tools.crashanalyser.ui.dialogs.*; |
47 import com.nokia.s60tools.crashanalyser.ui.dialogs.*; |
45 import com.nokia.s60tools.crashanalyser.data.*; |
48 import com.nokia.s60tools.crashanalyser.data.*; |
46 import com.nokia.s60tools.crashanalyser.interfaces.*; |
49 import com.nokia.s60tools.crashanalyser.interfaces.*; |
|
50 |
47 import java.io.*; |
51 import java.io.*; |
48 import java.util.*; |
52 import java.util.*; |
49 |
53 |
50 /** |
54 /** |
51 * Crash Analyser's main view class. Shows Crash files in a table. |
55 * Crash Analyser's main view class. Shows Crash files in a table. |
61 /** |
65 /** |
62 * We can get view ID at runtime once the view is instantiated, but we |
66 * We can get view ID at runtime once the view is instantiated, but we |
63 * also need static access to ID in order to be able to invoke the view. |
67 * also need static access to ID in order to be able to invoke the view. |
64 */ |
68 */ |
65 public static final String ID = "com.nokia.s60tools.crashanalyser.ui.views.MainView"; //$NON-NLS-1$ |
69 public static final String ID = "com.nokia.s60tools.crashanalyser.ui.views.MainView"; //$NON-NLS-1$ |
66 private TableViewer tableViewerCrashFiles; |
70 //private TableViewer tableViewerCrashFiles; |
|
71 private TreeViewer treeViewerCrashFiles; |
|
72 /** |
|
73 * Open the preferences |
|
74 */ |
|
75 private Action mainMenuActionOpenPreferences; |
|
76 |
67 private Action actionDoubleClick; |
77 private Action actionDoubleClick; |
68 private Action actionOpenWizard; |
78 private Action actionOpenWizard; |
69 private Action actionDecode; |
79 private Action actionDecode; |
70 private Action actionDeleteFiles; |
80 private Action actionDeleteFiles; |
71 private Action actionPanicLibrary; |
81 private Action actionPanicLibrary; |
85 private CrashAnalyserFile fileToBeShown = null; |
95 private CrashAnalyserFile fileToBeShown = null; |
86 private CrashAnalyserWizard wizard = null; |
96 private CrashAnalyserWizard wizard = null; |
87 |
97 |
88 |
98 |
89 public void selectionChanged(SelectionChangedEvent arg0) { |
99 public void selectionChanged(SelectionChangedEvent arg0) { |
90 ISelection selection = tableViewerCrashFiles.getSelection(); |
100 ISelection selection = treeViewerCrashFiles.getSelection(); |
91 |
101 |
92 // no files selected, don't show description |
102 // no files selected, don't show description |
93 if (selection == null || selection.isEmpty()) { |
103 if (selection == null || selection.isEmpty()) { |
94 browserPanicDescription.setText(""); |
104 browserPanicDescription.setText(""); |
|
105 actionDecode.setEnabled(false); |
|
106 actionDeleteFiles.setEnabled(false); |
95 return; |
107 return; |
96 } |
108 } |
|
109 |
97 |
110 |
98 @SuppressWarnings("unchecked") |
111 @SuppressWarnings("unchecked") |
99 Iterator<CrashFileBundle> i = ((IStructuredSelection)selection).iterator(); |
112 Iterator<CrashFileBundle> i = ((IStructuredSelection)selection).iterator(); |
100 while (i.hasNext()) { |
113 while (i.hasNext()) { |
101 CrashFileBundle cFileBundle = i.next(); |
114 CrashFileBundle cFileBundle = i.next(); |
146 * This is a callback that will allow us |
161 * This is a callback that will allow us |
147 * to create the viewer and initialize it. |
162 * to create the viewer and initialize it. |
148 */ |
163 */ |
149 public void createPartControl(Composite parent) { |
164 public void createPartControl(Composite parent) { |
150 SashForm sashFormMain = new SashForm(parent, SWT.HORIZONTAL); |
165 SashForm sashFormMain = new SashForm(parent, SWT.HORIZONTAL); |
151 createCrashFilesListViewTableViewer(sashFormMain); |
166 //createCrashFilesListViewTableViewer(sashFormMain); |
|
167 createCrashFilesListViewTreeViewer(sashFormMain); |
152 createPanicsViewer(sashFormMain); |
168 createPanicsViewer(sashFormMain); |
153 sashFormMain.setWeights(new int[] {2,1}); |
169 sashFormMain.setWeights(new int[] {2,1}); |
154 |
170 |
155 makeActions(); |
171 makeActions(); |
156 hookContextMenu(); |
172 hookContextMenu(); |
157 hookDoubleClickAction(); |
173 hookDoubleClickAction(); |
158 contributeToActionBars(); |
174 contributeToActionBars(); |
159 |
175 |
160 actionOpenWizard.setEnabled(false); |
176 actionOpenWizard.setEnabled(false); |
|
177 mainMenuActionOpenPreferences.setEnabled(false); |
161 actionDecode.setEnabled(false); |
178 actionDecode.setEnabled(false); |
162 actionPanicLibrary.setEnabled(false); |
179 actionPanicLibrary.setEnabled(false); |
163 errorLibrary = ErrorLibrary.getInstance(this); |
180 errorLibrary = ErrorLibrary.getInstance(this); |
164 |
181 |
165 try { |
182 try { |
166 PlatformUI.getWorkbench().getHelpSystem().setHelp(tableViewerCrashFiles.getControl(), |
183 PlatformUI.getWorkbench().getHelpSystem().setHelp(treeViewerCrashFiles.getControl(), |
167 HelpContextIDs.CRASH_ANALYSER_HELP_MAIN_VIEW); |
184 HelpContextIDs.CRASH_ANALYSER_HELP_MAIN_VIEW); |
168 } catch (Exception e) { |
185 } catch (Exception e) { |
169 e.printStackTrace(); |
186 e.printStackTrace(); |
170 } |
187 } |
171 } |
188 } |
237 } |
254 } |
238 |
255 |
239 /** |
256 /** |
240 * Creates the MainView table which is used for showing crash files |
257 * Creates the MainView table which is used for showing crash files |
241 */ |
258 */ |
242 private void createCrashFilesListViewTableViewer(Composite parent) { |
259 private void createCrashFilesListViewTreeViewer(Composite parent) { |
243 SashForm sashFormCrashFiles = new SashForm(parent, SWT.VERTICAL); |
260 SashForm sashFormCrashFiles = new SashForm(parent, SWT.VERTICAL); |
244 |
261 |
245 List<S60ToolsTableColumnData> columnDataArr = new ArrayList<S60ToolsTableColumnData>(); |
262 Tree tree = new Tree(sashFormCrashFiles, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); |
246 |
263 |
247 columnDataArr.add(new S60ToolsTableColumnData("Crash File", 690, 0)); |
264 tree.setHeaderVisible(true); |
248 columnDataArr.add(new S60ToolsTableColumnData("Panic Code", 70, 0)); |
265 TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); |
249 columnDataArr.add(new S60ToolsTableColumnData("Panic Category", 90, 0)); |
266 column1.setText("Time"); |
250 columnDataArr.add(new S60ToolsTableColumnData("Thread", 250, 0)); |
267 column1.setWidth(150); |
251 columnDataArr.add(new S60ToolsTableColumnData("Time", 130, 0)); |
268 |
252 |
269 TreeColumn column2 = new TreeColumn(tree, SWT.LEFT); |
253 S60ToolsTableColumnData[] arr |
270 column2.setText("Thread"); |
254 = columnDataArr.toArray(new S60ToolsTableColumnData[columnDataArr.size()]); |
271 column2.setWidth(250); |
255 |
272 |
256 S60ToolsTable tbl = S60ToolsTableFactory.create(sashFormCrashFiles, arr); |
273 TreeColumn column3 = new TreeColumn(tree, SWT.LEFT); |
257 |
274 column3.setText("Panic Category"); |
258 TableViewer tblViewer = new TableViewer(tbl.getTableInstance()); |
275 column3.setWidth(90); |
259 tbl.setHostingViewer(tblViewer); |
276 |
260 tblViewer.addDropSupport(DND.DROP_COPY, new Transfer[] {FileTransfer.getInstance()}, this); |
277 TreeColumn column4 = new TreeColumn(tree, SWT.LEFT); |
|
278 column4.setText("Panic Code"); |
|
279 column4.setWidth(70); |
|
280 |
|
281 TreeColumn column5 = new TreeColumn(tree, SWT.LEFT); |
|
282 column5.setText("Crash File"); |
|
283 column5.setWidth(690); |
|
284 |
|
285 TreeViewer treeViewer = new TreeViewer(tree); |
|
286 treeViewer.addDropSupport(DND.DROP_COPY, new Transfer[] {FileTransfer.getInstance()}, this); |
261 |
287 |
262 contentProvider = new MainViewContentProvider(this); |
288 contentProvider = new MainViewContentProvider(this); |
263 tblViewer.setContentProvider(contentProvider); |
289 treeViewer.setContentProvider(contentProvider); |
264 tblViewer.setLabelProvider(new MainViewLabelProvider()); |
290 treeViewer.setLabelProvider(new MainViewLabelProvider()); |
265 tblViewer.setSorter(new ViewerSorter()); |
291 treeViewer.setSorter(new ViewerSorter()); |
266 tblViewer.setInput(getViewSite()); |
292 treeViewer.setInput(getViewSite()); |
267 tblViewer.addSelectionChangedListener(this); |
293 treeViewer.addSelectionChangedListener(this); |
268 |
294 treeViewer.expandAll(); |
269 tableViewerCrashFiles = tblViewer; |
295 treeViewerCrashFiles = treeViewer; |
270 } |
296 } |
271 |
297 |
272 /** |
298 /** |
273 * Creates the right side view of the MainView. Contains a browser which |
299 * Creates the right side view of the MainView. Contains a browser which |
274 * is used for showing information about a selected file in MainView table. |
300 * is used for showing information about a selected file in MainView table. |
275 */ |
301 */ |
276 private void createPanicsViewer(Composite parent) { |
302 private void createPanicsViewer(Composite parent) { |
328 /** |
354 /** |
329 * Fill pull down menu |
355 * Fill pull down menu |
330 */ |
356 */ |
331 private void fillLocalPullDown(IMenuManager manager) { |
357 private void fillLocalPullDown(IMenuManager manager) { |
332 manager.add(actionOpenWizard); |
358 manager.add(actionOpenWizard); |
|
359 manager.add(mainMenuActionOpenPreferences); |
333 manager.add(actionDecode); |
360 manager.add(actionDecode); |
334 manager.add(actionDeleteFiles); |
361 manager.add(actionDeleteFiles); |
335 manager.add(actionPanicLibrary); |
362 manager.add(actionPanicLibrary); |
336 MenuManager exportMenu = getExportMenu(true); |
363 MenuManager exportMenu = getExportMenu(true); |
337 if (exportMenu != null) |
364 if (exportMenu != null) |
369 * @return Export menu if it can be show, null if it can't |
397 * @return Export menu if it can be show, null if it can't |
370 */ |
398 */ |
371 private MenuManager getExportMenu(boolean showAlways) { |
399 private MenuManager getExportMenu(boolean showAlways) { |
372 MenuManager subMenuExport = new MenuManager("Export"); |
400 MenuManager subMenuExport = new MenuManager("Export"); |
373 |
401 |
374 ISelection selection = tableViewerCrashFiles.getSelection(); |
402 ISelection selection = treeViewerCrashFiles.getSelection(); |
375 // if no files are selected, don't show export menu |
403 // if no files are selected, don't show export menu |
376 if (!showAlways && (selection == null || selection.isEmpty())) |
404 if (!showAlways && (selection == null || selection.isEmpty())) |
377 return null; |
405 return null; |
378 |
406 |
379 boolean allFilesContainsXml = true; |
407 boolean allFilesContainsXml = true; |
628 } |
662 } |
629 }; |
663 }; |
630 actionDecode.setText("Decode Files..."); |
664 actionDecode.setText("Decode Files..."); |
631 actionDecode.setToolTipText("Decode Selected Files"); |
665 actionDecode.setToolTipText("Decode Selected Files"); |
632 actionDecode.setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.DECODE_FILES)); |
666 actionDecode.setImageDescriptor(ImageResourceManager.getImageDescriptor(ImageKeys.DECODE_FILES)); |
|
667 actionDecode.setEnabled(false); |
633 } |
668 } |
634 |
669 |
635 /** |
670 /** |
636 * Delete Files button |
671 * Delete Files button |
637 */ |
672 */ |
638 private void makeDeleteFilesAction() { |
673 private void makeDeleteFilesAction() { |
639 // Delete file button |
674 // Delete file button |
640 actionDeleteFiles = new Action() { |
675 actionDeleteFiles = new Action() { |
641 public void run() { |
676 public void run() { |
642 ISelection selection = tableViewerCrashFiles.getSelection(); |
677 ISelection selection = treeViewerCrashFiles.getSelection(); |
643 if (selection == null || selection.isEmpty()) |
678 if (selection == null || selection.isEmpty()) |
644 return; |
679 return; |
645 |
680 |
646 // Confirm file delete |
681 // Confirm file delete |
647 MessageBox messageBox = new MessageBox(tableViewerCrashFiles.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); |
682 MessageBox messageBox = new MessageBox(treeViewerCrashFiles.getControl().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.NO); |
648 messageBox.setText("Crash Analyser - Delete Files"); |
683 messageBox.setText("Crash Analyser - Remove Files"); |
649 messageBox.setMessage("Are you sure you want to delete selected files?"); |
684 messageBox.setMessage("Are you sure you want to remove selected files?"); |
650 int buttonID = messageBox.open(); |
685 int buttonID = messageBox.open(); |
651 if (buttonID == SWT.YES) { |
686 if (buttonID == SWT.YES) { |
652 // go through all selected files and remove them |
687 // go through all selected files and remove them |
653 List<CrashFileBundle> closeFiles = new ArrayList<CrashFileBundle>(); |
688 List<CrashFileBundle> closeFiles = new ArrayList<CrashFileBundle>(); |
654 @SuppressWarnings("unchecked") |
689 @SuppressWarnings("unchecked") |
663 EditorHandler.closeEditors(closeFiles); |
698 EditorHandler.closeEditors(closeFiles); |
664 contentProvider.refresh(); |
699 contentProvider.refresh(); |
665 } |
700 } |
666 |
701 |
667 // All items were removed, add empty item |
702 // All items were removed, add empty item |
668 if (tableViewerCrashFiles.getTable().getItemCount() == 0) { |
703 if (treeViewerCrashFiles.getTree().getItemCount() == 0) {//.getTable().getItemCount() == 0) { |
669 CrashFileBundle empty = new CrashFileBundle(true); |
704 CrashFileBundle empty = new CrashFileBundle(true); |
670 tableViewerCrashFiles.add(empty); |
705 treeViewerCrashFiles.add(empty, null); |
671 } |
706 } |
672 } |
707 } |
673 }; |
708 }; |
674 actionDeleteFiles.setText("Delete Files"); |
709 actionDeleteFiles.setText("Remove Files"); |
675 actionDeleteFiles.setToolTipText("Delete Selected Files"); |
710 actionDeleteFiles.setToolTipText("Remove Selected Files"); |
676 actionDeleteFiles.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); |
711 actionDeleteFiles.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_DELETE)); |
|
712 actionDeleteFiles.setEnabled(false); |
677 } |
713 } |
678 |
714 |
679 /** |
715 /** |
680 * Shows a message box with given message |
716 * Shows a message box with given message |
681 * @param message |
717 * @param message |
682 */ |
718 */ |
683 private void showMessage(String message) { |
719 private void showMessage(String message) { |
684 MessageDialog.openInformation( |
720 MessageDialog.openInformation( |
685 tableViewerCrashFiles.getControl().getShell(), |
721 treeViewerCrashFiles.getControl().getShell(), |
686 "Crash Analyser", |
722 "Crash Analyser", |
687 message); |
723 message); |
688 } |
724 } |
689 |
725 |
690 /** |
726 /** |
710 /** |
746 /** |
711 * Returns a shell |
747 * Returns a shell |
712 * @return a shell |
748 * @return a shell |
713 */ |
749 */ |
714 private Shell getShell() { |
750 private Shell getShell() { |
715 return tableViewerCrashFiles.getControl().getShell(); |
751 return treeViewerCrashFiles.getControl().getShell(); |
716 } |
752 } |
717 |
753 |
718 /** |
754 /** |
719 * Passing the focus request to the viewer's control. |
755 * Passing the focus request to the viewer's control. |
720 */ |
756 */ |
721 public void setFocus() { |
757 public void setFocus() { |
722 tableViewerCrashFiles.getControl().setFocus(); |
758 treeViewerCrashFiles.getControl().setFocus(); |
723 } |
759 } |
724 |
760 |
725 /** |
761 /** |
726 * When wizard is finished, wizard passes decoder engine to MainView so that |
762 * When wizard is finished, wizard passes decoder engine to MainView so that |
727 * MainView can start decoding process and register itself as the progress listener. |
763 * MainView can start decoding process and register itself as the progress listener. |
808 */ |
845 */ |
809 public void decodingFinished(String error, CrashAnalyserFile caFile) { |
846 public void decodingFinished(String error, CrashAnalyserFile caFile) { |
810 disableUIForImport(false); |
847 disableUIForImport(false); |
811 // no errors while decoding |
848 // no errors while decoding |
812 if ("".equals(error)) { //$NON-NLS-1$ |
849 if ("".equals(error)) { //$NON-NLS-1$ |
|
850 |
|
851 |
813 contentProvider.refresh(); |
852 contentProvider.refresh(); |
814 setMainViewVisible(); |
853 setMainViewVisible(); |
815 fileToBeShown = caFile; |
854 fileToBeShown = caFile; |
816 // there were errors in decoding process |
855 // there were errors in decoding process |
817 } else { |
856 } else { |