1 11 12 package org.eclipse.ui.internal.registry; 13 14 import java.util.Map ; 15 import java.util.TreeMap ; 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 44 public final class PreferencePageParameterValues implements IParameterValues { 45 46 public PreferencePageParameterValues() { 47 Platform.getExtensionRegistry().addRegistryChangeListener( 48 new IRegistryChangeListener() { 49 50 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 preferenceMap; 65 66 80 private final void collectParameterValues(final Map values, 81 final IPreferenceNode[] preferenceNodes, final String namePrefix) { 82 83 for (int i = 0; i < preferenceNodes.length; i++) { 84 final IPreferenceNode preferenceNode = preferenceNodes[i]; 85 86 final String 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 value = preferenceNode.getId(); 95 values.put(name, value); 96 97 collectParameterValues(values, preferenceNode.getSubNodes(), name); 98 } 99 } 100 101 public final Map getParameterValues() { 102 if (preferenceMap == null) { 103 preferenceMap = new TreeMap (); 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 |