1 package fr.ifremer.tutti.ui.swing.util;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import fr.ifremer.tutti.ui.swing.content.actions.AbstractChangeScreenAction;
26 import fr.ifremer.tutti.ui.swing.util.actions.LongActionSupport;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29 import org.nuiton.jaxx.application.ApplicationTechnicalException;
30 import org.nuiton.jaxx.application.swing.action.ApplicationActionException;
31 import org.nuiton.jaxx.application.swing.util.ApplicationErrorHelper;
32 import org.nuiton.jaxx.application.swing.util.ApplicationExceptionHandler;
33
34 import java.beans.PropertyVetoException;
35
36
37
38
39
40
41
42
43
44
45
46
47 public class TuttiExceptionHandler extends ApplicationExceptionHandler {
48
49 private static final Log log =
50 LogFactory.getLog(TuttiExceptionHandler.class);
51
52 public TuttiExceptionHandler(ApplicationErrorHelper errorHelper) {
53 super(errorHelper);
54 }
55
56 @Override
57 public void uncaughtException(Thread t, Throwable ex) {
58 if (t.getName().startsWith("AWT-EventQueue-") || ex.getCause() instanceof PropertyVetoException) {
59
60
61
62 if (log.isErrorEnabled()) {
63 log.error("Swallow Swing error: " + ex.getMessage(), ex);
64 }
65
66 } else {
67
68 super.uncaughtException(t, ex);
69 }
70 }
71
72 @Override
73 protected void handleException(String tname, Throwable ex) {
74 if (log.isErrorEnabled()) {
75 log.error("Global application exception [" + tname + "]", ex);
76 }
77
78 Throwable cause = getCause(ex);
79
80 boolean backToScreen = false;
81
82 LongActionSupport action = null;
83
84 if (cause instanceof ApplicationActionException) {
85
86 ApplicationActionException actionException = (ApplicationActionException) cause;
87 cause = cause.getCause();
88
89 if (log.isDebugEnabled()) {
90 log.debug("Action error cause:", cause);
91 }
92
93 action = (LongActionSupport) actionException.getAction();
94
95 if (action instanceof AbstractChangeScreenAction) {
96 backToScreen = true;
97 }
98 }
99
100 showErrorDialog(cause.getMessage(), cause);
101
102 if (backToScreen) {
103
104 action.getContext().setFallBackScreen();
105 }
106 }
107
108 @Override
109 protected Throwable getCause(Throwable ex) {
110
111
112 Throwable cause = super.getCause(ex);
113
114 if (cause == null) {
115
116 if (ex instanceof ApplicationTechnicalException) {
117 cause = ex;
118 }
119 }
120
121 return cause;
122
123 }
124 }