package eu.etaxonomy.taxeditor;
+
+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 eu.etaxonomy.taxeditor.model.MessagingUtils;
+
/**
*/
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
+ private CdmStatusHandler cdmStatusHandler;
/*
* (non-Javadoc)
* @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
*/
/** {@inheritDoc} */
- public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
+ @Override
+ public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
IWorkbenchWindowConfigurer configurer) {
return new ApplicationWorkbenchWindowAdvisor(configurer);
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
*
* @return a {@link java.lang.String} object.
*/
- public String getInitialWindowPerspectiveId() {
+ @Override
+ public String getInitialWindowPerspectiveId() {
return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
}
-
+
/*
* (non-Javadoc)
* @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
*/
/** {@inheritDoc} */
- public void initialize(IWorkbenchConfigurer configurer) {
+ @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);
- }
-
+ }
+
+
/* (non-Javadoc)
- * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup()
+ * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
*/
- /** {@inheritDoc} */
@Override
- public void preStartup() {
- // TODO Auto-generated method stub
- super.preStartup();
- // XXX check for updates before starting up.
- // If an update is performed, restart.
-// if (P2Util.checkForUpdates())
-// PlatformUI.getWorkbench().restart();
+ public synchronized AbstractStatusHandler getWorkbenchErrorHandler() {
+ if (cdmStatusHandler == null) {
+ cdmStatusHandler = new CdmStatusHandler();
+ }
+ return cdmStatusHandler;
}
-
-/**
- * see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=234252
- */
-// public void initialize(IWorkbenchConfigurer configurer) {
-//
-// WorkbenchAdapterBuilder.registerAdapters();
-//
-// final String ICONS_PATH = "icons/full/";
-// final String PATH_OBJECT = ICONS_PATH + "obj16/";
-// Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
-// declareWorkbenchImage(configurer, ideBundle,
-// IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + "prj_obj.gif",
-// true);
-// declareWorkbenchImage(configurer, ideBundle,
-// IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
-// + "cprj_obj.gif", true);
-//
-// }
-//
-// private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p,
-// Bundle ideBundle, String symbolicName, String path, boolean shared) {
-// URL url = ideBundle.getEntry(path);
-// ImageDescriptor desc = ImageDescriptor.createFromURL(url);
-// configurer_p.declareImage(symbolicName, desc, shared);
-// }
-//
-// public IAdaptable getDefaultPageInput() {
-// IWorkspace workspace = ResourcesPlugin.getWorkspace();
-// return workspace.getRoot();
-// }
-
-
+
+
+ /**
+ * 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 {
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
+ */
+ @Override
+ public void handle(StatusAdapter statusAdapter, int style)
+ {
+ if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
+
+ IStatus status = statusAdapter.getStatus();
+ Throwable t = statusAdapter.getStatus().getException();
+ // 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 != null && t instanceof RuntimeException && ! "Widget is disposed".equals(t.getMessage())){
+ MessagingUtils.errorDialog("Unexpected error",
+ null,
+ MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
+ statusAdapter.getStatus().getPlugin(),
+ t,
+ true);
+ }
+ }
+ }
+ }
+
+
}