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
;
15 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
20 * <p>ApplicationWorkbenchAdvisor class.</p>
25 public class ApplicationWorkbenchAdvisor
extends WorkbenchAdvisor
{
27 private CdmStatusHandler cdmStatusHandler
;
31 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
35 public WorkbenchWindowAdvisor
createWorkbenchWindowAdvisor(
36 IWorkbenchWindowConfigurer configurer
) {
37 return new ApplicationWorkbenchWindowAdvisor(configurer
);
43 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
46 * <p>getInitialWindowPerspectiveId</p>
48 * @return a {@link java.lang.String} object.
51 public String
getInitialWindowPerspectiveId() {
52 return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
57 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
61 public void initialize(IWorkbenchConfigurer configurer
) {
62 super.initialize(configurer
);
64 // Remembers the user's view layout, window size, window location etc.
65 // for the next time application is started
66 configurer
.setSaveAndRestore(true);
71 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
74 public synchronized AbstractStatusHandler
getWorkbenchErrorHandler() {
75 if (cdmStatusHandler
== null) {
76 cdmStatusHandler
= new CdmStatusHandler();
78 return cdmStatusHandler
;
83 * Custom status handler for handling scenarios which are
84 * not handled by the editor (e.g. runtime exceptions).
86 * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
87 * is not used or extended because we need a handler for specific scenarios
88 * which displays a custom built error dialog.
93 class CdmStatusHandler
extends AbstractStatusHandler
{
95 private Throwable previousT
;
97 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
100 public void handle(StatusAdapter statusAdapter
, int style
)
103 if(statusAdapter
.getStatus().matches(IStatus
.ERROR
)) {
105 IStatus status
= statusAdapter
.getStatus();
106 Throwable t
= statusAdapter
.getStatus().getException();
107 // NOTE : the global status handling mechanism in the case of
108 // runtime exceptions is called twice, once by the application
109 // throwing the exception and then by the rcp logging mechanism
110 // The check below is to make sure that the same exception is
111 // not shown twice in succession.
112 if(t
!= null && previousT
== t
) {
119 // NOTE : Currently we only allow RuntimeExceptions since
120 // allowing all kinds of exceptions would also include
121 // those in generated status objects coming from from logging triggers
122 // leading to a recursive infinite loop of :
123 // initial exception thrown -> status handling -> dialog opening + logging of status ->
124 // status handling -> dialog opening + logging of status ... and so on
126 t
instanceof RuntimeException
&&
127 ! "Widget is disposed".equals(t
.getMessage()) &&
128 ! handleKnownRuntimeException(t
,statusAdapter
.getStatus().getPlugin())) {
130 MessagingUtils
.errorDialog("Unexpected error",
132 MessagingUtils
.UNEXPECTED_ERROR_MESSAGE
,
133 statusAdapter
.getStatus().getPlugin(),
137 } else if (t
!= null && ("Widget is disposed".equals(t
.getMessage()))){
138 MessagingUtils
.warn(this.getClass(), t
.getMessage());
139 if (PreferencesUtil
.isDebugMode()){
140 MessagingUtils
.warningDialog("Widget is disposed", null, status
);
148 private boolean handleKnownRuntimeException(Throwable t
, String pluginId
) {
149 if(t
instanceof RemoteConnectFailureException
||
150 t
.getCause() instanceof RemoteConnectFailureException
) {
151 MessagingUtils
.errorDialog("Connection Failure",
153 MessagingUtils
.CONNECTION_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),
160 if(t
instanceof RemoteAccessException
||
161 t
.getCause() instanceof RemoteAccessException
) {
162 MessagingUtils
.errorDialog("Remote Access Error",
164 MessagingUtils
.REMOTE_ACCESS_FAILURE_MESSAGE
+ System
.getProperty("line.separator"),