KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > rcp > exceptionhandler > wizard > ExceptionHandlerWizard


1 /*
2  * Created on 23.03.2005
3  */

4 package com.nightlabs.rcp.exceptionhandler.wizard;
5
6 import org.apache.log4j.Logger;
7 import org.eclipse.jface.dialogs.MessageDialog;
8
9 import com.nightlabs.config.Config;
10 import com.nightlabs.rcp.wizard.DynamicPathWizard;
11 import com.nightlabs.rcp.wizard.IDynamicPathWizardPage;
12
13 /**
14  * @author Simon Lehmann - simon@nightlabs.de
15  */

16 public class ExceptionHandlerWizard extends DynamicPathWizard
17 {
18     public static final Logger LOGGER = Logger.getLogger(ExceptionHandlerWizard.class) ;
19     
20     private ErrorReport errorReport;
21
22     private UserCommentPage sendExceptionPage;
23
24     private ExceptionSummaryPage exceptionSummaryPage;
25     
26
27     
28     
29     /**
30      * @param errorReport A raw <tt>ErrorReport</tt>. It will be populated with user comment
31      * and other data by this wizard.
32      */

33     public ExceptionHandlerWizard(ErrorReport errorReport)
34     {
35         this.errorReport = errorReport;
36     }
37
38     public IDynamicPathWizardPage createWizardEntryPage()
39     {
40         ExceptionHandlerEntryPage entry = new ExceptionHandlerEntryPage();
41         sendExceptionPage = new UserCommentPage();
42         exceptionSummaryPage = new ExceptionSummaryPage();
43         addDynamicWizardPage(sendExceptionPage);
44         addDynamicWizardPage(exceptionSummaryPage);
45         setForcePreviousAndNextButtons(true);
46         return entry;
47     }
48
49     /**
50      * @see org.eclipse.jface.wizard.IWizard#performFinish()
51      */

52     public boolean performFinish()
53     {
54         if (getStartingPage() == getDynamicWizardDialog().getCurrentPage())
55             return true;
56
57         try {
58 // obtain configuration
59
Config configuration = Config.sharedInstance();
60
61 // create new ConfigModule or obtain the one read from xml files
62
ErrorReportSenderCfMod cfMod = (ErrorReportSenderCfMod) configuration.createConfigModule(ErrorReportSenderCfMod.class);
63             
64             Class JavaDoc clazz;
65             try {
66                 clazz = Class.forName(cfMod.getErrorReportSenderClass());
67             } catch (Throwable JavaDoc x) {
68                 throw new ClassNotFoundException JavaDoc(
69                         "Invalid configuration parameter in \"" + ErrorReportSenderCfMod.class + "\": Unable to load class \"" + cfMod.getErrorReportSenderClass() + "\"!", x);
70             }
71
72             if (!ErrorReportSender.class.isAssignableFrom(clazz))
73                 throw new ClassCastException JavaDoc(
74                         "Invalid configuration parameter in \"" + ErrorReportSenderCfMod.class + "\": Class \"" + cfMod.getErrorReportSenderClass() + "\" does not implement interface \""+ErrorReportSender.class.getName()+"\"!");
75
76             ErrorReportSender sender = (ErrorReportSender) clazz.newInstance();
77             sender.sendErrorReport(errorReport);
78             return true;
79         } catch (Throwable JavaDoc e) {
80             LOGGER.fatal("Sending ErrorReport failed!", e);
81             new MessageDialog(
82                     getShell(),
83                     "Sending Error Report failed!",
84                     null,
85                     e.getClass().getName() + ": " + e.getLocalizedMessage(),
86                     MessageDialog.ERROR,
87                     new String JavaDoc[]{"OK"},
88                     0).open();
89         }
90         return false;
91     }
92
93     public ErrorReport getErrorReport()
94     {
95         return errorReport;
96     }
97 }
98
Popular Tags