1 11 package org.eclipse.ui.internal.registry; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 import java.util.StringTokenizer ; 16 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.IExtensionRegistry; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.ui.PlatformUI; 21 22 26 public class EditorRegistryReader extends RegistryReader { 27 28 private EditorRegistry editorRegistry; 29 30 39 protected void addEditors(EditorRegistry registry) { 40 IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); 41 this.editorRegistry = registry; 42 readRegistry(extensionRegistry, PlatformUI.PLUGIN_ID, 43 IWorkbenchRegistryConstants.PL_EDITOR); 44 } 45 46 50 protected boolean readElement(IConfigurationElement element) { 51 if (!element.getName().equals(IWorkbenchRegistryConstants.TAG_EDITOR)) { 52 return false; 53 } 54 55 String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 56 if (id == null) { 57 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID); 58 return true; 59 } 60 61 EditorDescriptor editor = new EditorDescriptor(id, element); 62 63 List extensionsVector = new ArrayList (); 64 List filenamesVector = new ArrayList (); 65 List contentTypeVector = new ArrayList (); 66 boolean defaultEditor = false; 67 68 if (element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME) == null) { 70 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_NAME); 71 return true; 72 } 73 74 if (element.getAttribute(IWorkbenchRegistryConstants.ATT_ICON) == null) { 76 if (getClassValue(element, IWorkbenchRegistryConstants.ATT_CLASS) != null) { 77 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ICON); 78 return true; 79 } 80 } 81 82 String extensionsString = element.getAttribute(IWorkbenchRegistryConstants.ATT_EXTENSIONS); 84 if (extensionsString != null) { 85 StringTokenizer tokenizer = new StringTokenizer (extensionsString, 86 ","); while (tokenizer.hasMoreTokens()) { 88 extensionsVector.add(tokenizer.nextToken().trim()); 89 } 90 } 91 String filenamesString = element.getAttribute(IWorkbenchRegistryConstants.ATT_FILENAMES); 92 if (filenamesString != null) { 93 StringTokenizer tokenizer = new StringTokenizer (filenamesString, 94 ","); while (tokenizer.hasMoreTokens()) { 96 filenamesVector.add(tokenizer.nextToken().trim()); 97 } 98 } 99 100 IConfigurationElement [] bindings = element.getChildren(IWorkbenchRegistryConstants.TAG_CONTENT_TYPE_BINDING); 101 for (int i = 0; i < bindings.length; i++) { 102 String contentTypeId = bindings[i].getAttribute(IWorkbenchRegistryConstants.ATT_CONTENT_TYPE_ID); 103 if (contentTypeId == null) { 104 continue; 105 } 106 contentTypeVector.add(contentTypeId); 107 } 108 109 String def = element.getAttribute(IWorkbenchRegistryConstants.ATT_DEFAULT); 111 if (def != null) { 112 defaultEditor = Boolean.valueOf(def).booleanValue(); 113 } 114 115 editorRegistry.addEditorFromPlugin(editor, extensionsVector, 117 filenamesVector, contentTypeVector, defaultEditor); 118 return true; 119 } 120 121 122 126 public void readElement(EditorRegistry editorRegistry, 127 IConfigurationElement element) { 128 this.editorRegistry = editorRegistry; 129 readElement(element); 130 } 131 } 132 | Popular Tags |