1 package eu
.etaxonomy
.taxeditor
;
4 import java
.io
.PrintWriter
;
5 import java
.io
.StringWriter
;
6 import java
.rmi
.activation
.Activator
;
8 import org
.eclipse
.core
.runtime
.IStatus
;
9 import org
.eclipse
.core
.runtime
.Status
;
10 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
11 import org
.eclipse
.swt
.widgets
.Shell
;
12 import org
.eclipse
.ui
.application
.IWorkbenchConfigurer
;
13 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
14 import org
.eclipse
.ui
.application
.WorkbenchAdvisor
;
15 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
16 import org
.eclipse
.ui
.statushandlers
.AbstractStatusHandler
;
17 import org
.eclipse
.ui
.statushandlers
.StatusAdapter
;
18 import org
.eclipse
.ui
.statushandlers
.StatusManager
;
20 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
25 * <p>ApplicationWorkbenchAdvisor class.</p>
30 public class ApplicationWorkbenchAdvisor
extends WorkbenchAdvisor
{
32 private CdmStatusHandler cdmStatusHandler
;
35 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
38 public WorkbenchWindowAdvisor
createWorkbenchWindowAdvisor(
39 IWorkbenchWindowConfigurer configurer
) {
40 return new ApplicationWorkbenchWindowAdvisor(configurer
);
46 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
49 * <p>getInitialWindowPerspectiveId</p>
51 * @return a {@link java.lang.String} object.
53 public String
getInitialWindowPerspectiveId() {
54 return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
59 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
62 public void initialize(IWorkbenchConfigurer configurer
) {
63 super.initialize(configurer
);
65 // Remembers the user's view layout, window size, window location etc.
66 // for the next time application is started
67 configurer
.setSaveAndRestore(true);
71 * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup()
75 public void preStartup() {
76 // TODO Auto-generated method stub
78 // XXX check for updates before starting up.
79 // If an update is performed, restart.
80 // if (P2Util.checkForUpdates())
81 // PlatformUI.getWorkbench().restart();
85 * see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=234252
87 // public void initialize(IWorkbenchConfigurer configurer) {
89 // WorkbenchAdapterBuilder.registerAdapters();
91 // final String ICONS_PATH = "icons/full/";
92 // final String PATH_OBJECT = ICONS_PATH + "obj16/";
93 // Bundle ideBundle = Platform.getBundle(IDEWorkbenchPlugin.IDE_WORKBENCH);
94 // declareWorkbenchImage(configurer, ideBundle,
95 // IDE.SharedImages.IMG_OBJ_PROJECT, PATH_OBJECT + "prj_obj.gif",
97 // declareWorkbenchImage(configurer, ideBundle,
98 // IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
99 // + "cprj_obj.gif", true);
103 // private void declareWorkbenchImage(IWorkbenchConfigurer configurer_p,
104 // Bundle ideBundle, String symbolicName, String path, boolean shared) {
105 // URL url = ideBundle.getEntry(path);
106 // ImageDescriptor desc = ImageDescriptor.createFromURL(url);
107 // configurer_p.declareImage(symbolicName, desc, shared);
110 // public IAdaptable getDefaultPageInput() {
111 // IWorkspace workspace = ResourcesPlugin.getWorkspace();
112 // return workspace.getRoot();
116 // public void eventLoopException(Throwable exception) {
117 // super.eventLoopException(exception);
118 // StoreUtil.messageDialog("Unexpected error", null, exception.getMessage(), exception);
123 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
126 public synchronized AbstractStatusHandler
getWorkbenchErrorHandler() {
127 if (cdmStatusHandler
== null) {
128 cdmStatusHandler
= new CdmStatusHandler();
130 return cdmStatusHandler
;
135 * Custom status handler for handling scenarios which are
136 * not handled by the editor (e.g. runtime exceptions).
138 * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
139 * is not used or extended because we need a handler for specific scenarios
140 * which displays a custom built error dialog.
145 class CdmStatusHandler
extends AbstractStatusHandler
{
148 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
151 public void handle(StatusAdapter statusAdapter
, int style
)
153 if(statusAdapter
.getStatus().matches(IStatus
.ERROR
)) {
155 IStatus status
= statusAdapter
.getStatus();
156 Throwable t
= statusAdapter
.getStatus().getException();
157 // NOTE : Currently we only allow RuntimeExceptions since
158 // allowing all kinds of exceptions would also include
159 // those in generated status objects coming from from logging triggers
160 // leading to a recursive infinite loop of :
161 // initial exception thrown -> status handling -> dialog opening + logging of status ->
162 // status handling -> dialog opening + logging of status ... and so on
163 if(t
!= null && t
instanceof RuntimeException
) {
164 MessagingUtils
.errorDialog("Unexpected error",
166 MessagingUtils
.UNEXPECTED_ERROR_MESSAGE
+ MessagingUtils
.CONTACT_MESSAGE
,
167 statusAdapter
.getStatus().getPlugin(),