package eu.etaxonomy.taxeditor; import java.io.OptionalDataException; import org.apache.http.NoHttpResponseException; import org.eclipse.core.runtime.IStatus; import org.eclipse.ui.application.IWorkbenchConfigurer; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; import org.eclipse.ui.statushandlers.AbstractStatusHandler; import org.eclipse.ui.statushandlers.StatusAdapter; import org.springframework.remoting.RemoteAccessException; import org.springframework.remoting.RemoteConnectFailureException; import eu.etaxonomy.cdm.persistence.permission.PermissionDeniedException; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.store.CdmAuthenticationException; /** *
ApplicationWorkbenchAdvisor class.
* * @author n.hoffmann */ public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor { private CdmStatusHandler cdmStatusHandler; @Override public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor( IWorkbenchWindowConfigurer configurer) { return new ApplicationWorkbenchWindowAdvisor(configurer); } @Override public String getInitialWindowPerspectiveId() { // if (PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_CHECKLIST_PERSPECTIVE)){ // return "eu.etaxonomy.taxeditor.perspective.checklistperspective"; // } return "eu.etaxonomy.taxeditor.application.perspective.taxonomic"; } @Override public void initialize(IWorkbenchConfigurer configurer) { super.initialize(configurer); // Remembers the user's view layout, window size, window location etc. // for the next time application is started configurer.setSaveAndRestore(true); } @Override public synchronized AbstractStatusHandler getWorkbenchErrorHandler() { if (cdmStatusHandler == null) { cdmStatusHandler = new CdmStatusHandler(); } return cdmStatusHandler; } /** * Custom status handler for handling scenarios which are * not handled by the editor (e.g. runtime exceptions). * * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler} * is not used or extended because we need a handler for specific scenarios * which displays a custom built error dialog. * * @author cmathew */ class CdmStatusHandler extends AbstractStatusHandler { private Throwable previousT; @Override public void handle(StatusAdapter statusAdapter, int style){ if(statusAdapter.getStatus().matches(IStatus.ERROR)) { Throwable t = statusAdapter.getStatus().getException(); if (t != null){ // NOTE : the global status handling mechanism in the case of // runtime exceptions is called twice, once by the application // throwing the exception and then by the rcp logging mechanism. // The check below is to make sure that the same exception is // not shown twice in succession. if(previousT == t) { return; } previousT = t; if (t.getCause() instanceof PermissionDeniedException){ MessagingUtils.informationDialog("Permission denied", MessagingUtils.PERMISSION_DENIED); } else if (t instanceof NoHttpResponseException || t.getCause() instanceof CdmAuthenticationException || (t.getMessage() != null && t.getMessage().contains("status code = 403"))){ t.printStackTrace(); MessagingUtils.informationDialog("Access denied", MessagingUtils.ACCESS_DENIED); }else if (includesCause(t, OptionalDataException.class)){ MessagingUtils.informationDialog("Error (OptionalDataException)", MessagingUtils.RESTART_EDITOR_MESSAGE ); }else // NOTE : Currently we only allow RuntimeExceptions since // allowing all kinds of exceptions would also include // those in generated status objects coming from from logging triggers // leading to a recursive infinite loop of : // initial exception thrown -> status handling -> dialog opening + logging of status -> // status handling -> dialog opening + logging of status ... and so on if(t instanceof RuntimeException && ! "Widget is disposed".equals(t.getMessage()) && ! handleKnownRuntimeException(t,statusAdapter.getStatus().getPlugin())) { MessagingUtils.errorDialog("Error", null, MessagingUtils.UNEXPECTED_ERROR_MESSAGE, statusAdapter.getStatus().getPlugin(), t, true); } else if (("Widget is disposed".equals(t.getMessage()))){ MessagingUtils.warn(this.getClass(), t); if (PreferencesUtil.isShowUpWidgetIsDisposedMessages()){ MessagingUtils.errorDialog("Widget is disposed", null, MessagingUtils.WIDGET_IS_DISPOSED_MESSAGE, statusAdapter.getStatus().getPlugin(), t, true); } } } } } /** * Analyzes whether the throwable includes an exception of type clazz * in the stacktrace. */ private