1 11 12 package org.eclipse.ui.internal.registry; 13 14 import com.ibm.icu.text.Collator; 15 import java.util.ArrayList ; 16 import java.util.Collections ; 17 import java.util.Comparator ; 18 import java.util.HashMap ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.eclipse.core.runtime.IConfigurationElement; 23 import org.eclipse.core.runtime.IExtensionRegistry; 24 import org.eclipse.core.runtime.Platform; 25 import org.eclipse.core.runtime.preferences.PreferenceFilterEntry; 26 import org.eclipse.ui.internal.WorkbenchPlugin; 27 import org.eclipse.ui.internal.preferences.PreferenceTransferElement; 28 29 35 public class PreferenceTransferRegistryReader extends RegistryReader { 36 private List preferenceTransfers; 37 38 private String pluginPoint; 39 40 46 public PreferenceTransferRegistryReader(String pluginPointId) { 47 pluginPoint = pluginPointId; 48 } 49 50 51 52 59 protected PreferenceTransferElement createPreferenceTransferElement( 60 IConfigurationElement element) { 61 if (element.getAttribute(IWorkbenchRegistryConstants.ATT_NAME) == null) { 63 logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_NAME); 64 return null; 65 } 66 67 if (element.getChildren(IWorkbenchRegistryConstants.TAG_MAPPING) == null) { 69 logMissingElement(element, IWorkbenchRegistryConstants.TAG_MAPPING); 70 return null; 71 } 72 73 return new PreferenceTransferElement(element); 74 } 75 76 81 public PreferenceTransferElement[] getPreferenceTransfers() { 82 readPreferenceTransfers(); 83 PreferenceTransferElement[] transfers = new PreferenceTransferElement[preferenceTransfers 84 .size()]; 85 Collections.sort(preferenceTransfers, new Comparator () { 86 public int compare(Object o1, Object o2) { 87 String name1 = ((PreferenceTransferElement) o1).getName(); 88 String name2 = ((PreferenceTransferElement) o2).getName(); 89 90 return Collator.getInstance().compare(name1, name2); 91 } 92 }); 93 preferenceTransfers.toArray(transfers); 94 return transfers; 95 } 96 97 102 protected boolean readElement(IConfigurationElement element) { 103 if (element.getName().equals(IWorkbenchRegistryConstants.TAG_TRANSFER)) { 104 105 PreferenceTransferElement transfer = createPreferenceTransferElement(element); 106 if (transfer != null) 107 preferenceTransfers.add(transfer); 108 return true; 109 } 110 111 113 return element.getName().equals( 114 IWorkbenchRegistryConstants.TAG_SETTINGS_TRANSFER); 115 } 116 117 120 protected void readPreferenceTransfers() { 121 preferenceTransfers = new ArrayList (); 122 IExtensionRegistry registry = Platform.getExtensionRegistry(); 123 readRegistry(registry, WorkbenchPlugin.PI_WORKBENCH, pluginPoint); 124 } 125 126 132 public static IConfigurationElement[] getMappings( 133 IConfigurationElement configElement) { 134 IConfigurationElement[] children = configElement 135 .getChildren(IWorkbenchRegistryConstants.TAG_MAPPING); 136 if (children.length < 1) { 137 logMissingElement(configElement, 138 IWorkbenchRegistryConstants.TAG_MAPPING); 139 return null; 140 } 141 return children; 142 } 143 144 148 public static String getScope(IConfigurationElement element) { 149 return element.getAttribute(IWorkbenchRegistryConstants.ATT_SCOPE); 150 } 151 152 156 public static Map getEntry(IConfigurationElement element) { 157 IConfigurationElement[] entries = element 158 .getChildren(IWorkbenchRegistryConstants.TAG_ENTRY); 159 if (entries.length == 0) { 160 return null; 161 } 162 Map map = new HashMap (entries.length); 163 for (int i = 0; i < entries.length; i++) { 164 IConfigurationElement entry = entries[i]; 165 IConfigurationElement[] keys = entry 166 .getChildren(IWorkbenchRegistryConstants.ATT_KEY); 167 PreferenceFilterEntry[] prefFilters = null; 168 if (keys.length > 0) { 169 prefFilters = new PreferenceFilterEntry[keys.length]; 170 for (int j = 0; j < keys.length; j++) { 171 IConfigurationElement keyElement = keys[j]; 172 prefFilters[j] = new PreferenceFilterEntry(keyElement 173 .getAttribute(IWorkbenchRegistryConstants.ATT_NAME)); 174 } 175 } 176 map.put(entry.getAttribute(IWorkbenchRegistryConstants.ATT_NODE), 177 prefFilters); 178 } 179 return map; 180 } 181 } 182 | Popular Tags |