1 package org.tigris.scarab.actions; 2 3 48 49 import java.util.ArrayList ; 50 import java.util.Collections ; 51 import java.util.Comparator ; 52 import java.util.HashMap ; 53 import java.util.List ; 54 import java.util.Map ; 55 56 import org.apache.fulcrum.parser.ParameterParser; 57 import org.apache.fulcrum.security.util.TurbineSecurityException; 58 import org.apache.turbine.RunData; 59 import org.apache.turbine.TemplateContext; 60 import org.tigris.scarab.actions.base.RequireLoginFirstAction; 61 import org.tigris.scarab.om.Attribute; 62 import org.tigris.scarab.om.AttributeManager; 63 import org.tigris.scarab.om.ScarabUser; 64 import org.tigris.scarab.tools.ScarabLocalizationTool; 65 import org.tigris.scarab.tools.ScarabRequestTool; 66 import org.tigris.scarab.util.ScarabConstants; 67 68 74 public class ConfigureIssueList extends RequireLoginFirstAction 75 { 76 public void doSave(RunData data, TemplateContext context) 77 throws Exception 78 { 79 ScarabRequestTool scarabR = getScarabRequestTool(context); 80 ScarabLocalizationTool l10n = getLocalizationTool(context); 81 82 ParameterParser params = data.getParameters(); 84 String [] ids = params.getStrings("attid"); 85 String [] orders = params.getStrings("attorder"); 86 if (ids != null) 87 { 88 List attributes = new ArrayList (ids.length); 89 final Map orderMap = new HashMap (); 90 for (int i =0; i<ids.length; i++) 91 { 92 if (!orders[i].equals("hidden")) 93 { 94 Attribute attribute = AttributeManager 95 .getInstance(new Integer (ids[i])); 96 attributes.add(attribute); 97 Integer order = new Integer (orders[i]); 98 orderMap.put(attribute, order); 99 } 100 } 101 102 if (attributes.isEmpty()) 103 { 104 scarabR.setAlertMessage(l10n.get("MustSelectAtLeastOneAttribute")); 105 setTarget(data, data.getParameters() 106 .getString(ScarabConstants.TEMPLATE, 107 "ConfigureIssueList.vm")); 108 return; 109 } 110 else if (((ScarabUser)data.getUser()).getCurrentMITList() == null) 111 { 112 scarabR.setAlertMessage(l10n.get("NoIssueTypeList")); 113 return; 114 } 115 else 116 { 117 Comparator c = new Comparator () 118 { 119 public int compare(Object o1, Object o2) 120 { 121 int order1 = ((Integer )orderMap.get(o1)).intValue(); 122 int order2 = ((Integer )orderMap.get(o2)).intValue(); 123 int result = order1 - order2; 124 if (result == 0) 125 { 126 Attribute a1 = (Attribute)o1; 127 Attribute a2 = (Attribute)o2; 128 result = a1.getName().compareTo(a2.getName()); 129 } 130 return result; 131 } 132 }; 133 Collections.sort(attributes, c); 134 try 135 { 136 ((ScarabUser)data.getUser()).updateIssueListAttributes(attributes); 137 scarabR.setConfirmMessage(l10n.get(DEFAULT_MSG)); 138 } 139 catch (TurbineSecurityException tse) 140 { 141 scarabR.setAlertMessage(l10n.get(NO_PERMISSION_MESSAGE)); 142 } 143 } 144 } 145 doCancel(data,context); 146 } 147 148 151 public void doUsedefaults(RunData data, TemplateContext context) 152 throws Exception 153 { 154 data.getParameters().add("usedefaults", "true"); 155 } 156 } 157 | Popular Tags |