|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 package com.nokia.s60tools.ui.preferences; |
|
18 |
|
19 import java.util.Iterator; |
|
20 import java.util.List; |
|
21 |
|
22 import org.eclipse.jface.preference.IPreferenceNode; |
|
23 import org.eclipse.jface.preference.PreferenceDialog; |
|
24 import org.eclipse.jface.preference.PreferenceManager; |
|
25 import org.eclipse.jface.viewers.StructuredSelection; |
|
26 import org.eclipse.swt.widgets.Shell; |
|
27 import org.eclipse.ui.dialogs.PreferencesUtil; |
|
28 |
|
29 public class PreferenceUtils { |
|
30 |
|
31 /** |
|
32 * Open a preference page by ID introduced in <code>plugin.xml</code> |
|
33 * |
|
34 * @param preferencePageID ID for preference page |
|
35 * @param shell {@link Shell} |
|
36 */ |
|
37 public static void openPreferencePage(String preferencePageID, Shell shell) { |
|
38 |
|
39 PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( |
|
40 shell, preferencePageID, null, null); |
|
41 |
|
42 dialog.open(); |
|
43 } |
|
44 |
|
45 /** |
|
46 * Open a preference page tab by ID introduced in <code>plugin.xml</code> |
|
47 * |
|
48 * If the preference page contains tabs, and one tab is wanted to open, use this. |
|
49 * |
|
50 * @param preferencePageID ID for preference page |
|
51 * @param preferencePageTabID ID for preference page tab under preference page with ID <preferencePageID> |
|
52 * @param shell {@link Shell} |
|
53 */ |
|
54 // Warning comes from org.eclipse.jface.preference.PreferenceManager.getElements(int) because it uses raw List type as return value |
|
55 @SuppressWarnings("unchecked") |
|
56 public static void openPreferencePage(String preferencePageID, |
|
57 String preferencePageTabID, Shell shell) { |
|
58 |
|
59 PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn( |
|
60 shell, preferencePageID, null, null); |
|
61 |
|
62 List<IPreferenceNode> elemns = dialog.getPreferenceManager() |
|
63 .getElements(PreferenceManager.PRE_ORDER); |
|
64 IPreferenceNode preferenceNode = null; |
|
65 //check all preference pages, if required is found |
|
66 for (Iterator<IPreferenceNode> iterator = elemns.iterator(); iterator |
|
67 .hasNext();) { |
|
68 preferenceNode = iterator.next(); |
|
69 if (preferenceNode.getId().equals(preferencePageTabID)) { |
|
70 break; |
|
71 } |
|
72 } |
|
73 |
|
74 //If required preference page tab was found, set that as selection |
|
75 if (preferenceNode != null) { |
|
76 dialog.getTreeViewer().setSelection( |
|
77 new StructuredSelection(preferenceNode)); |
|
78 } |
|
79 |
|
80 dialog.open(); |
|
81 |
|
82 } |
|
83 |
|
84 } |