1 8 package com.mountainminds.eclemma.internal.ui.wizards; 9 10 import java.lang.reflect.InvocationTargetException ; 11 12 import org.eclipse.core.runtime.CoreException; 13 import org.eclipse.core.runtime.IProgressMonitor; 14 import org.eclipse.core.runtime.IStatus; 15 import org.eclipse.jface.dialogs.ErrorDialog; 16 import org.eclipse.jface.dialogs.IDialogSettings; 17 import org.eclipse.jface.operation.IRunnableWithProgress; 18 import org.eclipse.jface.viewers.IStructuredSelection; 19 import org.eclipse.jface.wizard.Wizard; 20 import org.eclipse.ui.IExportWizard; 21 import org.eclipse.ui.IWorkbench; 22 23 import com.mountainminds.eclemma.core.CoverageTools; 24 import com.mountainminds.eclemma.core.ISessionImporter; 25 import com.mountainminds.eclemma.internal.ui.EclEmmaUIPlugin; 26 import com.mountainminds.eclemma.internal.ui.UIMessages; 27 28 34 public class SessionImportWizard extends Wizard implements IExportWizard { 35 36 private static final String SETTINGSID = "SessionImportWizard"; 38 private SessionImportPage1 page1; 39 40 public SessionImportWizard() { 41 IDialogSettings pluginsettings = EclEmmaUIPlugin.getInstance() 42 .getDialogSettings(); 43 IDialogSettings wizardsettings = pluginsettings.getSection(SETTINGSID); 44 if (wizardsettings == null) { 45 wizardsettings = pluginsettings.addNewSection(SETTINGSID); 46 } 47 setDialogSettings(wizardsettings); 48 setWindowTitle(UIMessages.ImportSession_title); 49 setDefaultPageImageDescriptor(EclEmmaUIPlugin 50 .getImageDescriptor(EclEmmaUIPlugin.WIZBAN_IMPORT_SESSION)); 51 setNeedsProgressMonitor(true); 52 } 53 54 public void init(IWorkbench workbench, IStructuredSelection selection) { 55 } 57 58 public void addPages() { 59 addPage(page1 = new SessionImportPage1()); 60 super.addPages(); 61 } 62 63 public boolean performFinish() { 64 page1.saveWidgetValues(); 65 return importSession(); 66 } 67 68 private boolean importSession() { 69 final ISessionImporter importer = CoverageTools.getImporter(); 70 importer.setDescription(page1.getSessionDescription()); 71 importer.setCoverageFile(page1.getCoverageFile()); 72 importer.setClassFiles(page1.getClassFiles()); 73 importer.setCopy(page1.getCreateCopy()); 74 IRunnableWithProgress op = new IRunnableWithProgress() { 75 public void run(IProgressMonitor monitor) 76 throws InvocationTargetException , InterruptedException { 77 try { 78 importer.importSession(monitor); 79 } catch (Exception e) { 80 throw new InvocationTargetException (e); 81 } 82 } 83 }; 84 try { 85 getContainer().run(true, true, op); 86 } catch (InterruptedException e) { 87 return false; 88 } catch (InvocationTargetException ite) { 89 Throwable ex = ite.getTargetException(); 90 EclEmmaUIPlugin.log(ex); 91 String title = UIMessages.ImportReportErrorDialog_title; 92 String msg = UIMessages.ImportReportErrorDialog_message; 93 IStatus status; 94 if (ex instanceof CoreException) { 95 status = ((CoreException) ex).getStatus(); 96 } else { 97 status = EclEmmaUIPlugin.errorStatus(String.valueOf(ex.getMessage()), ex); 98 } 99 ErrorDialog.openError(getShell(), title, msg, status); 100 return false; 101 } 102 return true; 103 } 104 105 } 106 | Popular Tags |