001package jmri.configurexml.swing;
002
003import java.awt.HeadlessException;
004
005/**
006 * Swing dialog for reporting errors while loading. Shows each one, could save
007 * until end if needed.
008 *
009 * @author Bob Jacobsen Copyright (c) 2010
010 */
011public class DialogErrorHandler extends jmri.configurexml.ErrorHandler {
012
013    /**
014     * Handle error by formatting and putting up a dialog box
015     *
016     * @param e the error memo
017     */
018    @Override
019    public void handle(jmri.configurexml.ErrorMemo e) {
020        // first, send to log
021        super.handle(e);
022
023        try {
024            // then do dialog
025            StringBuilder m = new StringBuilder("<html>").append(e.description);
026            if (e.systemName != null) {
027                m.append(" System name \"").append(e.systemName).append("\"");
028            }
029            if (e.userName != null && !e.userName.isEmpty()) {
030                m.append("<br> User name \"").append(e.userName).append("\"");
031            }
032            if (e.operation != null) {
033                m.append("<br> while ").append(e.operation);
034            }
035            if (e.adapter != null) {
036                m.append("<br> in adaptor of type ").append(e.adapter.getClass().getName());
037            }
038            if (e.exception != null) {
039                m.append("<br> Exception: ").append(e.exception.toString());
040            }
041            m.append("<br> See http://jmri.org/help/en/package/jmri/configurexml/ErrorHandler.shtml for more information.</html>");
042
043            jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).
044                    showErrorMessage("Error during " + e.title, m.toString(), e.description, "", true, false);
045        } catch (HeadlessException ex) {
046            // silently do nothig - we can't display a dialog and have already
047            // logged the error
048        }
049    }
050
051    /**
052     * Do nothing at end, already displayed
053     */
054    @Override
055    public void done() {
056    }
057}