KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > registry > PreferencePageParameterValues


1 /*******************************************************************************
2  * Copyright (c) 2006, 2007 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
12 package org.eclipse.ui.internal.registry;
13
14 import java.util.Map JavaDoc;
15 import java.util.TreeMap JavaDoc;
16
17 import org.eclipse.core.commands.IParameterValues;
18 import org.eclipse.core.runtime.IRegistryChangeEvent;
19 import org.eclipse.core.runtime.IRegistryChangeListener;
20 import org.eclipse.core.runtime.Platform;
21 import org.eclipse.jface.preference.IPreferenceNode;
22 import org.eclipse.jface.preference.PreferenceManager;
23 import org.eclipse.ui.PlatformUI;
24 import org.eclipse.ui.internal.WorkbenchMessages;
25
26 /**
27  * <p>
28  * Provides the parameter values for the show preferences command.
29  * </p>
30  * <p>
31  * To disambiguate preference pages with the same local label, names are
32  * constructed incorporating the full path of preference page labels. For
33  * instance names like <code>General > Appearance</code> and
34  * <code>Java > Appearance</code> avoid the problem of trying to put two
35  * <code>Appearance</code> keys into the parameter values map.
36  * </p>
37  * <p>
38  * This is only intended for use within the
39  * <code>org.eclipse.ui.workbench</code> plug-in.
40  * </p>
41  *
42  * @since 3.2
43  */

44 public final class PreferencePageParameterValues implements IParameterValues {
45
46     public PreferencePageParameterValues() {
47         Platform.getExtensionRegistry().addRegistryChangeListener(
48                 new IRegistryChangeListener() {
49
50                     /*
51                      * (non-Javadoc)
52                      *
53                      * @see org.eclipse.core.runtime.IRegistryChangeListener#registryChanged(org.eclipse.core.runtime.IRegistryChangeEvent)
54                      */

55                     public void registryChanged(IRegistryChangeEvent event) {
56                         if (event.getExtensionDeltas(PlatformUI.PLUGIN_ID,
57                                 IWorkbenchRegistryConstants.PL_PREFERENCES).length > 0) {
58                             preferenceMap = null;
59                         }
60                     }
61                 });
62     }
63
64     private Map JavaDoc preferenceMap;
65
66     /**
67      * Iterate through the preference page and build the map of preference page
68      * names to ids.
69      *
70      * @param values
71      * The Map being populated with parameter values.
72      * @param preferenceNodes
73      * An array of <code>IPreferenceNode</code> to process.
74      * @param namePrefix
75      * A string incorporating the names of each parent
76      * <code>IPreferenceNode</code> up to the root of the
77      * preference page tree. This will be <code>null</code> for the
78      * root level preference page nodes.
79      */

80     private final void collectParameterValues(final Map JavaDoc values,
81             final IPreferenceNode[] preferenceNodes, final String JavaDoc namePrefix) {
82
83         for (int i = 0; i < preferenceNodes.length; i++) {
84             final IPreferenceNode preferenceNode = preferenceNodes[i];
85
86             final String JavaDoc name;
87             if (namePrefix == null) {
88                 name = preferenceNode.getLabelText();
89             } else {
90                 name = namePrefix
91                         + WorkbenchMessages.PreferencePageParameterValues_pageLabelSeparator
92                         + preferenceNode.getLabelText();
93             }
94             final String JavaDoc value = preferenceNode.getId();
95             values.put(name, value);
96
97             collectParameterValues(values, preferenceNode.getSubNodes(), name);
98         }
99     }
100
101     public final Map JavaDoc getParameterValues() {
102         if (preferenceMap == null) {
103             preferenceMap = new TreeMap JavaDoc();
104
105             final PreferenceManager preferenceManager = PlatformUI
106                     .getWorkbench().getPreferenceManager();
107             collectParameterValues(preferenceMap, preferenceManager
108                     .getRootSubNodes(), null);
109         }
110
111         return preferenceMap;
112     }
113
114 }
115
Popular Tags