1
|
package eu.etaxonomy.taxeditor;
|
2
|
|
3
|
|
4
|
import org.eclipse.core.runtime.IStatus;
|
5
|
import org.eclipse.ui.application.IWorkbenchConfigurer;
|
6
|
import org.eclipse.ui.application.IWorkbenchWindowConfigurer;
|
7
|
import org.eclipse.ui.application.WorkbenchAdvisor;
|
8
|
import org.eclipse.ui.application.WorkbenchWindowAdvisor;
|
9
|
import org.eclipse.ui.statushandlers.AbstractStatusHandler;
|
10
|
import org.eclipse.ui.statushandlers.StatusAdapter;
|
11
|
import org.springframework.remoting.RemoteAccessException;
|
12
|
import org.springframework.remoting.RemoteConnectFailureException;
|
13
|
|
14
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
15
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
16
|
|
17
|
|
18
|
|
19
|
/**
|
20
|
* <p>ApplicationWorkbenchAdvisor class.</p>
|
21
|
*
|
22
|
* @author n.hoffmann
|
23
|
* @version $Id: $
|
24
|
*/
|
25
|
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
|
26
|
|
27
|
private CdmStatusHandler cdmStatusHandler;
|
28
|
|
29
|
/*
|
30
|
* (non-Javadoc)
|
31
|
* @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
|
32
|
*/
|
33
|
/** {@inheritDoc} */
|
34
|
@Override
|
35
|
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
|
36
|
IWorkbenchWindowConfigurer configurer) {
|
37
|
return new ApplicationWorkbenchWindowAdvisor(configurer);
|
38
|
}
|
39
|
|
40
|
|
41
|
/*
|
42
|
* (non-Javadoc)
|
43
|
* @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
|
44
|
*/
|
45
|
/**
|
46
|
* <p>getInitialWindowPerspectiveId</p>
|
47
|
*
|
48
|
* @return a {@link java.lang.String} object.
|
49
|
*/
|
50
|
@Override
|
51
|
public String getInitialWindowPerspectiveId() {
|
52
|
return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
|
53
|
}
|
54
|
|
55
|
/*
|
56
|
* (non-Javadoc)
|
57
|
* @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
|
58
|
*/
|
59
|
/** {@inheritDoc} */
|
60
|
@Override
|
61
|
public void initialize(IWorkbenchConfigurer configurer) {
|
62
|
super.initialize(configurer);
|
63
|
|
64
|
// Remembers the user's view layout, window size, window location etc.
|
65
|
// for the next time application is started
|
66
|
configurer.setSaveAndRestore(true);
|
67
|
}
|
68
|
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
|
72
|
*/
|
73
|
@Override
|
74
|
public synchronized AbstractStatusHandler getWorkbenchErrorHandler() {
|
75
|
if (cdmStatusHandler == null) {
|
76
|
cdmStatusHandler = new CdmStatusHandler();
|
77
|
}
|
78
|
return cdmStatusHandler;
|
79
|
}
|
80
|
|
81
|
|
82
|
/**
|
83
|
* Custom status handler for handling scenarios which are
|
84
|
* not handled by the editor (e.g. runtime exceptions).
|
85
|
*
|
86
|
* The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
|
87
|
* is not used or extended because we need a handler for specific scenarios
|
88
|
* which displays a custom built error dialog.
|
89
|
*
|
90
|
* @author cmathew
|
91
|
*
|
92
|
*/
|
93
|
class CdmStatusHandler extends AbstractStatusHandler {
|
94
|
|
95
|
private Throwable previousT;
|
96
|
/* (non-Javadoc)
|
97
|
* @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
|
98
|
*/
|
99
|
@Override
|
100
|
public void handle(StatusAdapter statusAdapter, int style)
|
101
|
{
|
102
|
|
103
|
if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
|
104
|
|
105
|
IStatus status = statusAdapter.getStatus();
|
106
|
Throwable t = statusAdapter.getStatus().getException();
|
107
|
// NOTE : the global status handling mechanism in the case of
|
108
|
// runtime exceptions is called twice, once by the application
|
109
|
// throwing the exception and then by the rcp logging mechanism
|
110
|
// The check below is to make sure that the same exception is
|
111
|
// not shown twice in succession.
|
112
|
if(t != null && previousT == t) {
|
113
|
return;
|
114
|
}
|
115
|
previousT = t;
|
116
|
|
117
|
|
118
|
|
119
|
// NOTE : Currently we only allow RuntimeExceptions since
|
120
|
// allowing all kinds of exceptions would also include
|
121
|
// those in generated status objects coming from from logging triggers
|
122
|
// leading to a recursive infinite loop of :
|
123
|
// initial exception thrown -> status handling -> dialog opening + logging of status ->
|
124
|
// status handling -> dialog opening + logging of status ... and so on
|
125
|
if(t != null &&
|
126
|
t instanceof RuntimeException &&
|
127
|
! "Widget is disposed".equals(t.getMessage()) &&
|
128
|
! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) {
|
129
|
|
130
|
MessagingUtils.errorDialog("Unexpected error",
|
131
|
null,
|
132
|
MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
|
133
|
statusAdapter.getStatus().getPlugin(),
|
134
|
t,
|
135
|
true);
|
136
|
|
137
|
} else if (t != null && ("Widget is disposed".equals(t.getMessage()))){
|
138
|
MessagingUtils.warn(this.getClass(), t.getMessage());
|
139
|
if (PreferencesUtil.isDebugMode()){
|
140
|
MessagingUtils.warningDialog("Widget is disposed", null, status);
|
141
|
}
|
142
|
}{
|
143
|
|
144
|
}
|
145
|
}
|
146
|
}
|
147
|
|
148
|
private boolean handleKnownRuntimeException(Throwable t, String pluginId) {
|
149
|
if(t instanceof RemoteConnectFailureException ||
|
150
|
t.getCause() instanceof RemoteConnectFailureException) {
|
151
|
MessagingUtils.errorDialog("Connection Failure",
|
152
|
null,
|
153
|
MessagingUtils.CONNECTION_FAILURE_MESSAGE + System.getProperty("line.separator"),
|
154
|
pluginId,
|
155
|
t,
|
156
|
true,
|
157
|
false);
|
158
|
return true;
|
159
|
}
|
160
|
if(t instanceof RemoteAccessException ||
|
161
|
t.getCause() instanceof RemoteAccessException) {
|
162
|
MessagingUtils.errorDialog("Remote Access Error",
|
163
|
null,
|
164
|
MessagingUtils.REMOTE_ACCESS_FAILURE_MESSAGE + System.getProperty("line.separator"),
|
165
|
pluginId,
|
166
|
t,
|
167
|
true,
|
168
|
false);
|
169
|
return true;
|
170
|
}
|
171
|
return false;
|
172
|
}
|
173
|
}
|
174
|
|
175
|
|
176
|
|
177
|
}
|