Project

General

Profile

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

    
3

    
4
import java.io.PrintWriter;
5
import java.io.StringWriter;
6
import java.rmi.activation.Activator;
7

    
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;
19

    
20
import eu.etaxonomy.taxeditor.model.MessagingUtils;
21

    
22

    
23

    
24
/**
25
 * <p>ApplicationWorkbenchAdvisor class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @version $Id: $
29
 */
30
public class ApplicationWorkbenchAdvisor extends WorkbenchAdvisor {
31

    
32
	private CdmStatusHandler cdmStatusHandler;
33
	/*
34
	 * (non-Javadoc)
35
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#createWorkbenchWindowAdvisor(org.eclipse.ui.application.IWorkbenchWindowConfigurer)
36
	 */
37
	/** {@inheritDoc} */
38
	public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
39
			IWorkbenchWindowConfigurer configurer) {
40
		return new ApplicationWorkbenchWindowAdvisor(configurer);
41
	}
42

    
43
	
44
	/*
45
	 * (non-Javadoc)
46
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#getInitialWindowPerspectiveId()
47
	 */
48
	/**
49
	 * <p>getInitialWindowPerspectiveId</p>
50
	 *
51
	 * @return a {@link java.lang.String} object.
52
	 */
53
	public String getInitialWindowPerspectiveId() {
54
		return "eu.etaxonomy.taxeditor.application.perspective.taxonomic";
55
	}
56
	
57
	/*
58
	 * (non-Javadoc)
59
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#initialize(org.eclipse.ui.application.IWorkbenchConfigurer)
60
	 */
61
	/** {@inheritDoc} */
62
	public void initialize(IWorkbenchConfigurer configurer) {
63
		super.initialize(configurer);
64
				
65
		// Remembers the user's view layout, window size, window location etc.
66
		//  for the next time application is started
67
		configurer.setSaveAndRestore(true);
68
	}	
69
	
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#preStartup()
72
	 */
73
	/** {@inheritDoc} */
74
	@Override
75
	public void preStartup() {
76
		// TODO Auto-generated method stub
77
		super.preStartup();
78
		// XXX check for updates before starting up.
79
    	// If an update is performed, restart.
80
//    	if (P2Util.checkForUpdates())
81
//    		PlatformUI.getWorkbench().restart();
82
	}
83
	
84
/**
85
 * see:	https://bugs.eclipse.org/bugs/show_bug.cgi?id=234252
86
 */
87
//	public void initialize(IWorkbenchConfigurer configurer) {
88
//
89
//		WorkbenchAdapterBuilder.registerAdapters();
90
//
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",
96
//				true);
97
//		declareWorkbenchImage(configurer, ideBundle,
98
//				IDE.SharedImages.IMG_OBJ_PROJECT_CLOSED, PATH_OBJECT
99
//						+ "cprj_obj.gif", true);
100
//
101
//	}
102
//
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);
108
//	}
109
//
110
//	public IAdaptable getDefaultPageInput() {
111
//		IWorkspace workspace = ResourcesPlugin.getWorkspace();
112
//		return workspace.getRoot();
113
//	}
114

    
115
//	@Override
116
//	public void eventLoopException(Throwable exception) {
117
//		super.eventLoopException(exception);
118
//		StoreUtil.messageDialog("Unexpected error", null, exception.getMessage(), exception);
119
//	}
120
	
121
	
122
	/* (non-Javadoc)
123
	 * @see org.eclipse.ui.application.WorkbenchAdvisor#getWorkbenchErrorHandler()
124
	 */
125
	@Override
126
	public synchronized AbstractStatusHandler getWorkbenchErrorHandler() {
127
	    if (cdmStatusHandler == null) {
128
	        cdmStatusHandler = new CdmStatusHandler();
129
	    }
130
	    return cdmStatusHandler;
131
	}
132
	
133

    
134
	/**
135
	 * Custom status handler for handling scenarios which are 
136
	 * not handled by the editor (e.g. runtime exceptions).
137
	 * 
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.
141
	 * 
142
	 * @author cmathew
143
	 *
144
	 */
145
	class CdmStatusHandler extends AbstractStatusHandler {
146
		
147
		/* (non-Javadoc)
148
		 * @see org.eclipse.ui.statushandlers.AbstractStatusHandler#handle(org.eclipse.ui.statushandlers.StatusAdapter, int)
149
		 */
150
		@Override
151
		public void handle(StatusAdapter statusAdapter, int style)
152
		{
153
		    if(statusAdapter.getStatus().matches(IStatus.ERROR)) {
154
		    	
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", 
165
		    				null, 
166
		    				MessagingUtils.UNEXPECTED_ERROR_MESSAGE + MessagingUtils.CONTACT_MESSAGE, 
167
		    				statusAdapter.getStatus().getPlugin(), 
168
		    				t);				    		
169
		    	} 		    	    
170
		    }
171
		}
172
	}
173
	
174

    
175
	
176
}
(4-4/12)