1 11 12 package org.eclipse.ui.internal.preferences; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.Collections ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 20 import org.eclipse.core.runtime.IConfigurationElement; 21 import org.eclipse.jface.preference.PreferenceNode; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.swt.graphics.Image; 24 import org.eclipse.ui.IPluginContribution; 25 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 26 import org.eclipse.ui.internal.registry.KeywordRegistry; 27 import org.eclipse.ui.plugin.AbstractUIPlugin; 28 29 35 public abstract class WorkbenchPreferenceExtensionNode extends PreferenceNode implements IPluginContribution { 36 37 private static final String TAG_KEYWORD_REFERENCE = "keywordReference"; 39 private Collection keywordReferences; 40 41 private IConfigurationElement configurationElement; 42 43 private ImageDescriptor imageDescriptor; 44 45 private Image image; 46 47 private Collection keywordLabelCache; 48 49 50 56 public WorkbenchPreferenceExtensionNode(String id, IConfigurationElement configurationElement) { 57 super(id); 58 this.configurationElement = configurationElement; 59 } 60 61 66 public Collection getKeywordReferences() { 67 if (keywordReferences == null) { 68 IConfigurationElement[] references = getConfigurationElement() 69 .getChildren(TAG_KEYWORD_REFERENCE); 70 HashSet list = new HashSet (references.length); 71 for (int i = 0; i < references.length; i++) { 72 IConfigurationElement page = references[i]; 73 String id = page.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 74 if (id != null) { 75 list.add(id); 76 } 77 } 78 79 if (!list.isEmpty()) { 80 keywordReferences = list; 81 } else { 82 keywordReferences = Collections.EMPTY_SET; 83 } 84 85 } 86 return keywordReferences; 87 } 88 89 94 public Collection getKeywordLabels() { 95 if (keywordLabelCache != null) { 96 return keywordLabelCache; 97 } 98 99 Collection refs = getKeywordReferences(); 100 101 if(refs == Collections.EMPTY_SET) { 102 keywordLabelCache = Collections.EMPTY_SET; 103 return keywordLabelCache; 104 } 105 106 keywordLabelCache = new ArrayList (refs.size()); 107 Iterator referenceIterator = refs.iterator(); 108 while(referenceIterator.hasNext()){ 109 Object label = KeywordRegistry.getInstance().getKeywordLabel( 110 (String ) referenceIterator.next()); 111 if(label != null) { 112 keywordLabelCache.add(label); 113 } 114 } 115 116 return keywordLabelCache; 117 } 118 119 122 public void clearKeywords() { 123 keywordLabelCache = null; 124 } 125 126 129 public void disposeResources() { 130 if (image != null) { 131 image.dispose(); 132 image = null; 133 } 134 super.disposeResources(); 135 } 136 137 140 public Image getLabelImage() { 141 if (image == null) { 142 ImageDescriptor desc = getImageDescriptor(); 143 if (desc != null) { 144 image = imageDescriptor.createImage(); 145 } 146 } 147 return image; 148 } 149 150 151 154 public String getLabelText() { 155 return getConfigurationElement().getAttribute(IWorkbenchRegistryConstants.ATT_NAME); 156 } 157 158 163 public ImageDescriptor getImageDescriptor() { 164 if (imageDescriptor != null) { 165 return imageDescriptor; 166 } 167 168 String imageName = getConfigurationElement().getAttribute(IWorkbenchRegistryConstants.ATT_ICON); 169 if (imageName != null) { 170 String contributingPluginId = getConfigurationElement().getNamespace(); 171 imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(contributingPluginId, imageName); 172 } 173 return imageDescriptor; 174 } 175 176 181 public IConfigurationElement getConfigurationElement() { 182 return configurationElement; 183 } 184 185 188 public String getLocalId() { 189 return getId(); 190 } 191 192 195 public String getPluginId() { 196 return getConfigurationElement().getNamespace(); 197 } 198 } 199 | Popular Tags |