1 11 package org.eclipse.ui.internal.preferences; 12 13 import java.util.Map ; 14 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IConfigurationElement; 17 import org.eclipse.core.runtime.preferences.IPreferenceFilter; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.ui.IPluginContribution; 20 import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; 21 import org.eclipse.ui.internal.registry.PreferenceTransferRegistryReader; 22 import org.eclipse.ui.internal.registry.RegistryReader; 23 import org.eclipse.ui.model.WorkbenchAdapter; 24 import org.eclipse.ui.plugin.AbstractUIPlugin; 25 26 31 public class PreferenceTransferElement extends WorkbenchAdapter implements 32 IPluginContribution { 33 private String id; 34 35 private ImageDescriptor imageDescriptor; 36 37 private IConfigurationElement configurationElement; 38 39 private IPreferenceFilter filter; 40 41 47 public PreferenceTransferElement(IConfigurationElement configurationElement) { 48 this.configurationElement = configurationElement; 49 id = configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_ID); 50 } 51 52 55 public IConfigurationElement getConfigurationElement() { 56 return configurationElement; 57 } 58 59 66 public IPreferenceFilter getFilter() throws CoreException { 67 if (filter == null) { 69 IConfigurationElement[] mappings = PreferenceTransferRegistryReader.getMappings(configurationElement); 70 PreferenceFilter prefFilter = new PreferenceFilter(); 71 prefFilter.scopes = new String [mappings.length]; 72 prefFilter.maps = new Map [mappings.length]; 73 for (int i = 0; i < mappings.length; i++) { 74 prefFilter.scopes[i] = PreferenceTransferRegistryReader.getScope(mappings[i]); 75 prefFilter.maps[i] = PreferenceTransferRegistryReader.getEntry(mappings[i]); 76 } 77 filter = prefFilter; 78 } 79 return filter; 80 } 81 82 87 public String getDescription() { 88 return RegistryReader.getDescription(configurationElement); 89 } 90 91 96 public String getID() { 97 return id; 98 } 99 100 105 public ImageDescriptor getImageDescriptor() { 106 if (imageDescriptor == null) { 107 String iconName = configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_ICON); 108 if (iconName == null) { 109 return null; 110 } 111 imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( 112 configurationElement.getNamespace(), iconName); 113 } 114 return imageDescriptor; 115 } 116 117 121 public String getName() { 122 return configurationElement.getAttribute(IWorkbenchRegistryConstants.ATT_NAME); 123 } 124 125 128 public String getLocalId() { 129 return getID(); 130 } 131 132 135 public String getPluginId() { 136 return (configurationElement != null) ? configurationElement 137 .getNamespace() : null; 138 } 139 140 class PreferenceFilter implements IPreferenceFilter { 141 142 protected String [] scopes; 143 protected Map [] maps; 144 145 public String [] getScopes() { 146 return scopes; 147 } 148 149 public Map getMapping(String scope) { 150 for (int i = 0; i < scopes.length; i++) { 151 String item = scopes[i]; 152 if (item.equals(scope)) { 153 return maps[i]; 154 } 155 } 156 return null; 157 } 158 159 } 160 } 161 | Popular Tags |