Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package com.temp.client.foundation.widget.dialog;

import com.temp.client.foundation.handler.DialogClose;
import com.temp.client.foundation.util.UtilsGwt;
import com.temp.client.foundation.widget.LeftRightPanel;
import com.temp.client.foundation.widget.OurPushButton;
import com.temp.shared.utils.ExceptionStackTracePrintStream;
import com.temp.shared.utils.SourceIssues;
import com.temp.shared.utils.StringUtils;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * This custom dialog shows custom title, body lines (description) followed by a
 * centered 'close' button
 *
 * @author georgs
 */
public class ExceptionDialog extends SEDIDialogBox {

    public static final String DETAILS = "Details";

    public static final String DETAILS_BUTTON_SUBSTITUTION_ID = "{" + DETAILS + "}";

    private final SourceIssues sourceIssues;

    public ExceptionDialog(boolean noDetails, String title, Integer contentWidth, String source, String context, Throwable throwable, String... bodyTextBlocksAboveControlButtons) {
        super("images/dialog/alertIcon.png", contentWidth, title);

        sourceIssues = new SourceIssues(source, context, throwable);
        if (!sourceIssues.hasThrowables()) {
            throw new IllegalArgumentException("ExceptionDialog requested w/o an Exception!");
        }
        boolean detailsButtonAdded = false;
        VerticalPanel panel = new VerticalPanel();

        if (bodyTextBlocksAboveControlButtons != null) {
            for (String block : bodyTextBlocksAboveControlButtons) {
                if (block != null) {
                    Widget widget;
                    int addDetailsAt = block.indexOf(DETAILS_BUTTON_SUBSTITUTION_ID);
                    if (addDetailsAt == -1) {
                        widget = makeLabel(block);
                    } else {
                        String left = block.substring(0, addDetailsAt);
                        String right = block.substring(addDetailsAt + DETAILS_BUTTON_SUBSTITUTION_ID.length());
                        if (noDetails) {
                            widget = makeLabel(left + right);
                        } else {
                            detailsButtonAdded = true;
                            if (StringUtils.isBlank(right)) {
                                widget = new LeftRightPanel(makeLabel(left), createDetailsButton());
                            } else {
                                widget = UtilsGwt.horizontal(makeLabel(left), createDetailsButton(), makeLabel(right));
                            }
                        }
                    }
                    addWithSpacing(panel, widget);
                }
            }
        }
        if (!detailsButtonAdded && !noDetails) {
            addWithSpacing(panel, new LeftRightPanel(makeLabel(" "), createDetailsButton()));
        }
        setBody(panel, new OurPushButton("close").add(hideClickHandler));
    }

    public ExceptionDialog(boolean noDetails, String title, String source, String context, Throwable throwable, String... bodyTextBlocksAboveControlButtons) {
        this(noDetails, title, null, source, context, throwable, bodyTextBlocksAboveControlButtons);
    }

    public void add(String context, Throwable... throwables) {
        sourceIssues.add(context, throwables);
    }

    public void show(DialogClose closeListener) {
        setCloseListener(closeListener);
        show();
    }

    private Widget createDetailsButton() {
        return new OurPushButton("details", new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                ExceptionStackTracePrintStream ps = new ExceptionStackTracePrintStream();
                sourceIssues.dumpToAsHTML(ps, !GWT.isProdMode());
                UtilsGwt.windowOpenWithHtml("Exceptions", UtilsGwt.CHROMELESS_SCROLLABLE_WITH_MENUS, wrapWithHtmlStuff(ps.toString()));
            }
        });
    }

    protected String wrapWithHtmlStuff(String details) {
        return "<!DOCTYPE html>\n" + //
                "<html><body style='font-family:sans-serif'>" + details + "</body></html>";
    }
}

Commits for litesoft/trunk/GWT_Sandbox/FormEngine/src/com/temp/client/foundation/widget/dialog/ExceptionDialog.java

Diff revisions: vs.
Revision Author Commited Message
626 GeorgeS picture GeorgeS Wed 11 Apr, 2012 19:39:41 +0000