KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mountainminds > eclemma > internal > ui > wizards > SessionImportWizard


1 /*******************************************************************************
2  * Copyright (c) 2006 Mountainminds GmbH & Co. KG
3  * This software is provided under the terms of the Eclipse Public License v1.0
4  * See http://www.eclipse.org/legal/epl-v10.html.
5  *
6  * $Id: SessionImportWizard.java 90 2006-09-18 09:54:10Z mho $
7  ******************************************************************************/

8 package com.mountainminds.eclemma.internal.ui.wizards;
9
10 import java.lang.reflect.InvocationTargetException JavaDoc;
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 /**
29  * The import wizard for coverage sessions.
30  *
31  * @author Marc R. Hoffmann
32  * @version $Revision: 90 $
33  */

34 public class SessionImportWizard extends Wizard implements IExportWizard {
35
36   private static final String JavaDoc SETTINGSID = "SessionImportWizard"; //$NON-NLS-1$
37

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     // nothing to initialize
56
}
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 JavaDoc, InterruptedException JavaDoc {
77         try {
78           importer.importSession(monitor);
79         } catch (Exception JavaDoc e) {
80           throw new InvocationTargetException JavaDoc(e);
81         }
82       }
83     };
84     try {
85       getContainer().run(true, true, op);
86     } catch (InterruptedException JavaDoc e) {
87       return false;
88     } catch (InvocationTargetException JavaDoc ite) {
89       Throwable JavaDoc ex = ite.getTargetException();
90       EclEmmaUIPlugin.log(ex);
91       String JavaDoc title = UIMessages.ImportReportErrorDialog_title;
92       String JavaDoc 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