KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > part > services > DefaultMessageDialogs


1 /*******************************************************************************
2  * Copyright (c) 2004, 2005 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.ui.internal.part.services;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.core.runtime.Status;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.ui.internal.WorkbenchPlugin;
19 import org.eclipse.ui.internal.part.components.services.IUserMessages;
20
21 /**
22  * Default implementation of the IMessageDialogs interface. Takes the part's
23  * control as context and allows the part to open dialogs in a child shell.
24  *
25  * @since 3.1
26  */

27 public class DefaultMessageDialogs implements IUserMessages {
28
29     private Composite control;
30     
31     /**
32      * Component constructor. Do not invoke directly.
33      */

34     public DefaultMessageDialogs(Composite control) {
35         this.control = control;
36     }
37     
38     /* (non-Javadoc)
39      * @see org.eclipse.ui.workbench.services.IMessageDialogs#open(org.eclipse.core.runtime.IStatus)
40      */

41     public void show(IStatus message) {
42         if (message.getSeverity() == IStatus.ERROR) {
43             ErrorDialog.openError(control.getShell(), null, null, message);
44         } else {
45             show(message.getSeverity(), message.getMessage());
46         }
47     }
48
49     /* (non-Javadoc)
50      * @see org.eclipse.ui.workbench.services.IMessageDialogs#openError(java.lang.String, java.lang.Throwable)
51      */

52     public void showError(String JavaDoc message, Throwable JavaDoc cause) {
53         show(new Status(IStatus.ERROR,
54                 WorkbenchPlugin.getDefault().getBundle().getSymbolicName(),
55                 IStatus.OK,
56                 message,
57                 cause));
58     }
59     
60     /* (non-Javadoc)
61      * @see org.eclipse.ui.internal.part.components.services.IMessageDialogs#open(int, java.lang.String)
62      */

63     public void show(int severity, String JavaDoc message) {
64         if (severity == IStatus.ERROR) {
65             MessageDialog.openError(control.getShell(), null, message);
66         } else if (severity == IStatus.WARNING) {
67             MessageDialog.openWarning(control.getShell(), null, message);
68         } else {
69             MessageDialog.openInformation(control.getShell(), null, message);
70         }
71     }
72 }
73
Popular Tags