/** * Creates and returns HTML representing the details of this incident info. This method is only * called if the details needs to be generated: ie: the detailed error message property of the * incident info is null. */ protected String getDetailsAsHTML(ErrorInfo errorInfo) { if (errorInfo.getErrorException() != null) { // convert the stacktrace into a more pleasent bit of HTML StringBuffer html = new StringBuffer("<html>"); html.append("<h2>" + escapeXml(errorInfo.getTitle()) + "</h2>"); html.append("<HR size='1' noshade>"); html.append("<div></div>"); html.append("<b>Message:</b>"); html.append("<pre>"); html.append(" " + escapeXml(errorInfo.getErrorException().toString())); html.append("</pre>"); html.append("<b>Level:</b>"); html.append("<pre>"); html.append(" " + errorInfo.getErrorLevel()); html.append("</pre>"); html.append("<b>Stack Trace:</b>"); Throwable ex = errorInfo.getErrorException(); while (ex != null) { html.append("<h4>" + ex.getMessage() + "</h4>"); html.append("<pre>"); for (StackTraceElement el : ex.getStackTrace()) { html.append(" " + el.toString().replace("<init>", "<init>") + "\n"); } html.append("</pre>"); ex = ex.getCause(); } html.append("</html>"); return html.toString(); } else { return null; } }
/* (non-Javadoc) * @see org.jdesktop.swingworker.SwingWorker#doInBackground() */ @Override protected Void doInBackground() throws Exception { if (errorInfo != null) { Throwable t = errorInfo.getErrorException(); String osMessage = "An error occurred on " + System.getProperty("os.name") + " version " + System.getProperty("os.version"); StringBuffer message = new StringBuffer(); message.append("System Info : ").append(osMessage).append(NEW_LINE_CHAR); message.append("Message : ").append(t.toString()).append(NEW_LINE_CHAR); message.append("Level : ").append(errorInfo.getErrorLevel()).append(NEW_LINE_CHAR); message.append("Stack Trace : ").append(NEW_LINE_CHAR); message.append(stackTraceToString(t)); // copy error message to system clipboard StringSelection stringSelection = new StringSelection(message.toString()); Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); clipboard.setContents(stringSelection, null); // open errorReportingURL OpenBrowserAction openBrowserAction = new OpenBrowserAction(errorReportingURL); openBrowserAction.actionPerformed(null); } return null; }
private void exitIfFatal() { ErrorInfo info = pane.getErrorInfo(); // FYI: info can be null if (info != null && info.getErrorLevel() == ErrorLevel.FATAL) { Action fatalAction = pane.getActionMap().get(JXErrorPane.FATAL_ACTION_KEY); if (fatalAction == null) { System.exit(1); } else { ActionEvent ae = new ActionEvent(closeButton, -1, "fatal"); fatalAction.actionPerformed(ae); } } }
/** * Reconfigures the dialog if settings have changed, such as the errorInfo, errorIcon, * warningIcon, etc */ protected void reinit() { setDetailsVisible(false); Action reportAction = pane.getActionMap().get(JXErrorPane.REPORT_ACTION_KEY); reportButton.setAction(reportAction); reportButton.setVisible( reportAction != null && reportAction.isEnabled() && pane.getErrorReporter() != null); reportButton.setEnabled(reportButton.isVisible()); ErrorInfo errorInfo = pane.getErrorInfo(); if (errorInfo == null) { iconLabel.setIcon(pane.getIcon()); setErrorMessage(""); closeButton.setText( UIManagerExt.getString(CLASS_NAME + ".ok_button_text", closeButton.getLocale())); setDetails(""); // TODO Does this ever happen? It seems like if errorInfo is null and // this is called, it would be an IllegalStateException. } else { // change the "closeButton"'s text to either the default "ok"/"close" text // or to the "fatal" text depending on the error level of the incident info if (errorInfo.getErrorLevel() == ErrorLevel.FATAL) { closeButton.setText( UIManagerExt.getString(CLASS_NAME + ".fatal_button_text", closeButton.getLocale())); } else { closeButton.setText( UIManagerExt.getString(CLASS_NAME + ".ok_button_text", closeButton.getLocale())); } // if the icon for the pane has not been specified by the developer, // then set it to the default icon based on the error level Icon icon = pane.getIcon(); if (icon == null || icon instanceof UIResource) { if (errorInfo.getErrorLevel().intValue() <= Level.WARNING.intValue()) { icon = getDefaultWarningIcon(); } else { icon = getDefaultErrorIcon(); } } iconLabel.setIcon(icon); setErrorMessage(errorInfo.getBasicErrorMessage()); String details = errorInfo.getDetailedErrorMessage(); if (details == null) { details = getDetailsAsHTML(errorInfo); } setDetails(details); } }