Project

General

Profile

Download (3.67 KB) Statistics
| Branch: | Tag: | Revision:
1
package eu.etaxonomy.taxeditor;
2

    
3

    
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

    
12
import eu.etaxonomy.taxeditor.model.MessagingUtils;
13

    
14

    
15

    
16
/**
17
 * <p>ApplicationWorkbenchAdvisor class.</p>
18
 *
19
 * @author n.hoffmann
20
 * @version $Id: $
21
 */
22
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
23

    
24
	private CdmStatusHandler cdmStatusHandler;
25
	/*
26
	 * (non-Javadoc)
27
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
28
	 */
29
	/** {@inheritDoc} */
30
	@Override
31
    public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
32
			IWorkbenchWindowConfigurer configurer) {
33
		return new ApplicationWorkbenchWindowAdvisor(configurer);
34
	}
35

    
36

    
37
	/*
38
	 * (non-Javadoc)
39
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
40
	 */
41
	/**
42
	 * <p>getInitialWindowPerspectiveId</p>
43
	 *
44
	 * @return a {@link java.lang.String} object.
45
	 */
46
	@Override
47
    public String getInitialWindowPerspectiveId() {
48
		return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
49
	}
50

    
51
	/*
52
	 * (non-Javadoc)
53
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
54
	 */
55
	/** {@inheritDoc} */
56
	@Override
57
    public void initialize(IWorkbenchConfigurer configurer) {
58
		super.initialize(configurer);
59

    
60
		// Remembers the user's view layout, window size, window location etc.
61
		//  for the next time application is started
62
		configurer.setSaveAndRestore(true);
63
	}
64

    
65

    
66
	/* (non-Javadoc)
67
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
68
	 */
69
	@Override
70
	public synchronized AbstractStatusHandler getWorkbenchErrorHandler() {
71
	    if (cdmStatusHandler == null) {
72
	        cdmStatusHandler = new CdmStatusHandler();
73
	    }
74
	    return cdmStatusHandler;
75
	}
76

    
77

    
78
	/**
79
	 * Custom status handler for handling scenarios which are
80
	 * not handled by the editor (e.g. runtime exceptions).
81
	 *
82
	 * The default {@link org.eclipse.ui.statushandlers.WorkbenchErrorHandler}
83
	 * is not used or extended because we need a handler for specific scenarios
84
	 * which displays a custom built error dialog.
85
	 *
86
	 * @author cmathew
87
	 *
88
	 */
89
	class CdmStatusHandler extends AbstractStatusHandler {
90

    
91
		/* (non-Javadoc)
92
		 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
93
		 */
94
		@Override
95
		public void handle(StatusAdapter statusAdapter, int style)
96
		{
97
		    if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
98

    
99
		    	IStatus status = statusAdapter.getStatus();
100
		    	Throwable t = statusAdapter.getStatus().getException();
101
		    	// NOTE : Currently we only allow RuntimeExceptions since
102
		    	//        allowing all kinds of exceptions would also include
103
		    	//        those in generated status objects coming from from logging triggers
104
		    	//        leading to a recursive infinite loop of :
105
		    	//        initial exception thrown -> status handling -> dialog opening + logging of status ->
106
		    	//        status handling -> dialog opening + logging of status ... and so on
107
		    	if(t != null && t instanceof RuntimeException && !t.getMessage().equals("Widget is disposed")){
108
		    		MessagingUtils.errorDialog("Unexpected error",
109
		    				null,
110
		    				MessagingUtils.UNEXPECTED_ERROR_MESSAGE,
111
		    				statusAdapter.getStatus().getPlugin(),
112
		    				t,
113
		    				true);
114
		     	}
115
		    }
116
		}
117
	}
118

    
119

    
120

    
121
}
(4-4/11)