1 11 package org.eclipse.update.core.model; 12 13 import java.net.MalformedURLException ; 14 import java.net.URL ; 15 import java.util.Comparator ; 16 17 import org.eclipse.update.core.Site; 18 19 35 36 public class CategoryModel extends ModelObject { 37 38 private String name; 39 private String label; 40 private String localizedLabel; 41 private URLEntryModel description; 42 private static Comparator comp; 43 44 49 public CategoryModel() { 50 super(); 51 } 52 53 59 public String getName() { 60 return name; 61 } 62 63 70 public String getLabel() { 71 if (localizedLabel != null) 72 return localizedLabel; 73 else 74 return label; 75 } 76 77 83 public String getLabelNonLocalized() { 84 return label; 85 } 86 87 93 public URLEntryModel getDescriptionModel() { 94 return description; 95 } 96 97 104 public void setLabel(String label) { 105 assertIsWriteable(); 106 this.label = label; 107 this.localizedLabel = null; 108 } 109 110 117 public void setName(String name) { 118 assertIsWriteable(); 119 this.name = name; 120 } 121 122 129 public void setDescriptionModel(URLEntryModel description) { 130 assertIsWriteable(); 131 this.description = description; 132 } 133 134 139 public void markReadOnly() { 140 super.markReadOnly(); 141 markReferenceReadOnly(getDescriptionModel()); 142 } 143 144 156 public void resolve(URL base,URL bundleURL) 157 throws MalformedURLException { 158 localizedLabel = resolveNLString(bundleURL, label); 160 161 resolveReference(getDescriptionModel(),base, bundleURL); 163 } 164 165 171 public boolean equals(Object obj) { 172 boolean result = false; 173 if (obj instanceof CategoryModel) { 174 CategoryModel otherCategory = (CategoryModel) obj; 175 result = getName().equalsIgnoreCase(otherCategory.getName()); 176 } 177 return result; 178 } 179 180 186 public int hashCode() { 187 return getName().hashCode(); 188 } 189 190 196 public static Comparator getComparator() { 197 if (comp == null) { 198 comp = new Comparator () { 199 205 public int compare(Object o1, Object o2) { 206 207 CategoryModel cat1 = (CategoryModel) o1; 208 CategoryModel cat2 = (CategoryModel) o2; 209 210 if (cat1.equals(cat2)) 211 return 0; 212 return cat1.getName().compareTo(cat2.getName()); 213 } 214 }; 215 } 216 return comp; 217 } 218 219 222 protected String getPropertyName() { 223 return Site.SITE_FILE; 224 } 225 } 226 | Popular Tags |