KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > dialogs > PreferenceErrorDialog


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

11 package org.eclipse.ui.internal.dialogs;
12
13
14 import org.eclipse.core.runtime.IStatus;
15 import org.eclipse.jface.dialogs.ErrorDialog;
16 import org.eclipse.jface.dialogs.IDialogConstants;
17 import org.eclipse.swt.graphics.Image;
18 import org.eclipse.swt.layout.GridLayout;
19 import org.eclipse.swt.widgets.Button;
20 import org.eclipse.swt.widgets.Composite;
21 import org.eclipse.swt.widgets.Shell;
22
23 /**
24  * A dialog to show an error while giving the user the option to continue.
25  */

26 public class PreferenceErrorDialog extends ErrorDialog {
27     /**
28      * Create a new instance of the dialog
29      */

30     public PreferenceErrorDialog(
31         Shell parentShell,
32         String JavaDoc dialogTitle,
33         String JavaDoc message,
34         IStatus status,
35         int displayMask) {
36             
37         super(parentShell, dialogTitle, message, status, displayMask);
38     }
39     /**
40      * Opens an error dialog to display the given error.
41      */

42     public static int openError(Shell parentShell, String JavaDoc title, String JavaDoc message, IStatus status) {
43         int displayMask = IStatus.OK | IStatus.INFO | IStatus.WARNING | IStatus.ERROR;
44         ErrorDialog dialog = new PreferenceErrorDialog(parentShell, title, message, status, displayMask);
45         return dialog.open();
46     }
47     /* (non-Javadoc)
48      * Method declared on Dialog.
49      */

50     protected void buttonPressed(int buttonId) {
51         if (IDialogConstants.YES_ID == buttonId)
52             okPressed();
53         else if (IDialogConstants.NO_ID == buttonId)
54             cancelPressed();
55         else
56             super.buttonPressed(buttonId);
57     }
58     /* (non-Javadoc)
59      * Method declared on Dialog.
60      */

61     protected void createButtonsForButtonBar(Composite parent) {
62         // create Yes, No, and Details buttons
63
createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
64         createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false);
65         super.createButtonsForButtonBar(parent);
66         // get rid of the unwanted ok button
67
Button okButton = getButton(IDialogConstants.OK_ID);
68         if (okButton != null && !okButton.isDisposed()) {
69             okButton.dispose();
70             ((GridLayout)parent.getLayout()).numColumns--;
71         }
72     }
73     /* (non-Javadoc)
74      * Method declared on ErrorDialog.
75      */

76     protected Image getImage() {
77         return getWarningImage();
78     }
79 }
80
81
Popular Tags