KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > preferences > PreferencePageSupport


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.jdt.internal.ui.preferences;
12
13 import org.eclipse.swt.custom.BusyIndicator;
14 import org.eclipse.swt.widgets.Shell;
15
16 import org.eclipse.jface.preference.IPreferenceNode;
17 import org.eclipse.jface.preference.IPreferencePage;
18 import org.eclipse.jface.preference.PreferenceDialog;
19 import org.eclipse.jface.preference.PreferenceManager;
20 import org.eclipse.jface.preference.PreferenceNode;
21 import org.eclipse.jface.window.Window;
22
23 /**
24  *
25  */

26 public class PreferencePageSupport {
27     /**
28      *
29      */

30     private PreferencePageSupport() {
31         super();
32     }
33     
34     /**
35      * Open the given preference page in a preference dialog.
36      * @param shell The shell to open on
37      * @param id The id of the preference page as in the plugin.xml
38      * @param page An instance of the page. Note that such a page should also set its own
39      * title to correctly show up.
40      * @return Returns <code>true</code> if the user ended the page by pressing OK.
41      */

42     public static boolean showPreferencePage(Shell shell, String JavaDoc id, IPreferencePage page) {
43         final IPreferenceNode targetNode = new PreferenceNode(id, page);
44         
45         PreferenceManager manager = new PreferenceManager();
46         manager.addToRoot(targetNode);
47         final PreferenceDialog dialog = new PreferenceDialog(shell, manager);
48         final boolean [] result = new boolean[] { false };
49         BusyIndicator.showWhile(shell.getDisplay(), new Runnable JavaDoc() {
50             public void run() {
51                 dialog.create();
52                 dialog.setMessage(targetNode.getLabelText());
53                 result[0]= (dialog.open() == Window.OK);
54             }
55         });
56         return result[0];
57     }
58 }
59
Popular Tags