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