/** * Sorts the items on their ID: the option with the lower ID (case insensitive String comparison) will be placed * before the other one. * * @param o1 the first item to be compared. * @param o2 the second item to be compared. * @return a negative integer, zero, or a positive integer as the first argument is less than, equal to, or * greater than the second. */ public int compare(ListItem o1, ListItem o2) { return BASE_COMPARATOR.compare(o1.getId(), o2.getId()); } });
protected void addToTreeList(List<ListItem> treelist, Map<String, List<ListItem>> treemap, Map<String, ListItem> map, String parent, XWikiContext context) { List<ListItem> list = treemap.get(parent); if (list != null) { for (ListItem item : list) { ListItem item2 = new ListItem(item.getId(), getDisplayValue(item.getId(), "", map, context), item.getParent()); treelist.add(item2); addToTreeList(treelist, treemap, map, item.getId(), context); } } }
@Override public List<String> getList(XWikiContext context) { List<ListItem> dblist = getDBList(context); String sort = getSort(); if ("id".equals(sort)) { Collections.sort(dblist, ListItem.ID_COMPARATOR); } else if ("value".equals(sort)) { Collections.sort(dblist, ListItem.VALUE_COMPARATOR); } List<String> result = new ArrayList<String>(dblist.size()); for (ListItem value : dblist) { result.add(value.getId()); } return result; }
@Override public Map<String, ListItem> getMap(XWikiContext context) { List<ListItem> list = getDBList(context); Map<String, ListItem> result = new HashMap<String, ListItem>(); if ((list == null) || (list.size() == 0)) { return result; } for (int i = 0; i < list.size(); i++) { Object res = list.get(i); if (res instanceof String) { result.put((String) res, new ListItem((String) res)); } else { ListItem item = (ListItem) res; result.put(item.getId(), item); } } return result; }
private List<ListItem> getItemPath(String item, List<ListItem> treeList, ArrayList<ListItem> resList) { for (ListItem tmpItem : treeList) { if (item.equals(tmpItem.getId())) { if (tmpItem.getParent().length() > 0) { getItemPath(tmpItem.getParent(), treeList, resList); } resList.add(tmpItem); return resList; } } return null; }
protected void addToSelect(select select, List<String> selectlist, Map<String, ListItem> map, Map<String, List<ListItem>> treemap, String parent, String level, XWikiContext context) { List<ListItem> list = treemap.get(parent); if (list != null) { for (ListItem item : list) { String display = level + getDisplayValue(item.getId(), "", map, context); option option = new option(display, item.getId()); option.addElement(display); if (selectlist.contains(item.getId())) { option.setSelected(true); } select.addElement(option); addToSelect(select, selectlist, map, treemap, item.getId(), level + " ", context); } } }
/** * {@inheritDoc} * * @see Object#toString() */ @Override public String toString() { return "[" + getId() + ", " + getValue() + ", " + getParent() + "]"; } }
@Override public List<String> getList(XWikiContext context) { String sort = getSort(); if (StringUtils.isEmpty(sort) || "none".equals(sort)) { return getListFromString(getValues()); } Map<String, ListItem> valuesMap = getMap(context); List<ListItem> values = new ArrayList<ListItem>(valuesMap.size()); values.addAll(valuesMap.values()); if ("id".equals(sort)) { Collections.sort(values, ListItem.ID_COMPARATOR); } else if ("value".equals(sort)) { Collections.sort(values, ListItem.VALUE_COMPARATOR); } List<String> result = new ArrayList<String>(values.size()); for (ListItem value : values) { result.add(value.getId()); } return result; }
private void indexStaticList(Document luceneDoc, BaseObject baseObject, StaticListClass prop, String propertyName, XWikiContext context) { Map<String, ListItem> possibleValues = prop.getMap(context); String fieldFullName = baseObject.getClassName() + "." + propertyName; for (String value : (List<String>) baseObject.getListValue(propertyName)) { ListItem item = possibleValues.get(value); if (item != null) { // We index the key of the list String fieldName = fieldFullName + ".key"; addFieldToDocument(fieldName, item.getId(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); // We index the value fieldName = fieldFullName + ".value"; addFieldToDocument(fieldName, item.getValue(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); // If the key and value are not the same, we index both // The key is always indexed outside the if block, so here we just index the value if (!item.getId().equals(item.getValue())) { addFieldToDocument(fieldFullName, item.getValue(), Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); } } addFieldToDocument(fieldFullName, value, Field.Store.YES, Field.Index.ANALYZED, OBJECT_PROPERTY_BOOST, luceneDoc); } }