1 19 20 package ca.mcgill.sable.soot.launching; 21 22 import java.util.*; 23 24 import org.eclipse.jface.dialogs.IDialogSettings; 25 26 import ca.mcgill.sable.soot.*; 27 28 32 public class SavedConfigManager { 33 34 37 public SavedConfigManager() { 38 super(); 39 } 40 41 public void handleDeletes() { 42 if (getDeleteList() != null) { 43 Iterator it = getDeleteList().iterator(); 44 while (it.hasNext()) { 45 String name = (String )it.next(); 46 remove(name); 47 } 48 } 49 } 50 51 private void remove(String name) { 52 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 53 int count = 0; 54 try { 55 count = settings.getInt("config_count"); 56 } 57 catch (NumberFormatException e){ 58 } 59 String [] pointers = new String [count]; 60 for (int i = 1; i <= count; i++) { 61 pointers[i-1] = settings.get("soot_run_config_"+i); 62 } 63 64 int i = 1; 65 int j = 0; 66 while (j < count) { 67 if (!pointers[j].equals(name)) { 68 settings.put("soot_run_config_"+i, pointers[j]); 69 i++; 70 } 71 j++; 72 } 73 74 settings.put("soot_run_config_"+count, (String )null); 75 count--; 76 if (count < 0) { 77 count = 0; 78 } 79 settings.put("config_count", count); 80 settings.put(name, (String )null); 81 82 } 83 84 public void handleEdits() { 85 if (getEditMap() != null) { 86 Iterator it = getEditMap().keySet().iterator(); 87 while (it.hasNext()) { 88 String name = (String )it.next(); 89 if (alreadyInList(name)) { 90 update(name, (ArrayList)getEditMap().get(name)); 91 } 92 else { 93 add(name, (ArrayList)getEditMap().get(name)); 94 } 95 } 96 } 97 } 98 99 100 private boolean alreadyInList(String name) { 101 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 102 int count = 0; 103 try { 104 count = settings.getInt("config_count"); 105 } 106 catch (NumberFormatException e){ 107 } 108 for (int i = 1; i <= count; i++){ 109 if (settings.get("soot_run_config_"+i).equals(name)){ 110 return true; 111 } 112 } 113 return false; 114 } 115 116 private void update(String name, ArrayList val){ 118 String [] temp = new String [val.size()]; 119 val.toArray(temp); 120 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 121 122 settings.put(name, temp); 123 } 124 125 private void update(String name, String [] val){ 127 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 128 129 settings.put(name, val); 130 } 131 132 private void update(String name, String val) { 134 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 135 136 if (val != null) { 137 settings.put(name, val); 138 } 139 else { 140 settings.put(name, "default"); 141 } 142 } 143 144 private void add(String name, ArrayList val){ 146 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 147 int count = 0; 148 try { 149 count = settings.getInt("config_count"); 150 } 151 catch(NumberFormatException e) { 152 } 153 count++; 154 settings.put("config_count", count); 155 settings.put("soot_run_config_"+count, name); 156 update(name, val); 157 } 158 159 private void add(String name, String val) { 161 IDialogSettings settings = SootPlugin.getDefault().getDialogSettings(); 162 int count = 0; 163 try { 164 count = settings.getInt("config_count"); 165 } 166 catch(NumberFormatException e) { 167 } 168 count++; 169 settings.put("config_count", count); 170 settings.put("soot_run_config_"+count, name); 171 update(name, val); 172 } 173 174 private HashMap editMap; 175 private ArrayList deleteList; 176 177 178 182 public ArrayList getDeleteList() { 183 return deleteList; 184 } 185 186 190 public HashMap getEditMap() { 191 return editMap; 192 } 193 194 198 public void setDeleteList(ArrayList deleteList) { 199 this.deleteList = deleteList; 200 } 201 202 206 public void setEditMap(HashMap editMap) { 207 this.editMap = editMap; 208 } 209 210 } 211 | Popular Tags |