Changeset 4882
- Timestamp:
- 04/02/14 15:17:26 (11 years ago)
- Location:
- vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/pojo/ResourceTypeCount.java
r4620 r4882 26 26 public class ResourceTypeCount implements Serializable { 27 27 28 /** 29 * Enumeration for singular/plural distinction. {@link #toString() } 30 * returns "singular" or "plural" respectively to make the resource bundle 31 * files look clean (no screaming) 32 */ 33 public enum Number { 34 35 SINGULAR("singular"), 36 PLURAL("plural"); 37 38 private final String numberString; 39 40 Number(String numberString) { 41 this.numberString = numberString; 42 } 43 44 @Override 45 public String toString() { 46 return numberString; 47 } 48 49 } 50 28 51 private final ResourceType resourceType; 29 52 private final Integer count; … … 40 63 public ResourceType getResourceType() { 41 64 return resourceType; 65 } 66 67 /** 68 * 69 * @return {@link Number#SINGULAR } or {@link Number#PLURAL } depending on 70 * value of {@link #getCount() } 71 */ 72 public Number getNumber() { 73 return getCount() == 1 ? Number.SINGULAR : Number.PLURAL; 42 74 } 43 75 -
vlo/branches/vlo-3.0/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/search/SearchResultItemCollapsedPanel.java
r4881 r4882 25 25 import eu.clarin.cmdi.vlo.wicket.model.SolrFieldModel; 26 26 import eu.clarin.cmdi.vlo.wicket.provider.ResouceTypeCountDataProvider; 27 import java.util.Locale;28 27 import org.apache.solr.common.SolrDocument; 29 28 import org.apache.wicket.markup.html.WebMarkupContainer; … … 35 34 import org.apache.wicket.markup.repeater.data.IDataProvider; 36 35 import org.apache.wicket.model.IModel; 37 import org.apache.wicket.model.Model;38 36 import org.apache.wicket.model.StringResourceModel; 39 37 import org.apache.wicket.spring.injection.annot.SpringBean; 40 import org.apache.wicket.util.convert.ConversionException;41 import org.apache.wicket.util.convert.IConverter;42 38 43 39 /** … … 47 43 public class SearchResultItemCollapsedPanel extends Panel { 48 44 49 private final ResourceTypeCountConverter resourceTypeCountConverter = new ResourceTypeCountConverter();50 45 private static final int MAX_DESCRIPTION_LENGTH = 350; 51 46 private static final int LONG_DESCRIPTION_TRUNCATE_POINT = 320; … … 103 98 protected void populateItem(Item<ResourceTypeCount> item) { 104 99 final Link resourceLink = new RecordPageLink("recordLink", documentModel, selectionModel); 105 final Label label = new Label("resourceCountLabel", item.getModel()) { 106 107 @Override 108 public <C> IConverter<C> getConverter(Class<C> type) { 109 if (type == ResourceTypeCount.class) { 110 return (IConverter<C>) resourceTypeCountConverter; 111 } else { 112 return super.getConverter(type); 113 } 114 } 115 116 }; 117 100 final Label label = new Label("resourceCountLabel", getResourceCountModel(item.getModel())); 118 101 resourceLink.add(label); 119 102 item.add(resourceLink); 120 103 } 104 105 /** 106 * 107 * @param resourceTypeCountModel 108 * @return a string model that conveys the type of resource and number 109 * of instances 110 */ 111 private IModel<String> getResourceCountModel(final IModel<ResourceTypeCount> resourceTypeCountModel) { 112 // first create a string model that provides the type of resources 113 // in the right number (plural or singular, conveniently supplied by ResourceTypeCount) 114 final StringResourceModel resourceTypeModel = new StringResourceModel("resourcetype.${resourceType}.${number}", resourceTypeCountModel, "?"); 115 // inject this into the resource string that combines it with count 116 return new StringResourceModel("resources.typecount", this, resourceTypeCountModel, resourceTypeModel); 117 } 121 118 } 122 119 123 /**124 * One-way converter for resource type counts that generates string125 * representations like "1 video file", "2 video files" or "3 text126 * documents"127 */128 private static class ResourceTypeCountConverter implements IConverter<ResourceTypeCount> {129 130 @Override131 public ResourceTypeCount convertToObject(String value, Locale locale) throws ConversionException {132 throw new UnsupportedOperationException("Not supported");133 }134 135 @Override136 public String convertToString(ResourceTypeCount value, Locale locale) {137 final String resourceTypeString = getResourceTypeString(value);138 return String.format("%d %s", value.getCount(), resourceTypeString);139 }140 141 private String getResourceTypeString(ResourceTypeCount value) {142 final String count = value.getCount() == 1 ? "singular" : "plural";143 final StringResourceModel resourceModel = new StringResourceModel("resourcetype.${resourceType}." + count, Model.of(value), "?");144 return resourceModel.getObject();145 }146 147 }148 120 }
Note: See TracChangeset
for help on using the changeset viewer.