@SuppressWarnings("unchecked") private void deepSort(DefaultMutableTreeNode parent, TreeObjectSortBy sortBy, SortOrder order) { Enumeration<DefaultMutableTreeNode> treeObjectNodes = parent.children(); List<DefaultMutableTreeNode> treeNodes = EnumerationUtils .toList(treeObjectNodes); BeanToPropertyValueTransformer sortProperty = getSortByTransformer(sortBy); Comparator<DefaultMutableTreeNode> comparator = new TransformingComparator( sortProperty); if (SortOrder.DESC.equals(order)) { comparator = new ReverseComparator<DefaultMutableTreeNode>( comparator); } Collections.sort(treeNodes, comparator); parent.removeAllChildren(); for (DefaultMutableTreeNode childNode : treeNodes) { parent.add(childNode); deepSort(childNode, sortBy, order); } }
private BeanToPropertyValueTransformer getSortByTransformer( TreeObjectSortBy sortBy) { String sortProperty = null; switch (sortBy) { case NAME: sortProperty = "userObject.path.pathname"; break; case SIZE: sortProperty = "userObject.size"; break; default: sortProperty = "userObject"; break; } BeanToPropertyValueTransformer beanValueTransformer = new BeanToPropertyValueTransformer( sortProperty); return beanValueTransformer; }
private void doSliderRange(JspWriter out) throws JspException, IOException { List<Product> products = ((SearchFilterTag) getParent()).getProducts(); Money min = null; Money max = null; BeanToPropertyValueTransformer valueTransformer = new BeanToPropertyValueTransformer(property, true); for (Product product : products) { Money propertyObject = (Money) valueTransformer.transform(product); if (propertyObject == null) { min = new Money(0D); max = new Money(0D); } else { min = propertyObject.min(min); max = propertyObject.max(max); } } String propertyCss = property.replaceAll("[.\\[\\]]", "_"); out.println("<div id='searchFilter-"+propertyCss+"'></div>"); out.println("Range:"); out.println("<input type=\"text\" id=\"min-" + propertyCss + "\" name='min-" + property + "' value='"+min.getCurrency().getSymbol()+min.getAmount().toPlainString()+"'/> - "); out.println("<input type=\"text\" id=\"max-" + propertyCss + "\" name='max-" + property + "' value='"+max.getCurrency().getSymbol()+max.getAmount().toPlainString()+"'/> <br/>"); out.println(" <script type=\"text/javascript\">\r\n" + " $(function() {\r\n" + " $(\"#searchFilter-" + propertyCss + "\").slider({\r\n" + " range: true,\r\n" + " min: "+ min.getAmount().toPlainString() +", max: "+ max.getAmount().toPlainString() + "," + " values: ["+ min.getAmount().toPlainString() +","+ max.getAmount().toPlainString() +"]," + " slide: function(event, ui) {\r\n" + " $(\"#min-" + propertyCss + "\").val('" + min.getCurrency().getSymbol() + "' + ui.values[0] );\r\n" + " $(\"#max-" + propertyCss + "\").val('" + max.getCurrency().getSymbol() + "' + ui.values[1]);\r\n" + " }\r\n" + " });\r\n" + " });\r\n" + " $('#searchFilter-"+propertyCss+"').bind('slidechange', updateSearchFilterResults); \r\n" + " </script>"); }
/** * JAVADOC Method Level Comments * * @param subjectType * JAVADOC. * @param search * JAVADOC. * @param projections * JAVADOC. * @see org.cucina.meringue.search.SearchBeanFactory#addProjections(java.lang * .String, org.cucina.meringue.query.SearchBean, java.lang.String[]) */ @SuppressWarnings("unchecked") @Override public void addProjections(String subjectType, SearchBean search, Collection<String> projections, Class<?>... projectionGroup) { Assert.notNull(search, "search is required!"); Assert.hasText(subjectType, "subjectType is required!"); Assert.notEmpty(projections, "projections is required!"); addProjections(subjectType, search, projectionGroup); ArrayList<Projection> orderedProjections = new ArrayList<Projection>(); for (String requestedProjection : projections) { for (Iterator<Projection> iter = search.getProjections().iterator(); iter.hasNext();) { Projection projection = iter.next(); if (requestedProjection.equals(projection.getAlias())) { orderedProjections.add(projection); iter.remove(); break; } } } search.setProjections(orderedProjections); Collection<String> unresolved = CollectionUtils.subtract(projections, CollectionUtils.collect(search.getProjections(), new BeanToPropertyValueTransformer("alias"))); if (LOG.isDebugEnabled()) { LOG.debug("The following requested projections " + unresolved + " could not be found"); } Assert.notEmpty(search.getProjections(), "No projections could be added!"); }