NIHVIVO-1210 : Code change for adding sorted properties in dropdown for sub/superproperty links.
This commit is contained in:
parent
97ef829204
commit
d0c73a4d23
1 changed files with 50 additions and 3 deletions
|
@ -2,9 +2,16 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.controller.edit;
|
||||
|
||||
import java.text.CollationKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import javax.servlet.RequestDispatcher;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -13,8 +20,11 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.text.Collator;
|
||||
|
||||
import edu.cornell.mannlib.vedit.beans.EditProcessObject;
|
||||
import edu.cornell.mannlib.vedit.beans.FormObject;
|
||||
import edu.cornell.mannlib.vedit.beans.Option;
|
||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||
import edu.cornell.mannlib.vedit.util.FormUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Classes2Classes;
|
||||
|
@ -66,9 +76,16 @@ public class Properties2PropertiesRetryController extends BaseEditController {
|
|||
String superpropertyURIstr = request.getParameter("SuperpropertyURI");
|
||||
String subpropertyURIstr = request.getParameter("SubpropertyURI");
|
||||
|
||||
|
||||
HashMap<String,Option> hashMap = new HashMap<String,Option>();
|
||||
List<Option> optionList = FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",superpropertyURIstr,null);
|
||||
List<Option> superPropertyOptions = getSortedList(hashMap,optionList);
|
||||
optionList = FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",subpropertyURIstr,null);
|
||||
List<Option> subPropertyOptions = getSortedList(hashMap, optionList);
|
||||
|
||||
HashMap hash = new HashMap();
|
||||
hash.put("SuperpropertyURI", FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",superpropertyURIstr,null));
|
||||
hash.put("SubpropertyURI", FormUtils.makeOptionListFromBeans(propList,"URI","LocalNameWithPrefix",subpropertyURIstr,null));
|
||||
hash.put("SuperpropertyURI", superPropertyOptions);
|
||||
hash.put("SubpropertyURI", subPropertyOptions);
|
||||
|
||||
FormObject foo = new FormObject();
|
||||
foo.setOptionLists(hash);
|
||||
|
@ -100,5 +117,35 @@ public class Properties2PropertiesRetryController extends BaseEditController {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public List<Option> getSortedList(HashMap<String,Option> hashMap, List<Option> optionList){
|
||||
|
||||
class ListComparator implements Comparator<String>{
|
||||
@Override
|
||||
public int compare(String str1, String str2) {
|
||||
// TODO Auto-generated method stub
|
||||
Collator collator = Collator.getInstance();
|
||||
return collator.compare(str1, str2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List<String> bodyVal = new ArrayList<String>();
|
||||
List<Option> options = new ArrayList<Option>();
|
||||
Iterator<Option> itr = optionList.iterator();
|
||||
while(itr.hasNext()){
|
||||
Option option = itr.next();
|
||||
hashMap.put(option.getBody(),option);
|
||||
bodyVal.add(option.getBody());
|
||||
}
|
||||
|
||||
|
||||
Collections.sort(bodyVal, new ListComparator());
|
||||
ListIterator<String> itrStr = bodyVal.listIterator();
|
||||
while(itrStr.hasNext()){
|
||||
options.add(hashMap.get(itrStr.next()));
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue