1 11 package org.eclipse.ui.internal.about; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 import com.ibm.icu.text.Collator; 16 import java.util.Arrays ; 17 import java.util.Collections ; 18 import java.util.Comparator ; 19 import java.util.List ; 20 import java.util.Locale ; 21 22 import org.eclipse.jface.resource.ImageDescriptor; 23 24 29 public abstract class AboutData { 30 private String providerName; 31 32 private String name; 33 34 private String version; 35 36 private String id; 37 38 private String versionedId = null; 39 40 protected AboutData(String providerName, String name, String version, 41 String id) { 42 this.providerName = providerName == null ? "" : providerName; this.name = name == null ? "" : name; this.version = version == null ? "" : version; this.id = id == null ? "" : id; } 47 48 public String getId() { 49 return id; 50 } 51 52 public String getName() { 53 return name; 54 } 55 56 public String getProviderName() { 57 return providerName; 58 } 59 60 public String getVersion() { 61 return version; 62 } 63 64 public String getVersionedId() { 65 if (versionedId == null) { 66 versionedId = getId() + "_" + getVersion(); } 68 return versionedId; 69 } 70 71 75 private static void reverse(AboutData[] infos) { 76 List infoList = Arrays.asList(infos); 77 Collections.reverse(infoList); 78 for (int i = 0; i < infos.length; ++i) { 79 infos[i] = (AboutData) infoList.get(i); 80 } 81 } 82 83 95 public static void sortByProvider(boolean reverse, AboutData[] infos) { 96 if (reverse) { 97 reverse(infos); 98 return; 99 } 100 101 Arrays.sort(infos, new Comparator () { 102 Collator collator = Collator.getInstance(Locale.getDefault()); 103 104 public int compare(Object a, Object b) { 105 AboutData info1 = (AboutData) a; 106 AboutData info2 = (AboutData) b; 107 108 String provider1 = info1.getProviderName(); 109 String provider2 = info2.getProviderName(); 110 111 if (!provider1.equals(provider2)) { 112 return collator.compare(provider1, provider2); 113 } 114 115 return collator.compare(info1.getName(), info2.getName()); 116 } 117 }); 118 } 119 120 131 public static void sortByName(boolean reverse, AboutData[] infos) { 132 if (reverse) { 133 reverse(infos); 134 return; 135 } 136 137 Arrays.sort(infos, new Comparator () { 138 Collator collator = Collator.getInstance(Locale.getDefault()); 139 140 public int compare(Object a, Object b) { 141 AboutData info1 = (AboutData) a; 142 AboutData info2 = (AboutData) b; 143 return collator.compare(info1.getName(), info2.getName()); 144 } 145 }); 146 } 147 148 160 public static void sortByVersion(boolean reverse, AboutData[] infos) { 161 if (reverse) { 162 reverse(infos); 163 return; 164 } 165 166 Arrays.sort(infos, new Comparator () { 167 Collator collator = Collator.getInstance(Locale.getDefault()); 168 169 public int compare(Object a, Object b) { 170 AboutData info1 = (AboutData) a; 171 AboutData info2 = (AboutData) b; 172 173 String version1 = info1.getVersion(); 174 String version2 = info2.getVersion(); 175 176 if (!version1.equals(version2)) { 177 return collator.compare(version1, version2); 178 } 179 180 return collator.compare(info1.getName(), info2.getName()); 181 } 182 }); 183 } 184 185 197 public static void sortById(boolean reverse, AboutData[] infos) { 198 if (reverse) { 199 reverse(infos); 200 return; 201 } 202 203 Arrays.sort(infos, new Comparator () { 204 Collator collator = Collator.getInstance(Locale.getDefault()); 205 206 public int compare(Object a, Object b) { 207 AboutData info1 = (AboutData) a; 208 AboutData info2 = (AboutData) b; 209 210 String id1 = info1.getId(); 211 String id2 = info2.getId(); 212 213 if (!id1.equals(id2)) { 214 return collator.compare(id1, id2); 215 } 216 217 return collator.compare(info1.getName(), info2.getName()); 218 } 219 }); 220 } 221 222 protected static URL getURL(String value) { 223 try { 224 if (value != null) { 225 return new URL (value); 226 } 227 } catch (IOException e) { 228 } 230 231 return null; 232 } 233 234 protected static ImageDescriptor getImage(URL url) { 235 return url == null ? null : ImageDescriptor.createFromURL(url); 236 } 237 238 protected static ImageDescriptor getImage(String value) { 239 return getImage(getURL(value)); 240 } 241 } 242 | Popular Tags |