KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > ui > internal > util > ErrorUtil


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.ui.internal.util;
12
13 import org.eclipse.help.internal.base.util.IErrorUtil;
14 import org.eclipse.help.ui.internal.Messages;
15 import org.eclipse.jface.dialogs.MessageDialog;
16 import org.eclipse.swt.widgets.Display;
17 import org.eclipse.swt.widgets.Shell;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.PlatformUI;
20
21 /**
22  * Utility class for common error displaying tasks.
23  */

24 public class ErrorUtil implements IErrorUtil {
25
26     public void displayError(String JavaDoc msg) {
27         displayErrorDialog(msg);
28     }
29
30     public void displayError(final String JavaDoc msg, Thread JavaDoc uiThread) {
31         try {
32             Display.findDisplay(uiThread).asyncExec(new Runnable JavaDoc() {
33
34                 public void run() {
35                     displayErrorDialog(msg);
36                 }
37             });
38         } catch (Exception JavaDoc e2) {
39         }
40     }
41
42     /**
43      * Immediately displays error dialog with a given string
44      *
45      * @param msg
46      * error message to display and log.
47      */

48     public static void displayErrorDialog(String JavaDoc msg) {
49         String JavaDoc title = Messages.Help_Error;
50         IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow();
51         Shell shell;
52         if (workbenchWindow != null) {
53             shell = workbenchWindow.getShell();
54         } else {
55             shell = new Shell();
56         }
57         MessageDialog.openError(shell, title, msg);
58     }
59
60     /**
61      * Immediately displays an Information dialog with a given string
62      *
63      * @param msg
64      * error message to display.
65      */

66     public static void displayInfoDialog(String JavaDoc msg) {
67         String JavaDoc title = Messages.Help_Info;
68         IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow();
69         Shell shell;
70         if (workbenchWindow != null) {
71             shell = workbenchWindow.getShell();
72         } else {
73             shell = new Shell();
74         }
75         MessageDialog.openInformation(shell, title, msg);
76     }
77
78     /**
79      * Immediately displays a Question dialog with a given string (question).
80      *
81      * @return which button(Yes/No) was pressed by user
82      */

83     public static boolean displayQuestionDialog(String JavaDoc msg) {
84         String JavaDoc title = Messages.Help_Question;
85         IWorkbenchWindow workbenchWindow = getActiveWorkbenchWindow();
86         Shell shell;
87         if (workbenchWindow != null) {
88             shell = workbenchWindow.getShell();
89         } else {
90             shell = new Shell();
91         }
92         return MessageDialog.openQuestion(shell, title, msg);
93     }
94
95     protected static IWorkbenchWindow getActiveWorkbenchWindow() {
96         return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
97     }
98 }
99
Popular Tags