KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > update > internal > ui > RestartDialog


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.update.internal.ui;
12
13 import org.eclipse.core.runtime.IProduct;
14 import org.eclipse.core.runtime.Platform;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.dialogs.MessageDialog;
17 import org.eclipse.osgi.util.NLS;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.update.operations.*;
20
21 /**
22  * A dialog which prompts the user to restart after an update operation
23  * and provides Yes, No, Continue buttons.
24  */

25 public class RestartDialog extends MessageDialog {
26     private static final int CONTINUE = 2;
27     private final static String JavaDoc[] yesNo = new String JavaDoc[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL};
28     private final static String JavaDoc[] yesNoApply = new String JavaDoc[] {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, UpdateUIMessages.ApplyChanges};
29     
30     private int buttonId = 0;
31     
32     /**
33      * Creates a new dialog
34      * @see MessageDialog#MessageDialog(org.eclipse.swt.widgets.Shell, java.lang.String, org.eclipse.swt.graphics.Image, java.lang.String, int, java.lang.String[], int)
35      */

36     public RestartDialog(Shell parent, String JavaDoc title, String JavaDoc message, boolean restartNeeded) {
37         super(parent,
38                 title,
39                 null, // accept the default window icon
40
message,
41                 QUESTION,
42                 restartNeeded ? yesNo : yesNoApply,
43                 0); // yes is the default
44
}
45
46     /**
47      * Convenience method to open the Yes/No/Continue question dialog.
48      *
49      * @param parent the parent shell of the dialog, or <code>null</code> if none
50      * @param restartIsReallyNeeded when false, the changes are applied to the current config
51      * @return <code>true</code> if the user presses YES
52      * <code>false</code> otherwise
53      */

54     public static boolean openQuestion(Shell parent, boolean restartIsReallyNeeded) {
55         String JavaDoc title = UpdateUIMessages.RestartTitle;
56         IProduct product = Platform.getProduct();
57         String JavaDoc productName = product != null && product.getName() != null ? product.getName() : UpdateUIMessages.ApplicationInRestartDialog;
58         String JavaDoc message = NLS.bind(restartIsReallyNeeded ? UpdateUIMessages.RestartMessage: UpdateUIMessages.OptionalRestartMessage, productName);
59         RestartDialog dialog = new RestartDialog(parent, title, message, restartIsReallyNeeded);
60         int button= dialog.open();
61         if (button == 2)
62             OperationsManager.applyChangesNow();
63         return button == 0; // Yes
64
}
65     
66     /**
67      * When a button is pressed, store the preference.
68      *
69      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
70      */

71     protected void buttonPressed(int id) {
72         if (id == 2) {
73             buttonId= CONTINUE;
74         }
75         
76         super.buttonPressed(id);
77     }
78     
79     /**
80      * Returns the user's selection,
81      * <code>null</code> if the user hasn't chosen yet.
82      *
83      * @return the user's selection or <code>null</code>
84      */

85     public int getResult() {
86         return buttonId;
87     }
88 }
89
Popular Tags