CustomizableObjectList

FilterControls werden nicht mehr ausgegeben, wenn keine Filter definiert sind.

git-svn-id: https://svn.libreccm.org/ccm/trunk@2324 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2013-09-25 07:37:46 +00:00
parent ded554211d
commit e209bd4b5e
1 changed files with 68 additions and 65 deletions

View File

@ -14,19 +14,20 @@ import org.apache.log4j.Logger;
/** /**
* <p> An object list variant which can be filtered and sorted by the visitor of * <p> An object list variant which can be filtered and sorted by the visitor of
* the website. The available filters and sort options are added in a JSP * the website. The available filters and sort options are added in a JSP
* template. There are three kinds of filters yet: </p> <dl> <dt><code>TextFilter</code></dt> * template. There are three kinds of filters yet: </p> <dl>
* <dd>This filter filters the object list using a user provided string, which * <dt><code>TextFilter</code></dt> <dd>This filter filters the object list
* is put into the * using a user provided string, which is put into the
* <code>WHERE</code> clause with * <code>WHERE</code> clause with
* <code>LIKE</code> operator. You might use this filter to allow the visitor to * <code>LIKE</code> operator. You might use this filter to allow the visitor to
* filter an object list for items with a specific name.</dd> <dt><code>SelectFilter</code></dt> * filter an object list for items with a specific name.</dd>
* <dd>This filter traverses through the objects displayed by the list and * <dt><code>SelectFilter</code></dt> <dd>This filter traverses through the
* determines all distinct values of a property. The visitor can choose one of * objects displayed by the list and determines all distinct values of a
* this values, and the displayed list will only contain items which where the * property. The visitor can choose one of this values, and the displayed list
* property has the selected value.</dd> <dt><code>CompareFilter</code></dt> * will only contain items which where the property has the selected value.</dd>
* <dd>This filter also provides selectable options. But these options can be * <dt><code>CompareFilter</code></dt> <dd>This filter also provides selectable
* configured by the developer in the template.</dd> </dl> <p> If there is more * options. But these options can be configured by the developer in the
* than one filter, the values of all filters are combined using * template.</dd> </dl> <p> If there is more than one filter, the values of all
* filters are combined using
* <code>AND</code>. </p> <p> This object list class was developed for * <code>AND</code>. </p> <p> This object list class was developed for
* displaying list of items from the Sci modules (SciPublications and * displaying list of items from the Sci modules (SciPublications and
* SciOrganization). For example, we use this list to provide lists of * SciOrganization). For example, we use this list to provide lists of
@ -89,8 +90,7 @@ public class CustomizableObjectList extends ComplexObjectList {
* *
*/ */
private final Map<String, Filter> filters = private final Map<String, Filter> filters =
new LinkedHashMap<String, Filter>(); new LinkedHashMap<String, Filter>();
//private CategoryFilter categoryFilter; //private CategoryFilter categoryFilter;
/** /**
* The available sort fields. We use an {@link LinkedHashMap} here to * The available sort fields. We use an {@link LinkedHashMap} here to
@ -98,7 +98,7 @@ public class CustomizableObjectList extends ComplexObjectList {
* *
*/ */
private final Map<String, String> sortFields = private final Map<String, String> sortFields =
new LinkedHashMap<String, String>(); new LinkedHashMap<String, String>();
/** /**
* Adds a new text filter to the list. * Adds a new text filter to the list.
@ -122,25 +122,27 @@ public class CustomizableObjectList extends ComplexObjectList {
* @param allOption Add an <em>all</em> option to the filter. * @param allOption Add an <em>all</em> option to the filter.
* @param allOptionIsDefault Is the all option the default? * @param allOptionIsDefault Is the all option the default?
* @param propertyIsNumeric Is the property to filter numeric? * @param propertyIsNumeric Is the property to filter numeric?
* @return The new filter. Options can be added to the filter by calling the {@link CompareFilter#addOption(java.lang.String, java.lang.String)} * @return The new filter. Options can be added to the filter by calling the
* or the {@link CompareFilter#addOption(java.lang.String, com.arsdigita.navigation.ui.object.CompareFilter.Operators, java.lang.String)} * {@link CompareFilter#addOption(java.lang.String, java.lang.String)} or
* the
* {@link CompareFilter#addOption(java.lang.String, com.arsdigita.navigation.ui.object.CompareFilter.Operators, java.lang.String)}
* method. * method.
* @see CompareFilter#CompareFilter(java.lang.String, java.lang.String, * @see CompareFilter#CompareFilter(java.lang.String, java.lang.String,
* boolean, boolean, boolean) * boolean, boolean, boolean)
* *
*/ */
public CompareFilter addCompareFilter(final String property, public CompareFilter addCompareFilter(final String property,
final String label, final String label,
final boolean allOption, final boolean allOption,
final boolean allOptionIsDefault, final boolean allOptionIsDefault,
final boolean propertyIsNumeric) { final boolean propertyIsNumeric) {
CompareFilter filter; CompareFilter filter;
filter = new CompareFilter(property, filter = new CompareFilter(property,
label, label,
allOption, allOption,
allOptionIsDefault, allOptionIsDefault,
propertyIsNumeric); propertyIsNumeric);
filters.put(label, filter); filters.put(label, filter);
return filter; return filter;
@ -160,30 +162,29 @@ public class CustomizableObjectList extends ComplexObjectList {
* boolean, boolean, boolean) * boolean, boolean, boolean)
*/ */
public void addSelectFilter(final String property, public void addSelectFilter(final String property,
final String label, final String label,
final boolean reverseOptions, final boolean reverseOptions,
final boolean allOption, final boolean allOption,
final boolean allOptionIsDefault, final boolean allOptionIsDefault,
final boolean propertyIsNumeric) { final boolean propertyIsNumeric) {
SelectFilter filter; SelectFilter filter;
filter = new SelectFilter(property, filter = new SelectFilter(property,
label, label,
this, this,
reverseOptions, reverseOptions,
allOption, allOption,
allOptionIsDefault, allOptionIsDefault,
propertyIsNumeric); propertyIsNumeric);
filters.put(label, filter); filters.put(label, filter);
} }
// public CategoryFilter addCategoryFilter(final String label, // public CategoryFilter addCategoryFilter(final String label,
// final String rootCategory) { // final String rootCategory) {
// categoryFilter = CategoryFilter.createCategoryFilter(label, rootCategory); // categoryFilter = CategoryFilter.createCategoryFilter(label, rootCategory);
// //
// return categoryFilter; // return categoryFilter;
// } // }
/** /**
* Add a sort field option. * Add a sort field option.
* *
@ -220,7 +221,7 @@ public class CustomizableObjectList extends ComplexObjectList {
*/ */
@Override @Override
protected DataCollection getObjects(final HttpServletRequest request, protected DataCollection getObjects(final HttpServletRequest request,
final HttpServletResponse response) { final HttpServletResponse response) {
//Set filters (using the SQL) //Set filters (using the SQL)
// final StringBuilder sqlFilters = new StringBuilder(); // final StringBuilder sqlFilters = new StringBuilder();
// for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) { // for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) {
@ -239,14 +240,14 @@ public class CustomizableObjectList extends ComplexObjectList {
// if (sqlFilters.length() > 0) { // if (sqlFilters.length() > 0) {
// setSQLFilter(sqlFilters.toString()); // setSQLFilter(sqlFilters.toString());
// } // }
final String filterSql = getFilterSql(); final String filterSql = getFilterSql();
if (filterSql.length() > 0) { if (filterSql.length() > 0) {
setSQLFilter(filterSql); setSQLFilter(filterSql);
} }
final DataCollection objects = super.getObjects(request, response); final DataCollection objects = super.getObjects(request, response);
// if ((objects != null) && (categoryFilter != null)) { // if ((objects != null) && (categoryFilter != null)) {
// categoryFilter.applyFilter(objects); // categoryFilter.applyFilter(objects);
// } // }
@ -258,7 +259,7 @@ public class CustomizableObjectList extends ComplexObjectList {
final StringBuilder sqlFilters = new StringBuilder(); final StringBuilder sqlFilters = new StringBuilder();
for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) { for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) {
if ((filterEntry.getValue().getFilter() == null) if ((filterEntry.getValue().getFilter() == null)
|| (filterEntry.getValue().getFilter().isEmpty())) { || (filterEntry.getValue().getFilter().isEmpty())) {
continue; continue;
} }
@ -290,7 +291,7 @@ public class CustomizableObjectList extends ComplexObjectList {
*/ */
@Override @Override
public Element generateXML(final HttpServletRequest request, public Element generateXML(final HttpServletRequest request,
final HttpServletResponse response) { final HttpServletResponse response) {
//Some stuff for the list (copied from ComplexObjectList) //Some stuff for the list (copied from ComplexObjectList)
final Element content = Navigation.newElement("customizableObjectList"); final Element content = Navigation.newElement("customizableObjectList");
@ -334,31 +335,34 @@ public class CustomizableObjectList extends ComplexObjectList {
// } // }
// } // }
final Element controls = content.newChildElement("filterControls"); if (!filters.isEmpty()) {
controls.addAttribute("customName", m_customName);
final Element filterElems = controls.newChildElement("filters"); final Element controls = content.newChildElement("filterControls");
for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) { controls.addAttribute("customName", m_customName);
filterElems.addContent(filterEntry.getValue().getXml());
}
// if (categoryFilter != null) {
// filterElems.addContent(categoryFilter.getXml());
// }
if (!sortFields.isEmpty()) { final Element filterElems = controls.newChildElement("filters");
//Look for a sort parameter. If one is found, use one to sort the data for (Map.Entry<String, Filter> filterEntry : filters.entrySet()) {
//collection (if it is a valid value). If no sort parameter is found, filterElems.addContent(filterEntry.getValue().getXml());
//use the first sort field as default.
String sortByKey = request.getParameter("sort");
if (!sortFields.containsKey(sortByKey)) {
sortByKey = new ArrayList<String>(sortFields.keySet()).get(0);
} }
// if (categoryFilter != null) {
// filterElems.addContent(categoryFilter.getXml());
// }
final Element sortFieldElems = controls.newChildElement("sortFields"); if (!sortFields.isEmpty()) {
sortFieldElems.addAttribute("sortBy", sortByKey); //Look for a sort parameter. If one is found, use one to sort the data
for (Map.Entry<String, String> sortField : sortFields.entrySet()) { //collection (if it is a valid value). If no sort parameter is found,
final Element sortFieldElem = sortFieldElems.newChildElement("sortField"); //use the first sort field as default.
sortFieldElem.addAttribute("label", sortField.getKey()); String sortByKey = request.getParameter("sort");
if (!sortFields.containsKey(sortByKey)) {
sortByKey = new ArrayList<String>(sortFields.keySet()).get(0);
}
final Element sortFieldElems = controls.newChildElement("sortFields");
sortFieldElems.addAttribute("sortBy", sortByKey);
for (Map.Entry<String, String> sortField : sortFields.entrySet()) {
final Element sortFieldElem = sortFieldElems.newChildElement("sortField");
sortFieldElem.addAttribute("label", sortField.getKey());
}
} }
} }
@ -367,5 +371,4 @@ public class CustomizableObjectList extends ComplexObjectList {
return content; return content;
} }
} }