1 package eu
.etaxonomy
.taxeditor
;
4 import org
.eclipse
.core
.runtime
.IStatus
;
5 import org
.eclipse
.ui
.application
.IWorkbenchConfigurer
;
6 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
7 import org
.eclipse
.ui
.application
.WorkbenchAdvisor
;
8 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
9 import org
.eclipse
.ui
.statushandlers
.AbstractStatusHandler
;
10 import org
.eclipse
.ui
.statushandlers
.StatusAdapter
;
11 import org
.springframework
.remoting
.RemoteAccessException
;
12 import org
.springframework
.remoting
.RemoteConnectFailureException
;
14 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
19 * <p>ApplicationWorkbenchAdvisor class.</p>
24 public class ApplicationWorkbenchAdvisor
extends WorkbenchAdvisor
{
26 private CdmStatusHandler cdmStatusHandler
;
30 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
34 public WorkbenchWindowAdvisor
createWorkbenchWindowAdvisor(
35 IWorkbenchWindowConfigurer configurer
) {
36 return new ApplicationWorkbenchWindowAdvisor(configurer
);
42 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
45 * <p>getInitialWindowPerspectiveId</p>
47 * @return a {@link java.lang.String} object.
50 public String
getInitialWindowPerspectiveId() {
51 return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
56 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
60 public void initialize(IWorkbenchConfigurer configurer
) {
61 super.initialize(configurer
);
63 // Remembers the user's view layout, window size, window location etc.
64 // for the next time application is started
65 configurer
.setSaveAndRestore(true);
70 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
73 public synchronized AbstractStatusHandler
getWorkbenchErrorHandler() {
74 if (cdmStatusHandler
== null) {
75 cdmStatusHandler
= new CdmStatusHandler();
77 return cdmStatusHandler
;
82 * Custom status handler for handling scenarios which are
83 * not handled by the editor (e.g. runtime exceptions).
85 * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
86 * is not used or extended because we need a handler for specific scenarios
87 * which displays a custom built error dialog.
92 class CdmStatusHandler
extends AbstractStatusHandler
{
94 private Throwable previousT
;
96 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
99 public void handle(StatusAdapter statusAdapter
, int style
)
102 if(statusAdapter
.getStatus().matches(IStatus
.ERROR
)) {
104 IStatus status
= statusAdapter
.getStatus();
105 Throwable t
= statusAdapter
.getStatus().getException();
106 // NOTE : the global status handling mechanism in the case of
107 // runtime exceptions is called twice, once by the application
108 // throwing the exception and then by the rcp logging mechanism
109 // The check below is to make sure that the same exception is
110 // not shown twice in succession.
111 if(t
!= null && previousT
== t
) {
115 // NOTE : Currently we only allow RuntimeExceptions since
116 // allowing all kinds of exceptions would also include
117 // those in generated status objects coming from from logging triggers
118 // leading to a recursive infinite loop of :
119 // initial exception thrown -> status handling -> dialog opening + logging of status ->
120 // status handling -> dialog opening + logging of status ... and so on
122 t
instanceof RuntimeException
&&
123 ! "Widget is disposed".equals(t
.getMessage()) &&
124 ! handleKnownRuntimeException(t
,statusAdapter
.getStatus().getPlugin())) {
126 MessagingUtils
.errorDialog("Unexpected error",
128 MessagingUtils
.UNEXPECTED_ERROR_MESSAGE
,
129 statusAdapter
.getStatus().getPlugin(),
137 private boolean handleKnownRuntimeException(Throwable t
, String pluginId
) {
138 if(t
instanceof RemoteConnectFailureException
||
139 t
.getCause() instanceof RemoteConnectFailureException
) {
140 MessagingUtils
.errorDialog("Connection Failure",
142 MessagingUtils
.CONNECTION_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),
149 if(t
instanceof RemoteAccessException
||
150 t
.getCause() instanceof RemoteAccessException
) {
151 MessagingUtils
.errorDialog("Remote Access Error",
153 MessagingUtils
.REMOTE_ACCESS_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),