1 11 package org.eclipse.ui.internal.registry; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 18 import org.eclipse.core.runtime.IConfigurationElement; 19 import org.eclipse.core.runtime.IExtensionRegistry; 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.internal.dialogs.PropertyPageContributorManager; 22 import org.eclipse.ui.internal.dialogs.RegistryPageContributor; 23 24 27 public class PropertyPagesRegistryReader extends CategorizedPageRegistryReader { 28 29 32 public static final String ATT_NAME_FILTER = "nameFilter"; 34 37 public static final String ATT_FILTER_NAME = "name"; 39 42 public static final String ATT_FILTER_VALUE = "value"; 44 private static final String TAG_PAGE = "page"; 46 49 public static final String TAG_FILTER = "filter"; 51 54 public static final String TAG_KEYWORD_REFERENCE = "keywordReference"; 56 59 public static final String ATT_OBJECTCLASS = "objectClass"; 61 64 public static final String ATT_ADAPTABLE = "adaptable"; 66 private static final String CHILD_ENABLED_WHEN = "enabledWhen"; 68 private Collection pages = new ArrayList (); 69 70 private PropertyPageContributorManager manager; 71 72 class PropertyCategoryNode extends CategoryNode { 73 74 RegistryPageContributor page; 75 76 82 PropertyCategoryNode(CategorizedPageRegistryReader reader, 83 RegistryPageContributor propertyPage) { 84 super(reader); 85 page = propertyPage; 86 } 87 88 93 String getLabelText() { 94 return page.getPageName(); 95 } 96 97 102 String getLabelText(Object element) { 103 return ((RegistryPageContributor) element).getPageName(); 104 } 105 106 111 Object getNode() { 112 return page; 113 } 114 } 115 116 122 public PropertyPagesRegistryReader(PropertyPageContributorManager manager) { 123 this.manager = manager; 124 } 125 126 129 private void processPageElement(IConfigurationElement element) { 130 String pageId = element 131 .getAttribute(IWorkbenchRegistryConstants.ATT_ID); 132 133 if (pageId == null) { 134 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID); 135 return; 136 } 137 138 RegistryPageContributor contributor = new RegistryPageContributor( 139 pageId, element); 140 141 String pageClassName = getClassValue(element, 142 IWorkbenchRegistryConstants.ATT_CLASS); 143 if (pageClassName == null) { 144 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_CLASS); 145 return; 146 } 147 if (element.getAttribute(ATT_OBJECTCLASS) == null) { 148 pages.add(contributor); 149 manager.registerContributor(contributor, Object .class.getName()); 150 } else { 151 List objectClassNames = new ArrayList (); 152 objectClassNames.add(element.getAttribute(ATT_OBJECTCLASS)); 153 registerContributors(contributor, objectClassNames); 154 } 155 } 156 157 163 private void registerContributors(RegistryPageContributor contributor, 164 List objectClassNames) { 165 166 pages.add(contributor); 167 for (Iterator iter = objectClassNames.iterator(); iter.hasNext();) { 168 manager.registerContributor(contributor, (String ) iter.next()); 169 } 170 171 } 172 173 174 179 public boolean readElement(IConfigurationElement element) { 180 if (element.getName().equals(TAG_PAGE)) { 181 processPageElement(element); 182 readElementChildren(element); 183 return true; 184 } 185 if (element.getName().equals(TAG_FILTER)) { 186 return true; 187 } 188 189 if (element.getName().equals(CHILD_ENABLED_WHEN)) { 190 return true; 191 } 192 193 if (element.getName().equals(TAG_KEYWORD_REFERENCE)) { 194 return true; 195 } 196 197 return false; 198 } 199 200 206 public void registerPropertyPages(IExtensionRegistry registry) { 207 readRegistry(registry, PlatformUI.PLUGIN_ID, 208 IWorkbenchRegistryConstants.PL_PROPERTY_PAGES); 209 processNodes(); 210 } 211 212 218 void add(Object parent, Object node) { 219 ((RegistryPageContributor) parent) 220 .addSubPage((RegistryPageContributor) node); 221 222 } 223 224 230 CategoryNode createCategoryNode(CategorizedPageRegistryReader reader, 231 Object object) { 232 return new PropertyCategoryNode(reader, 233 (RegistryPageContributor) object); 234 } 235 236 242 Object findNode(Object parent, String currentToken) { 243 return ((RegistryPageContributor) parent).getChild(currentToken); 244 } 245 246 251 Object findNode(String id) { 252 Iterator iterator = pages.iterator(); 253 while (iterator.hasNext()) { 254 RegistryPageContributor next = (RegistryPageContributor) iterator 255 .next(); 256 if (next.getPageId().equals(id)) 257 return next; 258 } 259 return null; 260 } 261 262 267 String getCategory(Object node) { 268 return ((RegistryPageContributor) node).getCategory(); 269 } 270 271 276 String getFavoriteNodeId() { 277 return null; } 279 280 285 Collection getNodes() { 286 return pages; 287 } 288 } 289 | Popular Tags |