KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > dialogs > PreferencesUtil


1 /*******************************************************************************
2  * Copyright (c) 2005, 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.ui.dialogs;
12
13 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.jface.preference.IPreferencePage;
15 import org.eclipse.jface.preference.PreferenceDialog;
16 import org.eclipse.jface.preference.PreferenceManager;
17 import org.eclipse.jface.preference.PreferencePage;
18 import org.eclipse.swt.widgets.Shell;
19 import org.eclipse.ui.internal.dialogs.FilteredPreferenceDialog;
20 import org.eclipse.ui.internal.dialogs.PropertyDialog;
21 import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog;
22
23 /**
24  * The PreferencesUtil class is the class that opens a properties or preference
25  * dialog on a set of ids.
26  * @since 3.1
27  */

28 public final class PreferencesUtil {
29
30     /**
31      * Apply the data to the first page if there is any.
32      * @param data The data to be applied
33      * @param displayedIds The ids to filter to.
34      * @param dialog The dialog to apply to.
35      */

36     private static void applyOptions(Object JavaDoc data, String JavaDoc[] displayedIds,
37             FilteredPreferenceDialog dialog) {
38         if (data != null) {
39             dialog.setPageData(data);
40             IPreferencePage page = dialog.getCurrentPage();
41             if (page instanceof PreferencePage) {
42                 ((PreferencePage) page).applyData(data);
43             }
44         }
45
46         if (displayedIds != null) {
47             dialog.showOnly(displayedIds);
48         }
49     }
50
51     /**
52      * Creates a workbench preference dialog and selects particular preference page.
53      * If there is already a preference dialog open this dialog is used and its
54      * selection is set to the page with id preferencePageId.
55      * Show the other pages as filtered results using whatever filtering
56      * criteria the search uses. It is the responsibility of the caller to then
57      * call <code>open()</code>. The call to <code>open()</code> will not
58      * return until the dialog closes, so this is the last chance to manipulate
59      * the dialog.
60      *
61      * @param shell
62      * The Shell to parent the dialog off of if it is not
63      * already created. May be <code>null</code>
64      * in which case the active workbench window will be used
65      * if available.
66      * @param preferencePageId
67      * The identifier of the preference page to open; may be
68      * <code>null</code>. If it is <code>null</code>, then the
69      * preference page is not selected or modified in any way.
70      * @param displayedIds
71      * The ids of the other pages to be displayed using the same
72      * filtering criterea as search. If this is <code>null</code>,
73      * then the all preference pages are shown.
74      * @param data
75      * Data that will be passed to all of the preference pages to be
76      * applied as specified within the page as they are created. If
77      * the data is <code>null</code> nothing will be called.
78      *
79      * @return a preference dialog.
80      * @since 3.1
81      * @see PreferenceDialog#PreferenceDialog(Shell, PreferenceManager)
82      */

83     public static final PreferenceDialog createPreferenceDialogOn(Shell shell,
84             String JavaDoc preferencePageId, String JavaDoc[] displayedIds, Object JavaDoc data) {
85         FilteredPreferenceDialog dialog = WorkbenchPreferenceDialog.createDialogOn(shell,
86                 preferencePageId);
87
88         applyOptions(data, displayedIds, dialog);
89
90         return dialog;
91     }
92
93     /**
94      * Creates a workbench preference dialog to a particular preference page.
95      * Show the other pages as filtered results using whatever filtering
96      * criteria the search uses. It is the responsibility of the caller to then
97      * call <code>open()</code>. The call to <code>open()</code> will not
98      * return until the dialog closes, so this is the last chance to manipulate
99      * the dialog.
100      *
101      * @param shell
102      * The shell to use to parent the dialog if required.
103      * @param propertyPageId
104      * The identifier of the preference page to open; may be
105      * <code>null</code>. If it is <code>null</code>, then the
106      * dialog is opened with no selected page.
107      * @param element
108      * IAdaptable An adaptable element to open the dialog
109      * on.
110      * @param displayedIds
111      * The ids of the other pages to be displayed using the same
112      * filtering criterea as search. If this is <code>null</code>,
113      * then the all preference pages are shown.
114      * @param data
115      * Data that will be passed to all of the preference pages to be
116      * applied as specified within the page as they are created. If
117      * the data is <code>null</code> nothing will be called.
118      *
119      * @return A preference dialog showing properties for the selection or
120      * <code>null</code> if it could not be created.
121      * @since 3.1
122      */

123     public static final PreferenceDialog createPropertyDialogOn(Shell shell,
124             final IAdaptable element, String JavaDoc propertyPageId, String JavaDoc[] displayedIds, Object JavaDoc data) {
125
126         FilteredPreferenceDialog dialog = PropertyDialog.createDialogOn(shell, propertyPageId,
127                 element);
128
129         if (dialog == null) {
130             return null;
131         }
132
133         applyOptions(data, displayedIds, dialog);
134
135         return dialog;
136
137     }
138
139 }
140
Popular Tags