1 11 package org.eclipse.ui.internal.registry; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.List ; 16 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.IExtensionRegistry; 19 import org.eclipse.jface.preference.IPreferenceNode; 20 import org.eclipse.ui.IWorkbench; 21 import org.eclipse.ui.PlatformUI; 22 import org.eclipse.ui.internal.Workbench; 23 import org.eclipse.ui.internal.dialogs.WorkbenchPreferenceNode; 24 25 29 public class PreferencePageRegistryReader extends CategorizedPageRegistryReader { 30 31 private static final String TAG_PAGE = "page"; 33 private List nodes; 34 35 private IWorkbench workbench; 36 37 38 class PreferencesCategoryNode extends CategoryNode { 39 40 WorkbenchPreferenceNode node; 41 42 47 public PreferencesCategoryNode(CategorizedPageRegistryReader reader, 48 WorkbenchPreferenceNode nodeToCategorize) { 49 super(reader); 50 this.node = nodeToCategorize; 51 } 52 53 56 String getLabelText() { 57 return node.getLabelText(); 58 } 59 60 63 String getLabelText(Object element) { 64 return ((WorkbenchPreferenceNode) element).getLabelText(); 65 } 66 67 70 Object getNode() { 71 return node; 72 } 73 } 74 75 80 public PreferencePageRegistryReader(IWorkbench newWorkbench) { 81 workbench = newWorkbench; 82 } 83 84 87 Object findNode(String id) { 88 for (int i = 0; i < nodes.size(); i++) { 89 WorkbenchPreferenceNode node = (WorkbenchPreferenceNode) nodes.get(i); 90 if (node.getId().equals(id)) { 91 return node; 92 } 93 } 94 return null; 95 } 96 97 100 Object findNode(Object parent, String currentToken) { 101 IPreferenceNode[] subNodes = ((WorkbenchPreferenceNode) parent).getSubNodes(); 102 for (int i = 0; i < subNodes.length; i++) { 103 WorkbenchPreferenceNode node = (WorkbenchPreferenceNode) subNodes[i]; 104 if (node.getId().equals(currentToken)) { 105 return node; 106 } 107 } 108 return null; 109 } 110 111 114 void add(Object parent, Object node) { 115 ((IPreferenceNode) parent).add((IPreferenceNode) node); 116 } 117 118 121 CategoryNode createCategoryNode(CategorizedPageRegistryReader reader, Object object) { 122 return new PreferencesCategoryNode(reader, (WorkbenchPreferenceNode) object); 123 } 124 125 128 String getCategory(Object node) { 129 return ((WorkbenchPreferenceNode) node).getCategory(); 130 } 131 132 135 Collection getNodes() { 136 return nodes; 137 } 138 139 150 public void loadFromRegistry(IExtensionRegistry registry) { 151 nodes = new ArrayList (); 152 153 readRegistry(registry, PlatformUI.PLUGIN_ID, IWorkbenchRegistryConstants.PL_PREFERENCES); 154 155 processNodes(); 156 157 } 158 159 162 protected boolean readElement(IConfigurationElement element) { 163 if (element.getName().equals(TAG_PAGE) == false) { 164 return false; 165 } 166 WorkbenchPreferenceNode node = createNode(element); 167 if (node != null) { 168 nodes.add(node); 169 } 170 return true; 171 } 172 173 178 public static WorkbenchPreferenceNode createNode(IConfigurationElement element) { 179 boolean nameMissing = element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME) == null; 180 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 181 boolean classMissing = getClassValue(element, IWorkbenchRegistryConstants.ATT_CLASS) == null; 182 183 if (nameMissing) { 184 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_NAME); 185 } 186 if (id == null) { 187 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID); 188 } 189 if (classMissing) { 190 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_CLASS); 191 } 192 193 if (nameMissing || id == null || classMissing) { 194 return null; 195 } 196 197 WorkbenchPreferenceNode node = new WorkbenchPreferenceNode(id, element); 198 return node; 199 } 200 201 205 public Collection getTopLevelNodes() { 206 return topLevelNodes; 207 } 208 209 212 String getFavoriteNodeId() { 213 return ((Workbench) workbench).getMainPreferencePageId(); 214 } 215 } 216 | Popular Tags |