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 | |
|
26 | |
import com.google.gwt.core.client.GWT; |
27 | |
import com.google.gwt.user.client.Command; |
28 | |
import com.google.gwt.user.client.DeferredCommand; |
29 | |
import com.google.gwt.user.client.ui.SimplePanel; |
30 | |
import com.google.gwt.user.client.ui.VerticalPanel; |
31 | |
|
32 | 0 | public class KSErrorDialog { |
33 | |
|
34 | 0 | final static ApplicationContext context = Application.getApplicationContext(); |
35 | |
|
36 | 0 | public enum MessagesRequired { |
37 | 0 | DIALOG_TITLE("errorDialogTitle"), |
38 | 0 | DESCRIBE_ACTION("describeAction"), |
39 | 0 | ERROR_DESCRIPTION("errorDescription"); |
40 | |
|
41 | |
private String messageId; |
42 | 0 | private MessagesRequired(String messageId) { |
43 | 0 | this.messageId = messageId; |
44 | 0 | } |
45 | |
public String toString() { |
46 | 0 | return this.messageId; |
47 | |
} |
48 | |
} |
49 | |
|
50 | |
public static void bindUncaughtExceptionHandler() { |
51 | 0 | GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() { |
52 | |
public void onUncaughtException(Throwable e) { |
53 | 0 | GWT.log(e.getMessage(), e); |
54 | 0 | KSErrorDialog.show(e); |
55 | 0 | } |
56 | |
}); |
57 | 0 | } |
58 | |
|
59 | |
public static void show(final Throwable error) { |
60 | 0 | final KSLightBox lightbox = new KSLightBox(); |
61 | |
|
62 | 0 | final VerticalPanel panel = new VerticalPanel(); |
63 | 0 | panel.addStyleName("KS-Error-Dialog"); |
64 | |
|
65 | 0 | final KSLabel title = new KSLabel(context.getMessage(MessagesRequired.DIALOG_TITLE.toString())); |
66 | 0 | title.addStyleName("KS-Error-Dialog-Title"); |
67 | |
|
68 | 0 | final KSLabel errorDescriptionLabel = new KSLabel(context.getMessage(MessagesRequired.ERROR_DESCRIPTION.toString())); |
69 | 0 | errorDescriptionLabel.addStyleName("KS-Error-Dialog-Label"); |
70 | |
|
71 | 0 | final SimplePanel errorDescriptionPanel = new SimplePanel(); |
72 | 0 | errorDescriptionPanel.addStyleName("KS-Error-Dialog-Panel"); |
73 | |
|
74 | 0 | final KSTextArea errorDescription = new KSTextArea(); |
75 | 0 | errorDescription.setText(getErrorDescription(error)); |
76 | 0 | errorDescription.addStyleName("KS-Error-Dialog-TextArea"); |
77 | 0 | errorDescription.setReadOnly(true); |
78 | |
|
79 | 0 | errorDescriptionPanel.add(errorDescription); |
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
|
91 | 0 | final OkGroup buttonPanel = new OkGroup(new Callback<OkEnum>(){ |
92 | |
|
93 | |
@Override |
94 | |
public void exec(OkEnum result) { |
95 | 0 | switch(result){ |
96 | |
case Ok: |
97 | 0 | DeferredCommand.addCommand(new Command() { |
98 | |
public void execute() { |
99 | 0 | sendReport(error); |
100 | 0 | lightbox.hide(); |
101 | 0 | } |
102 | |
}); |
103 | |
break; |
104 | |
} |
105 | 0 | } |
106 | |
}); |
107 | |
|
108 | 0 | panel.add(title); |
109 | 0 | panel.add(errorDescriptionLabel); |
110 | 0 | panel.add(errorDescriptionPanel); |
111 | |
|
112 | |
|
113 | 0 | panel.add(buttonPanel); |
114 | |
|
115 | 0 | panel.setSize("100", "100"); |
116 | |
|
117 | 0 | lightbox.setWidget(panel); |
118 | 0 | lightbox.setSize(440, 200); |
119 | 0 | lightbox.show(); |
120 | |
|
121 | 0 | } |
122 | |
|
123 | |
private static String getErrorDescription(Throwable error) { |
124 | |
|
125 | 0 | return error.getMessage(); |
126 | |
} |
127 | |
|
128 | |
private static void sendReport(final Throwable error) { |
129 | |
|
130 | 0 | Logger.getClientContextInfo().put("logType", "clientError"); |
131 | |
|
132 | 0 | Logger.error("Uncaught exception", error); |
133 | 0 | Logger.sendLogs(); |
134 | |
|
135 | |
|
136 | 0 | Logger.getClientContextInfo().clear(); |
137 | 0 | } |
138 | |
|
139 | |
} |