1 package eu
.etaxonomy
.taxeditor
;
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
;
15 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
16 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
17 import eu
.etaxonomy
.taxeditor
.store
.CdmAuthenticationException
;
22 * <p>ApplicationWorkbenchAdvisor class.</p>
27 public class ApplicationWorkbenchAdvisor
extends WorkbenchAdvisor
{
29 private CdmStatusHandler cdmStatusHandler
;
33 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
37 public WorkbenchWindowAdvisor
createWorkbenchWindowAdvisor(
38 IWorkbenchWindowConfigurer configurer
) {
39 return new ApplicationWorkbenchWindowAdvisor(configurer
);
45 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
48 * <p>getInitialWindowPerspectiveId</p>
50 * @return a {@link java.lang.String} object.
53 public String
getInitialWindowPerspectiveId() {
54 // if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_CHECKLIST_PERSPECTIVE)){
55 // return "eu.etaxonomy.taxeditor.perspective.checklistperspective";
58 return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
63 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
67 public void initialize(IWorkbenchConfigurer configurer
) {
68 super.initialize(configurer
);
70 // Remembers the user's view layout, window size, window location etc.
71 // for the next time application is started
72 configurer
.setSaveAndRestore(true);
77 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
80 public synchronized AbstractStatusHandler
getWorkbenchErrorHandler() {
81 if (cdmStatusHandler
== null) {
82 cdmStatusHandler
= new CdmStatusHandler();
84 return cdmStatusHandler
;
89 * Custom status handler for handling scenarios which are
90 * not handled by the editor (e.g. runtime exceptions).
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.
99 class CdmStatusHandler
extends AbstractStatusHandler
{
101 private Throwable previousT
;
103 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
106 public void handle(StatusAdapter statusAdapter
, int style
)
109 if(statusAdapter
.getStatus().matches(IStatus
.ERROR
)) {
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
) {
123 if (t
!= null && (t
.getCause() instanceof RemoteAccessException
|| t
instanceof NoHttpResponseException
|| t
.getCause() instanceof CdmAuthenticationException
|| t
.getMessage().contains("status code = 403"))){
124 MessagingUtils
.errorDialog("Access denied",
126 MessagingUtils
.ACCESS_DENIED
,
127 statusAdapter
.getStatus().getPlugin(),
133 // NOTE : Currently we only allow RuntimeExceptions since
134 // allowing all kinds of exceptions would also include
135 // those in generated status objects coming from from logging triggers
136 // leading to a recursive infinite loop of :
137 // initial exception thrown -> status handling -> dialog opening + logging of status ->
138 // status handling -> dialog opening + logging of status ... and so on
140 t
instanceof RuntimeException
&&
141 ! "Widget is disposed".equals(t
.getMessage()) &&
142 ! handleKnownRuntimeException(t
,statusAdapter
.getStatus().getPlugin())) {
144 MessagingUtils
.errorDialog("Unexpected error",
146 MessagingUtils
.UNEXPECTED_ERROR_MESSAGE
,
147 statusAdapter
.getStatus().getPlugin(),
151 } else if (t
!= null && ("Widget is disposed".equals(t
.getMessage()))){
152 MessagingUtils
.warn(this.getClass(), t
);
153 if (PreferencesUtil
.isShowUpWidgetIsDisposedMessages()){
154 MessagingUtils
.errorDialog("Widget is disposed",
156 MessagingUtils
.WIDGET_IS_DISPOSED_MESSAGE
,
157 statusAdapter
.getStatus().getPlugin(),
166 private boolean handleKnownRuntimeException(Throwable t
, String pluginId
) {
167 if(t
instanceof RemoteConnectFailureException
||
168 t
.getCause() instanceof RemoteConnectFailureException
) {
169 MessagingUtils
.errorDialog("Connection Failure",
171 MessagingUtils
.CONNECTION_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),
178 if(t
instanceof RemoteAccessException
||
179 t
.getCause() instanceof RemoteAccessException
) {
180 MessagingUtils
.errorDialog("Remote Access Error",
182 MessagingUtils
.REMOTE_ACCESS_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),
189 if (t
instanceof CdmAuthenticationException
){
190 MessagingUtils
.info("You are logged in now but you are not permitted to use the TaxEditor with the selected data source");