Changeset 6012
- Timestamp:
- 02/23/15 11:01:21 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/wicket/panels/BreadCrumbPanel.java
r5224 r6012 24 24 import eu.clarin.cmdi.vlo.wicket.pages.FacetedSearchPage; 25 25 import eu.clarin.cmdi.vlo.wicket.provider.FacetSelectionProvider; 26 import eu.clarin.cmdi.vlo.wicket.provider.FieldValueConverterProvider; 26 27 import java.util.Collection; 27 28 import java.util.Iterator; … … 52 53 */ 53 54 public class BreadCrumbPanel extends GenericPanel<QueryFacetsSelection> { 54 55 55 56 @SpringBean(name = "queryParametersConverter") 56 57 private PageParametersConverter<QueryFacetsSelection> paramsConverter; 57 58 @SpringBean 59 private FieldValueConverterProvider fieldValueConverterProvider; 60 58 61 private final WebMarkupContainer query; 59 62 private final WebMarkupContainer facets; 60 63 61 64 public BreadCrumbPanel(String id, IModel<QueryFacetsSelection> model) { 62 65 super(id, model); … … 65 68 add(facets = createFacets(model, "facets")); 66 69 } 67 70 68 71 private WebMarkupContainer createQuery(final IModel<QueryFacetsSelection> selectionModel, String id) { 69 72 final WebMarkupContainer queryContainer = new WebMarkupContainer(id); 70 73 final Link link = new AjaxFallbackLink("leavequery") { 71 74 72 75 @Override 73 76 public void onClick(AjaxRequestTarget target) { … … 81 84 return queryContainer; 82 85 } 83 86 84 87 private WebMarkupContainer createFacets(final IModel<QueryFacetsSelection> model, String id) { 85 88 final WebMarkupContainer facetsContainer = new WebMarkupContainer(id); 86 89 facetsContainer.add(new AjaxFallbackLink("leaveselection") { 87 90 88 91 @Override 89 92 public void onClick(AjaxRequestTarget target) { … … 95 98 final FacetSelectionProvider facetSelectionProvider = new FacetSelectionProvider(model); 96 99 facetsContainer.add(new DataView<Map.Entry<String, FacetSelection>>("facet", facetSelectionProvider) { 97 100 98 101 @Override 99 102 protected void populateItem(final Item<Map.Entry<String, FacetSelection>> item) { … … 101 104 // add a label for the selected facet value(s) 102 105 final Label valueLabel = new Label("value", new PropertyModel(selectionModel, "value")) { 103 106 104 107 @Override 105 108 public <C> IConverter<C> getConverter(Class<C> type) { 109 final String facet = item.getModelObject().getKey(); 106 110 // converter to render the value(s) nicely 107 return (IConverter<C>) new SelectionConverter( item.getModelObject().getKey());111 return (IConverter<C>) new SelectionConverter(facet, fieldValueConverterProvider.getConverter(facet)); 108 112 } 109 113 110 114 }; 111 115 // add facet name as title attribute so that it becomes available through a tooltip … … 116 120 // add a link for removal of the facet value selection 117 121 item.add(new AjaxFallbackLink("removal") { 118 122 119 123 @Override 120 124 public void onClick(AjaxRequestTarget target) { … … 129 133 } 130 134 }); 131 135 132 136 return facetsContainer; 133 137 } … … 144 148 setResponsePage(FacetedSearchPage.class, paramsConverter.toParameters(selection)); 145 149 } 146 150 147 151 @Override 148 152 protected void onConfigure() { 149 153 super.onConfigure(); 150 154 151 155 final String queryString = getModelObject().getQuery(); 152 156 final Map<String, FacetSelection> selection = getModelObject().getSelection(); 153 157 154 158 query.setVisible(queryString != null && !queryString.isEmpty()); 155 159 facets.setVisible(selection != null && !selection.isEmpty()); … … 161 165 */ 162 166 private class SelectionConverter implements IConverter<FacetSelection> { 163 167 164 168 private final String facet; 165 166 public SelectionConverter(String facet) { 169 private final IConverter<String> valueConverter; 170 171 public SelectionConverter(String facet, IConverter<String> valueConverter) { 167 172 this.facet = facet; 168 } 169 173 this.valueConverter = valueConverter; 174 } 175 170 176 @Override 171 177 public FacetSelection convertToObject(String value, Locale locale) throws ConversionException { 172 178 throw new UnsupportedOperationException("Not supported yet."); 173 179 } 174 180 175 181 @Override 176 182 public String convertToString(FacetSelection selection, Locale locale) { 177 183 switch (selection.getSelectionType()) { 178 184 case AND: 179 return getCollectionString(selection, " and " );185 return getCollectionString(selection, " and ", locale); 180 186 case OR: 181 return getCollectionString(selection, " or " );187 return getCollectionString(selection, " or ", locale); 182 188 case NOT: 183 return "not [" + getCollectionString(selection, " or " ) + "]";189 return "not [" + getCollectionString(selection, " or ", locale) + "]"; 184 190 case NOT_EMPTY: 185 191 return getAnyValueString(); … … 187 193 return facet; 188 194 } 189 190 } 191 195 196 } 197 192 198 private String getAnyValueString() { 193 199 if (FacetConstants.FIELD_SEARCH_SERVICE.equals(facet)) { … … 196 202 return "any " + facet; 197 203 } 198 199 public String getCollectionString(FacetSelection selection, String valueSeparator ) {204 205 public String getCollectionString(FacetSelection selection, String valueSeparator, Locale locale) { 200 206 final Collection<String> value = selection.getValues(); 201 207 //TODO: include selection type … … 203 209 return ""; 204 210 } else if (value.size() == 1) { 205 return value.iterator().next();211 return getConvertedValue(value.iterator().next(), locale); 206 212 } else { 207 213 final Iterator<String> iterator = value.iterator(); 208 final StringBuilder sb = new StringBuilder( iterator.next());214 final StringBuilder sb = new StringBuilder(getConvertedValue(iterator.next(), locale)); 209 215 while (iterator.hasNext()) { 210 sb.append(valueSeparator).append( iterator.next());216 sb.append(valueSeparator).append(getConvertedValue(iterator.next(), locale)); 211 217 } 212 218 return sb.toString(); 213 219 } 214 220 } 215 221 222 private String getConvertedValue(String string, Locale locale) { 223 if (valueConverter != null) { 224 final String converted = valueConverter.convertToString(string, locale); 225 if (converted != null) { 226 return converted; 227 } 228 } 229 return string; 230 } 231 216 232 }; 217 233 }
Note: See TracChangeset
for help on using the changeset viewer.