crashanalysis/crashanalyser/com.nokia.s60tools.crashanalyser/src/com/nokia/s60tools/crashanalyser/ui/views/MainView.java
changeset 4 615035072f7e
parent 0 5ad7ad99af01
equal deleted inserted replaced
3:431bbaccaec8 4:615035072f7e
    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();
   107 			} else {
   120 			} else {
   108 				browserPanicDescription.setText(HtmlFormatter.formatHtmlStyle(browserPanicDescription.getFont(), 
   121 				browserPanicDescription.setText(HtmlFormatter.formatHtmlStyle(browserPanicDescription.getFont(), 
   109 												cFileBundle.getDescription(true)));
   122 												cFileBundle.getDescription(true)));
   110 			}
   123 			}
   111 		}
   124 		}
       
   125 		actionDecode.setEnabled(true);
       
   126 		actionDeleteFiles.setEnabled(true);
   112 	}
   127 	}
   113 
   128 
   114 	/**
   129 	/**
   115 	 * Error library calls this method when it's ready to be used (i.e.
   130 	 * Error library calls this method when it's ready to be used (i.e.
   116 	 * it has finished reading in all errors & panics from xml files)
   131 	 * it has finished reading in all errors & panics from xml files)
   124 	/**
   139 	/**
   125 	 * MainView gets notified by this method to refresh the crash files table
   140 	 * MainView gets notified by this method to refresh the crash files table
   126 	 */
   141 	 */
   127 	public void crashFilesUpdated() {
   142 	public void crashFilesUpdated() {
   128 		mainViewLoaded = true;
   143 		mainViewLoaded = true;
   129 		actionOpenWizard.setEnabled(true);		
   144 		actionOpenWizard.setEnabled(true);	
   130 		actionDecode.setEnabled(true);
   145 		mainMenuActionOpenPreferences.setEnabled(true);
   131 		refreshView();
   146 		refreshView();
   132 		if (showWizard) {
   147 		if (showWizard) {
   133 			showWizard = false;
   148 			showWizard = false;
   134 			showWizardIfNoFiles();
   149 			showWizardIfNoFiles();
   135 		}
   150 		}
   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 	}
   178 	public void showWizardIfNoFiles() {
   195 	public void showWizardIfNoFiles() {
   179 		Runnable showWizardRunnable = new Runnable(){
   196 		Runnable showWizardRunnable = new Runnable(){
   180 			public void run(){
   197 			public void run(){
   181 				try {
   198 				try {
   182 					if (mainViewLoaded) {
   199 					if (mainViewLoaded) {
   183 						CrashFileBundle cFile = (CrashFileBundle)tableViewerCrashFiles.getElementAt(0);
   200 						CrashFileBundle cFile = (CrashFileBundle) treeViewerCrashFiles.getTree().getItem(0).getData();
   184 						if (cFile.isEmpty()) {
   201 						if (cFile.isEmpty()) {
   185 							showWizard();
   202 							showWizard();
   186 						}
   203 						}
   187 					} else {
   204 					} else {
   188 						showWizard = true;
   205 						showWizard = true;
   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) {
   290 	
   316 	
   291 	/**
   317 	/**
   292 	 * Initialize double-click action
   318 	 * Initialize double-click action
   293 	 */
   319 	 */
   294 	private void hookDoubleClickAction() {
   320 	private void hookDoubleClickAction() {
   295 		tableViewerCrashFiles.addDoubleClickListener(new IDoubleClickListener() {
   321 		treeViewerCrashFiles.addDoubleClickListener(new IDoubleClickListener() {
   296 			public void doubleClick(DoubleClickEvent event) {
   322 			public void doubleClick(DoubleClickEvent event) {
   297 				actionDoubleClick.run();
   323 				actionDoubleClick.run();
   298 			}
   324 			}
   299 		});
   325 		});
   300 	}	
   326 	}	
   309 			public void menuAboutToShow(IMenuManager manager) {
   335 			public void menuAboutToShow(IMenuManager manager) {
   310 				MainView.this.fillContextMenu(manager);
   336 				MainView.this.fillContextMenu(manager);
   311 				
   337 				
   312 			}
   338 			}
   313 		});
   339 		});
   314 		Menu menu = menuMgr.createContextMenu(tableViewerCrashFiles.getControl());
   340 		Menu menu = menuMgr.createContextMenu(treeViewerCrashFiles.getControl());
   315 		tableViewerCrashFiles.getControl().setMenu(menu);
   341 		treeViewerCrashFiles.getControl().setMenu(menu);
   316 		getSite().registerContextMenu(menuMgr, tableViewerCrashFiles);
   342 		getSite().registerContextMenu(menuMgr, treeViewerCrashFiles);
   317 	}
   343 	}
   318 
   344 
   319 	/**
   345 	/**
   320 	 * Action bars initializer
   346 	 * Action bars initializer
   321 	 */
   347 	 */
   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)
   352 	/**
   379 	/**
   353 	 * Fills tool bar
   380 	 * Fills tool bar
   354 	 */
   381 	 */
   355 	private void fillLocalToolBar(IToolBarManager manager) {
   382 	private void fillLocalToolBar(IToolBarManager manager) {
   356 		manager.add(actionOpenWizard);
   383 		manager.add(actionOpenWizard);
       
   384 		manager.add(mainMenuActionOpenPreferences);
   357 		manager.add(actionDecode);
   385 		manager.add(actionDecode);
   358 		manager.add(actionDeleteFiles);
   386 		manager.add(actionDeleteFiles);
   359 		manager.add(actionPanicLibrary);
   387 		manager.add(actionPanicLibrary);
   360 	}
   388 	}
   361 	
   389 	
   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;
   420 
   448 
   421 	/**
   449 	/**
   422 	 * Make all actions (buttons, double-click)
   450 	 * Make all actions (buttons, double-click)
   423 	 */
   451 	 */
   424 	private void makeActions() {
   452 	private void makeActions() {
       
   453 		mainMenuActionOpenPreferences = new OpenPreferencePageAction(
       
   454 				CrashAnalyserPreferences.PAGE_ID,
       
   455 				null,
       
   456 				null
       
   457 				);
       
   458 
   425 		makeDeleteFilesAction();
   459 		makeDeleteFilesAction();
   426 		makeOpenWizardAction();
   460 		makeOpenWizardAction();
   427 		makeOpenPanicLibraryAction();	
   461 		makeOpenPanicLibraryAction();	
   428 		makeExportToHtml();
   462 		makeExportToHtml();
   429 		makeExportToXml();
   463 		makeExportToXml();
   442 		actionDoubleClick = new Action() {
   476 		actionDoubleClick = new Action() {
   443 			public void run() {
   477 			public void run() {
   444 				try {
   478 				try {
   445 					if (wizardRunning)
   479 					if (wizardRunning)
   446 						return;
   480 						return;
   447 					ISelection selection = tableViewerCrashFiles.getSelection();
   481 					ISelection selection = treeViewerCrashFiles.getSelection();
   448 					Object obj = ((IStructuredSelection)selection).getFirstElement();
   482 					Object obj = ((IStructuredSelection)selection).getFirstElement();
   449 					CrashFileBundle cFile = (CrashFileBundle)obj;
   483 					CrashFileBundle cFile = (CrashFileBundle)obj;
   450 					// if empty file is double-clicked, open wizard
   484 					// if empty file is double-clicked, open wizard
   451 					if (cFile.isEmpty()) {
   485 					if (cFile.isEmpty()) {
   452 						showWizard();
   486 						showWizard();
   470 	 * Export selected file to html file
   504 	 * Export selected file to html file
   471 	 */
   505 	 */
   472 	private void makeExportToHtml() {
   506 	private void makeExportToHtml() {
   473 		actionExportToHtml = new Action() {
   507 		actionExportToHtml = new Action() {
   474 			public void run() {
   508 			public void run() {
   475 				ISelection selection = tableViewerCrashFiles.getSelection();
   509 				ISelection selection = treeViewerCrashFiles.getSelection();
   476 				FileExportManager.ExportSelectedFileToHtml(selection, getShell());
   510 				FileExportManager.ExportSelectedFileToHtml(selection, getShell());
   477 			}
   511 			}
   478 		};
   512 		};
   479 		actionExportToHtml.setText("to HTML File");
   513 		actionExportToHtml.setText("to HTML File");
   480 	}
   514 	}
   483 	 * Export selected file to .xml or .crashxml
   517 	 * Export selected file to .xml or .crashxml
   484 	 */
   518 	 */
   485 	private void makeExportToXml() {
   519 	private void makeExportToXml() {
   486 		actionExportToXml = new Action() {
   520 		actionExportToXml = new Action() {
   487 			public void run() {
   521 			public void run() {
   488 				ISelection selection = tableViewerCrashFiles.getSelection();
   522 				ISelection selection = treeViewerCrashFiles.getSelection();
   489 				FileExportManager.ExportSelectedFileToXml(selection, getShell());
   523 				FileExportManager.ExportSelectedFileToXml(selection, getShell());
   490 			}
   524 			}
   491 		};
   525 		};
   492 		actionExportToXml.setText("to XML File");
   526 		actionExportToXml.setText("to XML File");
   493 	}
   527 	}
   496 	 * Export to Zip as Xml
   530 	 * Export to Zip as Xml
   497 	 */
   531 	 */
   498 	private void makeExportAsXmlAction() {
   532 	private void makeExportAsXmlAction() {
   499 		actionExportAsXml = new Action() {
   533 		actionExportAsXml = new Action() {
   500 			public void run() {
   534 			public void run() {
   501 				ISelection selection = tableViewerCrashFiles.getSelection();
   535 				ISelection selection = treeViewerCrashFiles.getSelection();
   502 				FileExportManager.ExportSelectedFilesAsXmlToZip(selection, getShell());
   536 				FileExportManager.ExportSelectedFilesAsXmlToZip(selection, getShell());
   503 			}
   537 			}
   504 		};
   538 		};
   505 		actionExportAsXml.setText("to Zip as XML");
   539 		actionExportAsXml.setText("to Zip as XML");
   506 	}
   540 	}
   509 	 * Export to Zip as Html
   543 	 * Export to Zip as Html
   510 	 */
   544 	 */
   511 	private void makeExportAsHtmlAction() {
   545 	private void makeExportAsHtmlAction() {
   512 		actionExportAsHtml = new Action() {
   546 		actionExportAsHtml = new Action() {
   513 			public void run() {
   547 			public void run() {
   514 				ISelection selection = tableViewerCrashFiles.getSelection();
   548 				ISelection selection = treeViewerCrashFiles.getSelection();
   515 				FileExportManager.ExportSelectedFilesAsHtmlToZip(selection, getShell());
   549 				FileExportManager.ExportSelectedFilesAsHtmlToZip(selection, getShell());
   516 			}
   550 			}
   517 		};
   551 		};
   518 		actionExportAsHtml.setText("to Zip as HTML");
   552 		actionExportAsHtml.setText("to Zip as HTML");
   519 	}
   553 	}
   522 	 * Export all formats to zip
   556 	 * Export all formats to zip
   523 	 */
   557 	 */
   524 	private void makeExportAllAction() {
   558 	private void makeExportAllAction() {
   525 		actionExportAll = new Action() {
   559 		actionExportAll = new Action() {
   526 			public void run() {
   560 			public void run() {
   527 				ISelection selection = tableViewerCrashFiles.getSelection();
   561 				ISelection selection = treeViewerCrashFiles.getSelection();
   528 				FileExportManager.ExportSelectedFilesToZipInAllFormats(selection, getShell());
   562 				FileExportManager.ExportSelectedFilesToZipInAllFormats(selection, getShell());
   529 			}
   563 			}
   530 		};
   564 		};
   531 		actionExportAll.setText("All Formats to Zip");
   565 		actionExportAll.setText("All Formats to Zip");
   532 	}
   566 	}
   535 	 * Open Error Library button
   569 	 * Open Error Library button
   536 	 */
   570 	 */
   537 	private void makeOpenPanicLibraryAction() {
   571 	private void makeOpenPanicLibraryAction() {
   538 		actionPanicLibrary = new Action() {
   572 		actionPanicLibrary = new Action() {
   539 			public void run() {
   573 			public void run() {
   540 				ErrorLibraryDialog dlg = new ErrorLibraryDialog(tableViewerCrashFiles.getControl().getShell(), errorLibrary);
   574 				ErrorLibraryDialog dlg = new ErrorLibraryDialog(treeViewerCrashFiles.getControl().getShell(), errorLibrary);
   541 				dlg.open();
   575 				dlg.open();
   542 			}
   576 			}
   543 		};
   577 		};
   544 		actionPanicLibrary.setText("Open Error Library...");
   578 		actionPanicLibrary.setText("Open Error Library...");
   545 		actionPanicLibrary.setToolTipText("Open Error Library Window");
   579 		actionPanicLibrary.setToolTipText("Open Error Library Window");
   578 	 * Decode files button
   612 	 * Decode files button
   579 	 */
   613 	 */
   580 	private void makeDecodeFilesAction() {
   614 	private void makeDecodeFilesAction() {
   581 		actionDecode = new Action() {
   615 		actionDecode = new Action() {
   582 			public void run() {
   616 			public void run() {
   583 				ISelection selection = tableViewerCrashFiles.getSelection();
   617 				ISelection selection = treeViewerCrashFiles.getSelection();
   584 				// if nothing is selected, just ignore button press
   618 				// if nothing is selected, just ignore button press
   585 				if (selection == null || selection.isEmpty())
   619 				if (selection == null || selection.isEmpty())
   586 					return;
   620 					return;
   587 
   621 
   588 				String romId = "";
   622 				String romId = "";
   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 	/**
   693 	 */
   729 	 */
   694 	private void showErrorMessage() {
   730 	private void showErrorMessage() {
   695 		Runnable showErrorMessageRunnable = new Runnable(){
   731 		Runnable showErrorMessageRunnable = new Runnable(){
   696 			public void run(){
   732 			public void run(){
   697 				MessageDialog.openError(
   733 				MessageDialog.openError(
   698 						tableViewerCrashFiles.getControl().getShell(),
   734 						treeViewerCrashFiles.getControl().getShell(),
   699 						"Crash Analyser",
   735 						"Crash Analyser",
   700 						errorMessage);
   736 						errorMessage);
   701 				errorMessage = ""; //$NON-NLS-1$
   737 				errorMessage = ""; //$NON-NLS-1$
   702 			}
   738 			}
   703 		};
   739 		};
   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.
   744 	 * @param disable
   780 	 * @param disable
   745 	 */
   781 	 */
   746 	void disableUIForImport(boolean disable) {
   782 	void disableUIForImport(boolean disable) {
   747 		actionDecode.setEnabled(!disable);
   783 		actionDecode.setEnabled(!disable);
   748 		actionOpenWizard.setEnabled(!disable);
   784 		actionOpenWizard.setEnabled(!disable);
       
   785 		mainMenuActionOpenPreferences.setEnabled(!disable);
   749 		actionDeleteFiles.setEnabled(!disable);
   786 		actionDeleteFiles.setEnabled(!disable);
   750 		wizardRunning = disable;
   787 		wizardRunning = disable;
   751 	}
   788 	}
   752 	
   789 	
   753 	/**
   790 	/**
   778 	 * Refreshes view asynchronously.
   815 	 * Refreshes view asynchronously.
   779 	 */
   816 	 */
   780 	private void refreshView() {
   817 	private void refreshView() {
   781 		Runnable refreshRunnable = new Runnable(){
   818 		Runnable refreshRunnable = new Runnable(){
   782 			public void run(){
   819 			public void run(){
   783 				tableViewerCrashFiles.refresh();
   820 				treeViewerCrashFiles.refresh();
   784 			}
   821 			}
   785 		};
   822 		};
   786 		
   823 		
   787 		// Has to be done in its own thread
   824 		// Has to be done in its own thread
   788 		// in order not to cause invalid thread access
   825 		// in order not to cause invalid thread access
   794 	 *
   831 	 *
   795 	 */
   832 	 */
   796 	private void updateView() {
   833 	private void updateView() {
   797 		try {
   834 		try {
   798 			getViewSite().getPage().showView(MainView.ID);
   835 			getViewSite().getPage().showView(MainView.ID);
   799 			tableViewerCrashFiles.refresh();
   836 			treeViewerCrashFiles.refresh();
   800 		} catch (Exception e) {			
   837 		} catch (Exception e) {			
   801 			e.printStackTrace();
   838 			e.printStackTrace();
   802 		}
   839 		}
   803 	}
   840 	}
   804 
   841 
   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 {
   824 	/**
   863 	/**
   825 	 * Refreshes table
   864 	 * Refreshes table
   826 	 */
   865 	 */
   827 	public void refresh() {
   866 	public void refresh() {
   828 		contentProvider.refresh();
   867 		contentProvider.refresh();
   829 		tableViewerCrashFiles.refresh();
   868 		treeViewerCrashFiles.refresh();
   830 	}
   869 	}
   831 	
   870 	
   832 	public void dragEnter(DropTargetEvent event) {
   871 	public void dragEnter(DropTargetEvent event) {
   833 		event.detail = DND.DROP_COPY;
   872 		event.detail = DND.DROP_COPY;
   834 	}
   873 	}