Author: echatellier Date: 2012-04-17 18:00:24 +0200 (Tue, 17 Apr 2012) New Revision: 3373 Url: http://chorem.org/repositories/revision/lima/3373 Log: Refactor ErrorHelper use Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/FinancialTransactionSearchTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java trunk/lima-swing/src/main/java/org/chorem/lima/util/ErrorHelper.java Modified: trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/LimaMain.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -28,6 +28,7 @@ import jaxx.runtime.SwingUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.api.AccountService; import org.chorem.lima.business.monitorable.AccountServiceMonitorable; import org.chorem.lima.business.monitorable.HttpServerServiceMonitorable; @@ -37,6 +38,7 @@ import org.chorem.lima.ui.opening.OpeningView; import org.chorem.lima.util.ErrorHelper; +import javax.swing.JOptionPane; import javax.swing.SwingUtilities; import java.util.Arrays; import java.util.Date; @@ -49,7 +51,7 @@ * @author ore * @version $Revision$ */ -public class LimaMain { +public class LimaMain implements Thread.UncaughtExceptionHandler { /** Log. */ private static final Log log = LogFactory.getLog(LimaMain.class); @@ -64,36 +66,46 @@ * Lima main method. * * @param args program args + * @throws Exception */ - public static void main(String[] args) { + public static void main(String[] args) throws Exception { if (log.isInfoEnabled()) { log.info("Lima starts at " + new Date()); log.info("Args: " + Arrays.toString(args)); } - try { + // init root context + LimaContext context = init(args); - // init root context - LimaContext context = init(args); + // do actions + config = context.getConfig(); + config.doAction(LimaConfig.Action.AFTER_INIT_STEP); - // do actions - config = context.getConfig(); - config.doAction(LimaConfig.Action.AFTER_INIT_STEP); + // display main ui + if (config.isLaunchui()) { + // override default exception management (after config init) + Thread.setDefaultUncaughtExceptionHandler(new LimaMain()); - // display main ui - if (config.isLaunchui()) { - launch(context); - } - } catch (Exception ex) { - if (log.isErrorEnabled()) { - log.error(_("lima.common.globalexception"), ex); - } - ErrorHelper.showErrorDialog(_("lima.common.globalexception"), ex); - System.exit(1); + launch(context); } } + public void uncaughtException(Thread t, Throwable ex) { + if (log.isErrorEnabled()) { + log.error("Global application exception", ex); + } + + Throwable cause = ex.getCause(); + if (cause instanceof LimaBusinessException) { + JOptionPane.showMessageDialog(null, cause.getMessage(), + _("lima.ui.common.error"), JOptionPane.ERROR_MESSAGE); + } else { + ErrorHelper errorHelper = new ErrorHelper(config); + errorHelper.showErrorDialog(null, ex.getMessage(), ex); + } + } + /** * initialisation de l'application : * <p/> Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/MainViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -33,6 +33,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; import org.chorem.lima.LimaContext; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.monitorable.HttpServerServiceMonitorable; import org.chorem.lima.enums.ImportExportEnum; import org.chorem.lima.service.LimaServiceFactory; @@ -194,7 +195,7 @@ try { DesktopUtil.browse(siteURL.toURI()); } catch (Exception e) { - ErrorHelper.showErrorDialog("Can't open lima website at " + siteURL, e); + throw new LimaRuntimeException("Can't open lima website at " + siteURL, e); } } @@ -451,7 +452,7 @@ try { SwingUtil.openLink(url); } catch (Exception e) { - ErrorHelper.showErrorDialog("Can't open lima website at " + url, e); + throw new LimaRuntimeException("Can't open lima website at " + url, e); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/accountsreports/AccountsReportsViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; import org.chorem.lima.business.monitorable.ImportServiceMonitorable; @@ -108,10 +109,7 @@ results = reportService.generateAccountsReports(selectedAccount, true, selectedBeginDate, selectedEndDate); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.accountsreports.listerror"), eee); + throw new LimaRuntimeException(_("lima.accountsreports.listerror"), eee); } } return results; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/balance/BalanceViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -30,6 +30,7 @@ import org.chorem.lima.LimaConfig; import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; import org.chorem.lima.business.monitorable.FiscalPeriodServiceMonitorable; @@ -133,10 +134,7 @@ try { results = reportService.generateBalanceTrial(selectedBeginDate, selectedEndDate, selectedAccounts, false, view.getMovmentedFilter().isSelected()); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.balance.listerror"), eee); + throw new LimaRuntimeException(_("lima.balance.listerror"), eee); } return results; } @@ -187,10 +185,7 @@ try { blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Enable to create document ", eee); - } - ErrorHelper.showErrorDialog(_("lima.balance.documentcreationerror"), eee); + throw new LimaRuntimeException(_("lima.balance.documentcreationerror"), eee); } //tells if the fiscaPeriod as been found and is blocked Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/entrybooksreports/EntryBooksReportsViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -25,11 +25,26 @@ package org.chorem.lima.ui.entrybooksreports; +import static org.nuiton.i18n.I18n._; + +import java.awt.Desktop; +import java.io.IOException; +import java.math.BigDecimal; +import java.net.URI; +import java.net.URISyntaxException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.swing.JOptionPane; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.LimaConfig; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.monitorable.DocumentServiceMonitorable; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; @@ -44,20 +59,7 @@ import org.chorem.lima.service.LimaServiceFactory; import org.chorem.lima.util.ErrorHelper; -import javax.swing.JOptionPane; -import java.awt.Desktop; -import java.io.IOException; -import java.math.BigDecimal; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import static org.nuiton.i18n.I18n._; - - /** * Handler associated with accounts reports view. * By : $Author$ @@ -136,10 +138,7 @@ reportService.generateEntryBooksReports( selectedEntryBook, selectedBeginDate, selectedEndDate); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.entrybooksreports.listerror"), eee); + throw new LimaRuntimeException(_("lima.entrybooksreports.listerror"), eee); } } return results; @@ -191,10 +190,7 @@ try { blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Enable to create document ", eee); - } - ErrorHelper.showErrorDialog(_("lima.entrybooksreports.documentcreationerror"), eee); + throw new LimaRuntimeException(_("lima.entrybooksreports.documentcreationerror"), eee); } //tells if the fiscaPeriod as been found and is blocked Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementchart/FinancialStatementChartViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -29,6 +29,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.monitorable.FinancialStatementServiceMonitorable; import org.chorem.lima.business.monitorable.ImportServiceMonitorable; @@ -113,10 +114,7 @@ DialogHelper.showErrorMessageDialog(view, eee); } catch (LimaException ex) { - if (log.isErrorEnabled()) { - log.error("Can't add financialStatementHeader", ex); - } - ErrorHelper.showErrorDialog(_("lima.financialstatement.addfinancialStatementHeadererror"), ex); + throw new LimaRuntimeException(_("lima.financialstatement.addfinancialStatementHeadererror"), ex); } } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportTableModel.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -30,6 +30,7 @@ import org.chorem.lima.LimaConfig; import org.chorem.lima.beans.FinancialStatementAmounts; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.DocumentService; import org.chorem.lima.business.api.FinancialStatementService; @@ -257,10 +258,7 @@ try { results = financialStatementService.financialStatementReport(selectedBeginDate, selectedEndDate); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.financialstatementreport.listerror"), eee); + throw new LimaRuntimeException(_("lima.financialstatementreport.listerror"), eee); } } return results; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialstatementreport/FinancialStatementReportViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.monitorable.FiscalPeriodServiceMonitorable; import org.chorem.lima.business.utils.FormatsEnum; import org.chorem.lima.entity.FiscalPeriod; @@ -89,10 +90,7 @@ try { blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Enable to create document ", eee); - } - ErrorHelper.showErrorDialog("Enable to create document ", eee); + throw new LimaRuntimeException("Enable to create document ", eee); } //tells if the fiscaPeriod as been found and is blocked Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/FinancialTransactionSearchTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/FinancialTransactionSearchTableModel.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionsearch/FinancialTransactionSearchTableModel.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -31,6 +31,7 @@ import org.chorem.lima.beans.FinancialTransactionSearch; import org.chorem.lima.business.LimaBusinessException; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialPeriodService; import org.chorem.lima.business.api.FinancialTransactionService; @@ -124,11 +125,7 @@ try { results = financialTransactionService.searchFinancialTransaction(financialTransactionSearch); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - - ErrorHelper.showErrorDialog("Can't get transaction list", eee); + throw new LimaRuntimeException("Can't get transaction list", eee); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/financialtransactionunbalanced/FinancialTransactionUnbalancedTableModel.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; @@ -116,11 +117,7 @@ results.addAll(entries); } } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - - ErrorHelper.showErrorDialog("Can't get transaction list", eee); + throw new LimaRuntimeException("Can't get transaction list", eee); } } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/ledger/LedgerViewHandler.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -31,6 +31,7 @@ import org.chorem.lima.beans.BalanceTrial; import org.chorem.lima.beans.ReportsDatas; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FiscalPeriodService; import org.chorem.lima.business.api.ReportService; @@ -151,10 +152,7 @@ } } } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog("Can't get entries list", eee); + throw new LimaRuntimeException("Can't get entries list", eee); } return results; } @@ -202,10 +200,7 @@ try { blockedFiscalPeriods = fiscalPeriodService.getAllBlockedFiscalPeriods(); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Enable to create document ", eee); - } - ErrorHelper.showErrorDialog(_("lima.ledger.documentcreationerror"), eee); + throw new LimaRuntimeException(_("lima.ledger.documentcreationerror"), eee); } //tells if the fiscaPeriod as been found and is blocked Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/lettering/LetteringTableModel.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -28,6 +28,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.FinancialTransactionService; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; @@ -132,10 +133,7 @@ results.addAll(entries); } } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.lettering.listerror"), eee); + throw new LimaRuntimeException(_("lima.lettering.listerror"), eee); } } return results; Modified: trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/ui/vatreports/VatReportTableModel.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory; import org.chorem.lima.beans.VatStatementAmounts; import org.chorem.lima.business.LimaException; +import org.chorem.lima.business.LimaRuntimeException; import org.chorem.lima.business.ServiceListener; import org.chorem.lima.business.api.VatStatementService; import org.chorem.lima.business.monitorable.FinancialTransactionServiceMonitorable; @@ -107,10 +108,7 @@ getBeginDate(), getEndDate()); } catch (LimaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog(_("lima.vatreport.listerror"), eee); + throw new LimaRuntimeException(_("lima.vatreport.listerror"), eee); } } return list; @@ -120,10 +118,7 @@ try { cacheDataList = getDataList(); } catch (TopiaException eee) { - if (log.isErrorEnabled()) { - log.error("Can't update model", eee); - } - ErrorHelper.showErrorDialog("Can't get VAT list", eee); + throw new LimaRuntimeException("Can't get VAT list", eee); } fireTableDataChanged(); } Modified: trunk/lima-swing/src/main/java/org/chorem/lima/util/ErrorHelper.java =================================================================== --- trunk/lima-swing/src/main/java/org/chorem/lima/util/ErrorHelper.java 2012-04-17 15:39:47 UTC (rev 3372) +++ trunk/lima-swing/src/main/java/org/chorem/lima/util/ErrorHelper.java 2012-04-17 16:00:24 UTC (rev 3373) @@ -25,17 +25,8 @@ package org.chorem.lima.util; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.MultiPartEmail; -import org.chorem.lima.LimaMain; -import org.jdesktop.swingx.JXErrorPane; -import org.jdesktop.swingx.error.ErrorInfo; -import org.jdesktop.swingx.error.ErrorReporter; +import static org.nuiton.i18n.I18n._; -import javax.swing.JOptionPane; import java.awt.Component; import java.io.PrintWriter; import java.io.StringWriter; @@ -44,8 +35,18 @@ import java.util.Date; import java.util.List; -import static org.nuiton.i18n.I18n._; +import javax.swing.JOptionPane; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.mail.EmailException; +import org.apache.commons.mail.MultiPartEmail; +import org.chorem.lima.LimaConfig; +import org.jdesktop.swingx.JXErrorPane; +import org.jdesktop.swingx.error.ErrorInfo; +import org.jdesktop.swingx.error.ErrorReporter; + /** * Error helper. * <p/> @@ -62,6 +63,12 @@ /** Log. */ private static final Log log = LogFactory.getLog(ErrorHelper.class); + protected LimaConfig config; + + public ErrorHelper(LimaConfig config) { + this.config = config; + } + /** * Display a user friendly error frame. * @@ -69,14 +76,14 @@ * @param message message for user * @param cause exception cause */ - public static void showErrorDialog(Component parent, String message, + public void showErrorDialog(Component parent, String message, Throwable cause) { JXErrorPane pane = new JXErrorPane(); ErrorInfo info = new ErrorInfo(_("lima.common.error"), _("lima.error.errorpane.htmlmessage", message), null, null, cause, null, null); pane.setErrorInfo(info); - pane.setErrorReporter(new ErrorHelper()); + pane.setErrorReporter(this); JXErrorPane.showDialog(parent, pane); } @@ -85,7 +92,7 @@ * * @param message message for user */ - public static void showErrorDialog(String message) { + public void showErrorDialog(String message) { showErrorDialog(message, null); } @@ -95,7 +102,7 @@ * @param message message for user * @param cause exception cause */ - public static void showErrorDialog(String message, Throwable cause) { + public void showErrorDialog(String message, Throwable cause) { showErrorDialog(null, message, cause); } @@ -106,7 +113,7 @@ public void reportError(ErrorInfo errorInfo) throws NullPointerException { try { - String emailTo = LimaMain.config.getSupportEmail(); + String emailTo = config.getSupportEmail(); MultiPartEmail email = new MultiPartEmail(); // smtp @@ -120,19 +127,19 @@ // message description StringBuffer message = new StringBuffer(); - message.append(formatMessage("Project", "Lima " + LimaMain.config.getVersion())); + message.append(formatMessage("Project", "Lima " + config.getVersion())); message.append(formatMessage("Date", new Date().toString())); message.append(formatMessage("Title", errorInfo.getTitle())); message.append(formatMessage("Description", errorInfo.getBasicErrorMessage().replaceAll("<[^>]+>", ""))); // message configuration message.append(formatMessage("Configuration", null)); - List<String> propertiesNames = new ArrayList<String>(LimaMain.config.getOptions().stringPropertyNames()); + List<String> propertiesNames = new ArrayList<String>(config.getOptions().stringPropertyNames()); Collections.sort(propertiesNames); for (String propertyName : propertiesNames) { // security, don't send string containing password : if (!propertyName.contains("pass")) { - message.append("\t" + propertyName + " : " + LimaMain.config.getOptions().getProperty(propertyName) + "\n"); + message.append("\t" + propertyName + " : " + config.getOptions().getProperty(propertyName) + "\n"); } } @@ -142,9 +149,6 @@ errorInfo.getErrorException().printStackTrace(writer); message.append(formatMessage("Exception", out.toString())); - // TODO EC-20100409 i18n files are iso encoded ? - email.setContent(message.toString(), "text/plain; charset=ISO-8859-9"); - // send mail email.send();