1 11 package org.eclipse.ui.texteditor.spelling; 12 13 import org.osgi.framework.Bundle; 14 15 import org.eclipse.core.runtime.Assert; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.Platform; 19 20 21 import org.eclipse.ui.internal.texteditor.spelling.EmptySpellingPreferenceBlock; 22 23 31 public class SpellingEngineDescriptor { 32 33 34 private static final String LABEL_ATTRIBUTE= "label"; 36 private static final String CLASS_ATTRIBUTE= "class"; 38 private static final String ID_ATTRIBUTE= "id"; 40 private static final String DEFAULT_ATTRIBUTE= "default"; 42 private static final String PREFERENCES_CLASS_ATTRIBUTE= "preferencesClass"; 44 45 private IConfigurationElement fConfiguration; 46 47 private String fLabel; 48 49 private String fId; 50 51 private Boolean fDefault; 52 53 private Bundle fBundle; 54 55 private Boolean fHasPreferences; 56 57 65 public SpellingEngineDescriptor(IConfigurationElement element) { 66 Assert.isLegal(element != null); 67 fConfiguration= element; 68 } 69 70 75 public String getLabel() { 76 if (fLabel == null) { 77 fLabel= fConfiguration.getAttribute(LABEL_ATTRIBUTE); 78 Assert.isNotNull(fLabel); 79 } 80 return fLabel; 81 } 82 83 88 public String getId() { 89 if (fId == null) { 90 fId= fConfiguration.getAttribute(ID_ATTRIBUTE); 91 Assert.isNotNull(fId); 92 } 93 return fId; 94 } 95 96 102 public ISpellingEngine createEngine() throws CoreException { 103 return (ISpellingEngine)fConfiguration.createExecutableExtension(CLASS_ATTRIBUTE); 104 } 105 106 113 private boolean hasPreferences() { 114 if (fHasPreferences == null) 115 if (fConfiguration.getAttribute(PREFERENCES_CLASS_ATTRIBUTE) == null) 116 fHasPreferences= Boolean.FALSE; 117 else 118 fHasPreferences= Boolean.TRUE; 119 return fHasPreferences.booleanValue(); 120 } 121 122 128 public ISpellingPreferenceBlock createPreferences() throws CoreException { 129 if (hasPreferences()) 130 return (ISpellingPreferenceBlock) fConfiguration.createExecutableExtension(PREFERENCES_CLASS_ATTRIBUTE); 131 return new EmptySpellingPreferenceBlock(); 132 } 133 134 139 public boolean isPluginLoaded() { 140 if (fBundle == null) 141 fBundle= Platform.getBundle(fConfiguration.getContributor().getName()); 142 return (fBundle != null && fBundle.getState() == Bundle.ACTIVE); 143 } 144 145 150 public boolean isDefault() { 151 if (fDefault == null) { 152 String def= fConfiguration.getAttribute(DEFAULT_ATTRIBUTE); 153 if ("true".equalsIgnoreCase(def)) fDefault= Boolean.TRUE; 155 else 156 fDefault= Boolean.FALSE; 157 } 158 return fDefault.booleanValue(); 159 } 160 } | Popular Tags |