16 |
16 |
/**
|
17 |
17 |
* Utility class which handles all the messaging information generated by the
|
18 |
18 |
* Editor.
|
19 |
|
*
|
|
19 |
*
|
20 |
20 |
* This includes logging as well as dialogs.
|
21 |
|
*
|
|
21 |
*
|
22 |
22 |
* @author cmathew
|
23 |
23 |
*
|
24 |
24 |
*/
|
... | ... | |
36 |
36 |
public static Logger getLog4JLogger(Class clazz) {
|
37 |
37 |
return Logger.getLogger(clazz);
|
38 |
38 |
}
|
39 |
|
|
|
39 |
|
40 |
40 |
/**
|
41 |
41 |
* Logs details from a given Status object
|
42 |
42 |
*
|
... | ... | |
48 |
48 |
}
|
49 |
49 |
|
50 |
50 |
/**
|
51 |
|
* Logs a status object as information.
|
|
51 |
* Logs a status object as information.
|
52 |
52 |
*
|
53 |
53 |
* @param status
|
54 |
54 |
* a {@link org.eclipse.core.runtime.IStatus} object.
|
... | ... | |
58 |
58 |
}
|
59 |
59 |
|
60 |
60 |
/**
|
61 |
|
* Logs a string as information.
|
|
61 |
* Logs a string as information.
|
62 |
62 |
*
|
63 |
63 |
* @param message
|
64 |
64 |
* a {@link java.lang.String} object.
|
... | ... | |
69 |
69 |
}
|
70 |
70 |
|
71 |
71 |
/**
|
72 |
|
* Logs an exception from a given source as a warning.
|
73 |
|
*
|
|
72 |
* Logs an exception from a given source as a warning.
|
|
73 |
*
|
74 |
74 |
* @param source
|
75 |
75 |
* @param t
|
76 |
76 |
*/
|
... | ... | |
81 |
81 |
}
|
82 |
82 |
|
83 |
83 |
/**
|
84 |
|
* Logs a status object from a given source as a warning.
|
85 |
|
*
|
|
84 |
* Logs a status object from a given source as a warning.
|
|
85 |
*
|
86 |
86 |
* @param source
|
87 |
87 |
* @param status
|
88 |
88 |
*/
|
... | ... | |
92 |
92 |
}
|
93 |
93 |
|
94 |
94 |
/**
|
95 |
|
* Logs a string from a given source as a warning.
|
96 |
|
*
|
|
95 |
* Logs a string from a given source as a warning.
|
|
96 |
*
|
97 |
97 |
*
|
98 |
98 |
* @param source
|
99 |
99 |
* a {@link java.lang.Class} object.
|
... | ... | |
107 |
107 |
}
|
108 |
108 |
|
109 |
109 |
/**
|
110 |
|
* Logs a status object from a given source as an error.
|
111 |
|
*
|
|
110 |
* Logs a status object from a given source as an error.
|
|
111 |
*
|
112 |
112 |
*
|
113 |
113 |
* @param source
|
114 |
114 |
* a {@link java.lang.Class} object.
|
... | ... | |
122 |
122 |
}
|
123 |
123 |
|
124 |
124 |
/**
|
125 |
|
* Logs a string and exception from a given source as an error.
|
126 |
|
*
|
|
125 |
* Logs a string and exception from a given source as an error.
|
|
126 |
*
|
127 |
127 |
*
|
128 |
128 |
* @param source
|
129 |
129 |
* a {@link java.lang.Class} object.
|
... | ... | |
140 |
140 |
|
141 |
141 |
|
142 |
142 |
/**
|
143 |
|
* Logs an exception from a given source as an error.
|
144 |
|
*
|
|
143 |
* Logs an exception from a given source as an error.
|
|
144 |
*
|
145 |
145 |
*
|
146 |
146 |
* @param source
|
147 |
147 |
* a {@link java.lang.Class} object.
|
... | ... | |
162 |
162 |
* @param status
|
163 |
163 |
* a {@link org.eclipse.core.runtime.IStatus} object.
|
164 |
164 |
*/
|
165 |
|
public static void errorDialog(final String title,
|
166 |
|
final Object source,
|
167 |
|
final String message,
|
|
165 |
public static void errorDialog(final String title,
|
|
166 |
final Object source,
|
|
167 |
final String message,
|
168 |
168 |
final IStatus status) {
|
169 |
169 |
|
170 |
170 |
Display.getDefault().asyncExec(new Runnable() {
|
171 |
171 |
|
172 |
172 |
@Override
|
173 |
|
public void run() {
|
|
173 |
public void run() {
|
174 |
174 |
CdmErrorDialog ced = new CdmErrorDialog(AbstractUtility.getShell(), title, message, status);
|
175 |
175 |
ced.open();
|
176 |
176 |
Class<? extends Object> clazz = source != null ? source
|
... | ... | |
179 |
179 |
}
|
180 |
180 |
});
|
181 |
181 |
}
|
182 |
|
|
|
182 |
|
183 |
183 |
/**
|
184 |
184 |
* Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
|
185 |
|
*
|
|
185 |
*
|
186 |
186 |
* @param title
|
187 |
187 |
* @param source
|
188 |
188 |
* @param message
|
189 |
189 |
* @param pluginId
|
190 |
190 |
* @param t
|
191 |
191 |
*/
|
192 |
|
public static void errorDialog(final String title,
|
|
192 |
public static void errorDialog(final String title,
|
193 |
193 |
final Object source,
|
194 |
194 |
final String message,
|
195 |
|
final String pluginId,
|
|
195 |
final String pluginId,
|
196 |
196 |
final Throwable t,
|
197 |
197 |
boolean addContactMesg) {
|
198 |
198 |
// Usually the status contains only the first line of the stack trace.
|
199 |
|
// For the unexpected messages we need the entire stack trace so we
|
200 |
|
// create a new status with the entire stacktrace
|
|
199 |
// For the unexpected messages we need the entire stack trace so we
|
|
200 |
// create a new status with the entire stacktrace
|
201 |
201 |
StringWriter sw = new StringWriter();
|
202 |
202 |
t.printStackTrace(new PrintWriter(sw));
|
203 |
203 |
String finalMessage = t.getMessage();
|
204 |
204 |
if(addContactMesg) {
|
205 |
205 |
finalMessage += MessagingUtils.CONTACT_MESSAGE;
|
206 |
206 |
}
|
207 |
|
IStatus status = new Status(IStatus.ERROR,
|
208 |
|
pluginId,
|
209 |
|
finalMessage,
|
210 |
|
new Exception(sw.toString()));
|
|
207 |
IStatus status = new Status(IStatus.ERROR,
|
|
208 |
pluginId,
|
|
209 |
finalMessage,
|
|
210 |
new Exception(sw.toString()));
|
211 |
211 |
errorDialog(title, source, message, status);
|
212 |
212 |
}
|
213 |
|
|
214 |
213 |
|
215 |
|
|
|
214 |
|
|
215 |
|
216 |
216 |
/**
|
217 |
217 |
* Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
|
218 |
218 |
*
|
... | ... | |
223 |
223 |
* @param status
|
224 |
224 |
* a {@link org.eclipse.core.runtime.IStatus} object.
|
225 |
225 |
*/
|
226 |
|
public static void errorDialog(final String title,
|
227 |
|
final Object source,
|
228 |
|
final String message,
|
|
226 |
public static void errorDialog(final String title,
|
|
227 |
final Object source,
|
|
228 |
final String message,
|
229 |
229 |
final IStatus status,
|
230 |
|
final boolean showStackTrace) {
|
231 |
|
if(showStackTrace && status.getException() != null) {
|
|
230 |
final boolean showStackTrace) {
|
|
231 |
if(showStackTrace && status.getException() != null) {
|
232 |
232 |
errorDialog(title, source, status.getPlugin(), message, status.getException(),true);
|
233 |
233 |
} else {
|
234 |
234 |
errorDialog(title, source, message, status);
|
235 |
|
}
|
|
235 |
}
|
236 |
236 |
}
|
237 |
|
|
|
237 |
|
238 |
238 |
|
239 |
239 |
/**
|
240 |
240 |
* Displays a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog}.
|
... | ... | |
250 |
250 |
final IStatus status) {
|
251 |
251 |
errorDialog(title, source, null, status);
|
252 |
252 |
}
|
253 |
|
|
|
253 |
|
254 |
254 |
/**
|
255 |
255 |
* Displays a dialog for an exception occurring in an operation.
|
256 |
|
*
|
257 |
|
* This will be either a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog} in case of a
|
|
256 |
*
|
|
257 |
* This will be either a {@link eu.etaxonomy.taxeditor.model.CdmErrorDialog} in case of a
|
258 |
258 |
* security runtime exception or a warning {@link org.eclipse.jface.dialogs.MessageDialog} in
|
259 |
259 |
* case of any other exception.
|
260 |
260 |
*
|
... | ... | |
265 |
265 |
* @param status
|
266 |
266 |
* a {@link org.eclipse.core.runtime.IStatus} object.
|
267 |
267 |
*/
|
268 |
|
public static void operationDialog(final Object source,
|
|
268 |
public static void operationDialog(final Object source,
|
269 |
269 |
final Exception ex,
|
270 |
|
final String operationlabel,
|
|
270 |
final String pluginId,
|
|
271 |
final String operationlabel,
|
271 |
272 |
final String hint) {
|
272 |
273 |
|
273 |
274 |
Display.getDefault().asyncExec(new Runnable() {
|
274 |
275 |
|
275 |
276 |
@Override
|
276 |
|
public void run() {
|
|
277 |
public void run() {
|
277 |
278 |
MultiStatus info = null;
|
278 |
279 |
String title = null;
|
279 |
|
|
|
280 |
|
280 |
281 |
// FIXME cannot access TaxonomicEditorPlugin.PLUGIN_ID from here
|
281 |
282 |
// String PID = TaxonomicEditorPlugin.PLUGIN_ID;
|
282 |
283 |
String PID = "eu.etaxonomy.taxeditor.application";
|
... | ... | |
289 |
290 |
title = "Your changes could not be saved!";
|
290 |
291 |
warningDialog(title, source, String.format("You are missing sufficient permissions for the operation \"%s\". %s", operationlabel, hint));
|
291 |
292 |
} else {
|
292 |
|
title = "Error executing operation";
|
293 |
|
errorDialog(title, source, String.format("An error occured while executing %s. %s", operationlabel, hint), PID, ex, true);
|
294 |
|
|
|
293 |
title = "Error executing operation";
|
|
294 |
errorDialog(title, source, String.format("An error occured while executing %s. %s", operationlabel, hint), pluginId, ex, true);
|
|
295 |
|
295 |
296 |
}
|
296 |
|
|
297 |
|
|
|
297 |
|
|
298 |
|
298 |
299 |
}
|
299 |
300 |
});
|
300 |
301 |
}
|
301 |
|
|
302 |
|
|
|
302 |
|
|
303 |
|
303 |
304 |
|
304 |
305 |
|
305 |
306 |
/**
|
... | ... | |
317 |
318 |
|
318 |
319 |
/**
|
319 |
320 |
* Displays a message {@link org.eclipse.jface.dialogs.MessageDialog}.
|
320 |
|
*
|
|
321 |
*
|
321 |
322 |
* @param title
|
322 |
323 |
* @param source
|
323 |
324 |
* @param message
|
324 |
325 |
*/
|
325 |
326 |
public static void messageDialog(final String title, final Object source, final String message) {
|
326 |
|
MessagingUtils.messageDialog(title, source, message, null);
|
|
327 |
MessagingUtils.messageDialog(title, source, message, null, true);
|
327 |
328 |
}
|
328 |
329 |
|
|
330 |
|
|
331 |
|
329 |
332 |
/**
|
330 |
333 |
* Displays an error {@link org.eclipse.jface.dialogs.MessageDialog}.
|
331 |
334 |
*
|
... | ... | |
340 |
343 |
* @param t
|
341 |
344 |
* a Throwable if one exists or null
|
342 |
345 |
*/
|
343 |
|
public static void messageDialog(final String title, final Object source,
|
344 |
|
final String message, final Throwable t) {
|
345 |
|
Display.getDefault().asyncExec(new Runnable() {
|
346 |
|
|
347 |
|
@Override
|
348 |
|
public void run() {
|
349 |
|
MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
|
350 |
|
Class<? extends Object> clazz = source != null ? source
|
351 |
|
.getClass() : this.getClass();
|
352 |
|
error(clazz, message, t);
|
353 |
|
}
|
354 |
|
|
355 |
|
private String getCauseRecursively(Throwable t) {
|
356 |
|
if(t == null){
|
357 |
|
return "";
|
358 |
|
}
|
359 |
|
|
360 |
|
if(t.getCause() != null){
|
361 |
|
return getCauseRecursively(t.getCause());
|
362 |
|
}else{
|
363 |
|
return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
|
364 |
|
}
|
365 |
|
|
366 |
|
}
|
367 |
|
});
|
|
346 |
public static void messageDialog(final String title,
|
|
347 |
final Object source,
|
|
348 |
final String message,
|
|
349 |
final Throwable t) {
|
|
350 |
MessagingUtils.messageDialog(title, source, message, t, true);
|
368 |
351 |
}
|
369 |
352 |
|
|
353 |
/**
|
|
354 |
* Displays an error {@link org.eclipse.jface.dialogs.MessageDialog}.
|
|
355 |
*
|
|
356 |
* @param title
|
|
357 |
* The dialogs title
|
|
358 |
* @param source
|
|
359 |
* The object where the warning was generated (used by log4j)
|
|
360 |
* @param message
|
|
361 |
* An informative String to be presented to the user
|
|
362 |
* @param title
|
|
363 |
* The dialogs title
|
|
364 |
* @param t
|
|
365 |
* a Throwable if one exists or null
|
|
366 |
*/
|
|
367 |
public static void messageDialog(final String title,
|
|
368 |
final Object source,
|
|
369 |
final String message,
|
|
370 |
final Throwable t,
|
|
371 |
boolean async) {
|
|
372 |
if(async) {
|
|
373 |
Display.getDefault().asyncExec(new Runnable() {
|
|
374 |
|
|
375 |
@Override
|
|
376 |
public void run() {
|
|
377 |
MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
|
|
378 |
Class<? extends Object> clazz = source != null ? source
|
|
379 |
.getClass() : this.getClass();
|
|
380 |
error(clazz, message, t);
|
|
381 |
}
|
|
382 |
|
|
383 |
|
|
384 |
});
|
|
385 |
} else {
|
|
386 |
MessageDialog.openError(AbstractUtility.getShell(), title, message + getCauseRecursively(t));
|
|
387 |
Class<? extends Object> clazz = source != null ? source.getClass() : TaxeditorStorePlugin.class;
|
|
388 |
error(clazz, message, t);
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
public static String getCauseRecursively(Throwable t) {
|
|
393 |
if(t == null){
|
|
394 |
return "";
|
|
395 |
}
|
|
396 |
|
|
397 |
if(t.getCause() != null){
|
|
398 |
return getCauseRecursively(t.getCause());
|
|
399 |
}else{
|
|
400 |
return String.format("\n\nException: %s\nMessage: %s", t.getClass().getSimpleName(), t.getMessage());
|
|
401 |
}
|
|
402 |
|
|
403 |
}
|
370 |
404 |
/**
|
371 |
405 |
* Displays a warning {@link org.eclipse.jface.dialogs.MessageDialog}.
|
372 |
|
*
|
|
406 |
*
|
373 |
407 |
* @param title
|
374 |
408 |
* @param termBase
|
375 |
409 |
* @param status
|
... | ... | |
391 |
425 |
*/
|
392 |
426 |
public static void warningDialog(final String title, final Object source, final String message) {
|
393 |
427 |
Display.getDefault().asyncExec(new Runnable() {
|
394 |
|
|
|
428 |
|
395 |
429 |
@Override
|
396 |
430 |
public void run() {
|
397 |
431 |
MessageDialog.openWarning(AbstractUtility.getShell(), title, message);
|
... | ... | |
404 |
438 |
|
405 |
439 |
/**
|
406 |
440 |
* Displays an information {@link org.eclipse.jface.dialogs.MessageDialog}.
|
407 |
|
*
|
|
441 |
*
|
408 |
442 |
* @param title
|
409 |
443 |
* @param status
|
410 |
444 |
*/
|
... | ... | |
423 |
457 |
public static void informationDialog(final String title,
|
424 |
458 |
final String message) {
|
425 |
459 |
Display.getDefault().asyncExec(new Runnable() {
|
426 |
|
|
|
460 |
|
427 |
461 |
@Override
|
428 |
462 |
public void run() {
|
429 |
463 |
MessageDialog.openInformation(AbstractUtility.getShell(), title, message);
|
added new error dialog for operations