1 11 12 package org.eclipse.ui.internal.texteditor.spelling; 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.core.runtime.IConfigurationElement; 20 import org.eclipse.core.runtime.Platform; 21 22 import org.eclipse.ui.internal.texteditor.TextEditorPlugin; 23 import org.eclipse.ui.texteditor.spelling.SpellingEngineDescriptor; 24 25 33 public class SpellingEngineRegistry { 34 35 39 public static final String SPELLING_ENGINE_EXTENSION_POINT= "spellingEngine"; 41 42 private Map fDescriptorsMap; 43 44 45 private SpellingEngineDescriptor fDefaultDescriptor; 46 47 48 private SpellingEngineDescriptor[] fDescriptors; 49 50 51 private boolean fLoaded= false; 52 53 60 public SpellingEngineDescriptor getDescriptor(String id) { 61 ensureExtensionsLoaded(); 62 return (SpellingEngineDescriptor) fDescriptorsMap.get(id); 63 } 64 65 70 public SpellingEngineDescriptor getDefaultDescriptor() { 71 ensureExtensionsLoaded(); 72 return fDefaultDescriptor; 73 } 74 75 80 public SpellingEngineDescriptor[] getDescriptors() { 81 ensureExtensionsLoaded(); 82 return fDescriptors; 83 } 84 85 92 public synchronized void reloadExtensions() { 93 List descriptors= new ArrayList (); 94 fDescriptorsMap= new HashMap (); 95 fDefaultDescriptor= null; 96 IConfigurationElement[] elements= Platform.getExtensionRegistry().getConfigurationElementsFor(TextEditorPlugin.PLUGIN_ID, SPELLING_ENGINE_EXTENSION_POINT); 97 for (int i= 0; i < elements.length; i++) { 98 SpellingEngineDescriptor descriptor= new SpellingEngineDescriptor(elements[i]); 99 descriptors.add(descriptor); 100 fDescriptorsMap.put(descriptor.getId(), descriptor); 101 if (fDefaultDescriptor == null && descriptor.isDefault()) 102 fDefaultDescriptor= descriptor; 103 } 104 fDescriptors= (SpellingEngineDescriptor[]) descriptors.toArray(new SpellingEngineDescriptor[descriptors.size()]); 105 fLoaded= true; 106 } 107 108 111 private void ensureExtensionsLoaded() { 112 if (!fLoaded) 113 reloadExtensions(); 114 } 115 } 116 | Popular Tags |