1 11 12 package org.eclipse.ui.internal.quickaccess; 13 14 import java.util.ArrayList ; 15 import java.util.HashMap ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.jface.preference.IPreferenceNode; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.IWorkbenchGraphicConstants; 23 import org.eclipse.ui.internal.WorkbenchImages; 24 25 29 public class PreferenceProvider extends QuickAccessProvider { 30 31 private QuickAccessElement[] cachedElements; 32 private Map idToElement = new HashMap (); 33 34 public String getId() { 35 return "org.eclipse.ui.preferences"; } 37 38 public QuickAccessElement getElementForId(String id) { 39 getElements(); 40 return (PreferenceElement) idToElement.get(id); 41 } 42 43 public QuickAccessElement[] getElements() { 44 if (cachedElements == null) { 45 List list = new ArrayList (); 46 collectElements("", PlatformUI.getWorkbench().getPreferenceManager().getRootSubNodes(), list); cachedElements = new PreferenceElement[list.size()]; 48 for (int i = 0; i < list.size(); i++) { 49 PreferenceElement preferenceElement = (PreferenceElement) list.get(i); 50 cachedElements[i] = preferenceElement; 51 idToElement.put(preferenceElement.getId(), preferenceElement); 52 } 53 } 54 return cachedElements; 55 } 56 57 61 private void collectElements(String prefix, IPreferenceNode[] subNodes, List result) { 62 for (int i = 0; i < subNodes.length; i++) { 63 PreferenceElement preferenceElement = new PreferenceElement( 64 subNodes[i], prefix, this); 65 result.add(preferenceElement); 66 String nestedPrefix = prefix.length() == 0 ? subNodes[i].getLabelText() : (prefix + "/" + subNodes[i].getLabelText()); collectElements(nestedPrefix, subNodes[i].getSubNodes(), result); 68 } 69 } 70 71 public ImageDescriptor getImageDescriptor() { 72 return WorkbenchImages 73 .getImageDescriptor(IWorkbenchGraphicConstants.IMG_OBJ_NODE); 74 } 75 76 public String getName() { 77 return QuickAccessMessages.QuickAccess_Preferences; 78 } 79 } 80 | Popular Tags |