1 package jimm.datavision.gui.cmd; 2 import jimm.datavision.Parameter; 3 import jimm.util.I18N; 4 import java.util.List ; 5 import java.util.ArrayList ; 6 import java.util.Iterator ; 7 8 14 public class ParamEditCommand extends CommandAdapter { 15 16 Parameter param; 17 String newName; 18 String newQuestion; 19 int newType; 20 int newArity; 21 List newDefaultValues; 22 String oldName; 23 String oldQuestion; 24 int oldType; 25 int oldArity; 26 List oldDefaultValues; 27 28 42 public ParamEditCommand(Parameter param, String name, String question, 43 int type, int arity, List defaultValues) 44 { 45 super(I18N.get("ParamEditCommand.name")); 46 47 this.param = param; 48 newName = name; 49 newQuestion = question; 50 newType = type; 51 newArity = arity; 52 newDefaultValues = defaultValues; 53 54 oldName = param.getName(); 55 oldQuestion = param.getQuestion(); 56 oldType = param.getType(); 57 oldArity = param.getArity(); 58 oldDefaultValues = new ArrayList (); 59 for (Iterator iter = param.defaultValues(); iter.hasNext(); ) 60 oldDefaultValues.add(iter.next()); 61 } 62 63 public void perform() { 64 editParam(newName, newQuestion, newType, newArity, newDefaultValues); 65 } 66 67 public void undo() { 68 editParam(oldName, oldQuestion, oldType, oldArity, oldDefaultValues); 69 } 70 71 protected void editParam(String name, String question, int type, int arity, 72 List defaultValues) 73 { 74 param.setName(name); 75 param.setQuestion(question); 76 param.setType(type); 77 param.setArity(arity); 78 79 param.removeDefaultValues(); 80 switch (arity) { 81 case Parameter.ARITY_ONE: 82 if (type != Parameter.TYPE_DATE) 84 param.addDefaultValue(defaultValues.get(0)); 85 break; 86 case Parameter.ARITY_RANGE: 87 if (type != Parameter.TYPE_DATE) { 89 param.addDefaultValue(defaultValues.get(0)); 90 param.addDefaultValue(defaultValues.get(1)); 91 } 92 break; 93 case Parameter.ARITY_LIST_SINGLE: 94 case Parameter.ARITY_LIST_MULTIPLE: 95 for (Iterator iter = defaultValues.iterator(); iter.hasNext(); ) 96 param.addDefaultValue(iter.next()); 97 break; 98 } 99 } 100 101 } 102 | Popular Tags |