01: /* uDig - User Friendly Desktop Internet GIS client
02: * http://udig.refractions.net
03: * (C) 2004, Refractions Research Inc.
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation;
08: * version 2.1 of the License.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: */
15: package net.refractions.udig.ui;
16:
17: import java.util.ArrayList;
18: import java.util.List;
19:
20: import net.refractions.udig.ui.internal.Messages;
21:
22: import org.eclipse.core.runtime.IStatus;
23: import org.eclipse.core.runtime.MultiStatus;
24: import org.eclipse.core.runtime.Status;
25: import org.eclipse.jface.dialogs.Dialog;
26: import org.eclipse.jface.dialogs.ErrorDialog;
27: import org.eclipse.jface.dialogs.MessageDialog;
28: import org.eclipse.swt.widgets.Display;
29: import org.eclipse.swt.widgets.Shell;
30:
31: /**
32: * Provides a consistent way to handle error notifications.
33: *
34: * @author chorner
35: * @since 1.1.0
36: */
37: public class ErrorManager {
38:
39: private ErrorManager() {
40: }
41:
42: private static final ErrorManager instance = new ErrorManager();
43:
44: /**
45: * Returns the singleton instance
46: *
47: * @return the singleton instance
48: */
49: public static ErrorManager get() {
50: return instance;
51: }
52:
53: public void displayError(final String title, final String message) {
54: PlatformGIS.syncInDisplayThread(new Runnable() {
55: public void run() {
56: Shell shell = Display.getDefault().getActiveShell();
57: MessageDialog.openError(shell, title, message);
58: }
59: });
60: }
61:
62: public void displayException(final Throwable exception,
63: final String message, final String pluginID) {
64: List<Throwable> exceptions = new ArrayList<Throwable>();
65: exceptions.add(exception);
66: displayExceptions(exceptions, message, pluginID);
67: }
68:
69: public void displayExceptions(final List<Throwable> exceptions,
70: String message, final String pluginID) {
71: final String m;
72: if (message == null)
73: m = ""; //$NON-NLS-1$
74: else
75: m = message;
76:
77: final MultiStatus multi = new MultiStatus(pluginID, IStatus.OK,
78: message, null);
79: for (Throwable exception : exceptions) {
80: Status status = new Status(IStatus.ERROR, pluginID,
81: IStatus.ERROR, exception.getLocalizedMessage(),
82: exception);
83: multi.add(status);
84: }
85:
86: PlatformGIS.syncInDisplayThread(new Runnable() {
87: public void run() {
88: Dialog dialog = new ErrorDialog(Display.getDefault()
89: .getActiveShell(),
90: Messages.ErrorManager_very_informative_error,
91: m, multi, IStatus.ERROR);
92: dialog.open();
93: }
94: });
95: }
96:
97: }
|