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