1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.student.common.ui.client.widgets; |
17 | |
|
18 | |
|
19 | |
import org.kuali.student.common.ui.client.application.Application; |
20 | |
import org.kuali.student.common.ui.client.application.ApplicationContext; |
21 | |
import org.kuali.student.common.ui.client.logging.Logger; |
22 | |
import org.kuali.student.common.ui.client.mvc.Callback; |
23 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.OkGroup; |
24 | |
import org.kuali.student.common.ui.client.widgets.buttongroups.ButtonEnumerations.OkEnum; |
25 | |
import org.kuali.student.common.ui.client.widgets.table.summary.StaticDeletemeLineLogger; |
26 | |
|
27 | |
import com.google.gwt.core.client.GWT; |
28 | |
import com.google.gwt.user.client.Command; |
29 | |
import com.google.gwt.user.client.DeferredCommand; |
30 | |
import com.google.gwt.user.client.Window; |
31 | |
import com.google.gwt.user.client.ui.SimplePanel; |
32 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
33 | |
|
34 | 0 | public class KSErrorDialog { |
35 | |
|
36 | 0 | final static ApplicationContext context = Application.getApplicationContext(); |
37 | |
|
38 | 0 | public enum MessagesRequired { |
39 | 0 | DIALOG_TITLE("errorDialogTitle"), |
40 | 0 | DESCRIBE_ACTION("describeAction"), |
41 | 0 | ERROR_DESCRIPTION("errorDescription"); |
42 | |
|
43 | |
private String messageId; |
44 | 0 | private MessagesRequired(String messageId) { |
45 | 0 | this.messageId = messageId; |
46 | 0 | } |
47 | |
public String toString() { |
48 | 0 | return this.messageId; |
49 | |
} |
50 | |
} |
51 | |
|
52 | |
public static void bindUncaughtExceptionHandler() { |
53 | 0 | GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { |
54 | |
public void onUncaughtException(Throwable e) { |
55 | 0 | GWT.log(e.getMessage(), e); |
56 | 0 | StaticDeletemeLineLogger.AlertLastLine(); |
57 | 0 | Window.alert("Uncaught exception was thrown:"+getStackTrace(e)+"\nMessage:"+e.getMessage()); |
58 | 0 | KSErrorDialog.show(e); |
59 | 0 | } |
60 | |
}); |
61 | 0 | } |
62 | |
|
63 | |
private static String getStackTrace(Throwable t){ |
64 | 0 | StringBuilder sb = new StringBuilder(); |
65 | 0 | appendStackTrace(t,sb); |
66 | 0 | return sb.toString(); |
67 | |
} |
68 | |
|
69 | |
private static void appendStackTrace(Throwable t, StringBuilder s) { |
70 | 0 | s.append(t.toString()); |
71 | 0 | s.append(": at\n"); |
72 | 0 | StackTraceElement[] stack = t.getStackTrace(); |
73 | 0 | for (StackTraceElement frame : stack) { |
74 | 0 | s.append(frame.toString()); |
75 | 0 | s.append("\n"); |
76 | |
} |
77 | 0 | } |
78 | |
|
79 | |
public static void show(final Throwable error) { |
80 | 0 | final KSLightBox lightbox = new KSLightBox(); |
81 | |
|
82 | 0 | final VerticalPanel panel = new VerticalPanel(); |
83 | 0 | panel.addStyleName("KS-Error-Dialog"); |
84 | |
|
85 | 0 | final KSLabel title = new KSLabel(context.getMessage(MessagesRequired.DIALOG_TITLE.toString())); |
86 | 0 | title.addStyleName("KS-Error-Dialog-Title"); |
87 | |
|
88 | 0 | final KSLabel errorDescriptionLabel = new KSLabel(context.getMessage(MessagesRequired.ERROR_DESCRIPTION.toString())); |
89 | 0 | errorDescriptionLabel.addStyleName("KS-Error-Dialog-Label"); |
90 | |
|
91 | 0 | final SimplePanel errorDescriptionPanel = new SimplePanel(); |
92 | 0 | errorDescriptionPanel.addStyleName("KS-Error-Dialog-Panel"); |
93 | |
|
94 | 0 | final KSTextArea errorDescription = new KSTextArea(); |
95 | 0 | errorDescription.setText(getErrorDescription(error)); |
96 | 0 | errorDescription.addStyleName("KS-Error-Dialog-TextArea"); |
97 | 0 | errorDescription.setReadOnly(true); |
98 | |
|
99 | 0 | errorDescriptionPanel.add(errorDescription); |
100 | |
|
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | 0 | final OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){ |
112 | |
|
113 | |
@Override |
114 | |
public void exec(OkEnum result) { |
115 | 0 | switch(result){ |
116 | |
case Ok: |
117 | 0 | DeferredCommand.addCommand(new Command() { |
118 | |
public void execute() { |
119 | 0 | sendReport(error); |
120 | 0 | lightbox.hide(); |
121 | 0 | } |
122 | |
}); |
123 | |
break; |
124 | |
} |
125 | 0 | } |
126 | |
}); |
127 | |
|
128 | 0 | panel.add(title); |
129 | 0 | panel.add(errorDescriptionLabel); |
130 | 0 | panel.add(errorDescriptionPanel); |
131 | |
|
132 | |
|
133 | 0 | panel.add(buttonPanel); |
134 | |
|
135 | 0 | panel.setSize("100", "100"); |
136 | |
|
137 | 0 | lightbox.setWidget(panel); |
138 | 0 | lightbox.setSize(440, 200); |
139 | 0 | lightbox.show(); |
140 | |
|
141 | 0 | } |
142 | |
|
143 | |
private static String getErrorDescription(Throwable error) { |
144 | |
|
145 | 0 | return error.getMessage(); |
146 | |
} |
147 | |
|
148 | |
private static void sendReport(final Throwable error) { |
149 | |
|
150 | 0 | Logger.getClientContextInfo().put("logType", "clientError"); |
151 | |
|
152 | 0 | Logger.error("Uncaught exception", error); |
153 | 0 | Logger.sendLogs(); |
154 | |
|
155 | |
|
156 | 0 | Logger.getClientContextInfo().clear(); |
157 | 0 | } |
158 | |
|
159 | |
} |