updates for switching to menu edit mode and sorting options list
This commit is contained in:
parent
80adc59e7b
commit
5e89e6f4ff
4 changed files with 71 additions and 2 deletions
|
@ -2,8 +2,10 @@
|
|||
|
||||
package edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -453,6 +455,50 @@ public class SelectListGeneratorVTwo {
|
|||
log.debug("removed "+removeCount+" duplicate range individuals");
|
||||
return individuals;
|
||||
}
|
||||
|
||||
//Methods to sort the options map
|
||||
// from http://forum.java.sun.com/thread.jspa?threadID=639077&messageID=4250708
|
||||
public static Map<String,String> getSortedMap(Map<String,String> hmap){
|
||||
// first make temporary list of String arrays holding both the key and its corresponding value, so that the list can be sorted with a decent comparator
|
||||
List<String[]> objectsToSort = new ArrayList<String[]>(hmap.size());
|
||||
for (String key:hmap.keySet()) {
|
||||
String[] x = new String[2];
|
||||
x[0] = key;
|
||||
x[1] = hmap.get(key);
|
||||
objectsToSort.add(x);
|
||||
}
|
||||
Collections.sort(objectsToSort, new MapPairsComparator());
|
||||
|
||||
HashMap<String,String> map = new LinkedHashMap<String,String>(objectsToSort.size());
|
||||
for (String[] pair:objectsToSort) {
|
||||
map.put(pair[0],pair[1]);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static class MapPairsComparator implements Comparator<String[]> {
|
||||
public int compare (String[] s1, String[] s2) {
|
||||
Collator collator = Collator.getInstance();
|
||||
if (s2 == null) {
|
||||
return 1;
|
||||
} else if (s1 == null) {
|
||||
return -1;
|
||||
} else {
|
||||
if ("".equals(s1[0])) {
|
||||
return -1;
|
||||
} else if ("".equals(s2[0])) {
|
||||
return 1;
|
||||
}
|
||||
if (s2[1]==null) {
|
||||
return 1;
|
||||
} else if (s1[1] == null){
|
||||
return -1;
|
||||
} else {
|
||||
return collator.compare(s1[1],s2[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String LEFT_BLANK = "";
|
||||
}
|
||||
|
|
|
@ -306,7 +306,7 @@ public class DefaultAddMissingIndividualFormGenerator implements EditConfigurati
|
|||
|
||||
private HashMap<String, String> generateSparqlForExistingLiterals() {
|
||||
HashMap<String, String> map = new HashMap<String, String>();
|
||||
String query = StringUtils.join(getN3Prefixes(), "");
|
||||
String query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> ";
|
||||
query += "SELECT ?existingName WHERE { ?" + objectVarName + " rdfs:label ?existingName }";
|
||||
map.put("name", query);
|
||||
return map;
|
||||
|
|
|
@ -58,7 +58,12 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
|||
|
||||
try{
|
||||
WebappDaoFactory wdf = vreq.getWebappDaoFactory();
|
||||
//check some error conditions and if they exist return response values
|
||||
|
||||
if(isMenuMode(vreq)) {
|
||||
return redirectToMenuEdit(vreq);
|
||||
}
|
||||
|
||||
//check some error conditions and if they exist return response values
|
||||
//with error message
|
||||
if(isErrorCondition(vreq)){
|
||||
return doHelp(vreq, getErrorMessage(vreq));
|
||||
|
@ -114,6 +119,19 @@ public class EditRequestDispatchController extends FreemarkerHttpServlet {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean isMenuMode(VitroRequest vreq) {
|
||||
//Check if special model, in which case forward
|
||||
return(vreq.getParameter("switchToDisplayModel") != null);
|
||||
}
|
||||
|
||||
private ResponseValues redirectToMenuEdit(VitroRequest vreq) {
|
||||
String queryString = vreq.getQueryString();
|
||||
String redirectPage = vreq.getContextPath() + "/editDisplayModel?" + queryString;
|
||||
return new RedirectResponseValues(redirectPage, HttpServletResponse.SC_SEE_OTHER);
|
||||
|
||||
}
|
||||
private MultiValueEditSubmission getMultiValueSubmission(VitroRequest vreq, EditConfigurationVTwo editConfig) {
|
||||
return EditSubmissionUtils.getEditSubmissionFromSession(vreq.getSession(), editConfig);
|
||||
}
|
||||
|
|
|
@ -109,6 +109,11 @@ public class EditConfigurationTemplateModel extends BaseTemplateModel {
|
|||
|| field.getOptionsType() == null ){
|
||||
continue;
|
||||
}
|
||||
Map<String, String> optionsMap = SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf);
|
||||
//Sort options map if not hardcoded literals
|
||||
if(field.getOptionsType()!=FieldVTwo.OptionsType.HARDCODED_LITERALS) {
|
||||
optionsMap = SelectListGeneratorVTwo.getSortedMap(optionsMap);
|
||||
}
|
||||
pageData.put(fieldName, SelectListGeneratorVTwo.getOptions(editConfig, fieldName, wdf));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue