1 package net.suberic.pooka.gui.propedit; 2 import java.util.*; 3 import net.suberic.util.gui.propedit.*; 4 import net.suberic.util.VariableBundle; 5 6 9 public class NewUserProfileWizardController extends WizardController { 10 11 14 public NewUserProfileWizardController(String sourceTemplate, WizardEditorPane wep) { 15 super(sourceTemplate, wep); 16 } 17 18 22 public void checkStateTransition(String oldState, String newState) throws PropertyValueVetoException { 23 getEditorPane().validateProperty(oldState); 24 if (newState.equals("userName")) { 25 26 String userName = getManager().getCurrentProperty("UserProfile._newValueWizard.user.from", ""); 27 PropertyEditorUI userNameEditor = getManager().getPropertyEditor("UserProfile._newValueWizard.userName.userName"); 28 29 setUniqueProperty(userNameEditor, userName, "UserProfile._newValueWizard.userName.userName"); 30 31 String smtpServerName = ""; 32 33 PropertyEditorUI smtpServerNameEditor = getManager().getPropertyEditor("UserProfile._newValueWizard.userName.smtpServerName"); 35 36 smtpServerName= getManager().getCurrentProperty("NewStoreWizard.editors.smtp.outgoingServer", "__default"); 37 if (smtpServerName.equalsIgnoreCase("__new")) { 38 smtpServerName = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.server", ""); 39 setUniqueProperty(smtpServerNameEditor, smtpServerName, "UserProfile._newValueWizard.userName.smtpServerName"); 40 } else if (smtpServerName.equalsIgnoreCase("__default")) { 41 smtpServerName = getManager().getProperty("NewStoreWizard.editors.smtp.outgoingServer.listMapping.__default.label", "< Global Default SMTP Server >"); 42 smtpServerNameEditor.setOriginalValue(smtpServerName); 43 smtpServerNameEditor.resetDefaultValue(); 44 } else { 45 smtpServerNameEditor.setOriginalValue("<" + smtpServerName + ">"); 46 smtpServerNameEditor.resetDefaultValue(); 47 } 48 } 49 } 50 51 54 public String getNextState(String currentState) { 55 int current = mStateList.indexOf(mState); 56 if (current > -1 && current < (mStateList.size() -1)) { 57 String newState = mStateList.get(current + 1); 58 return newState; 59 } else { 60 return null; 61 } 62 } 63 64 67 public String getBackState(String currentState) { 68 int current = mStateList.indexOf(currentState); 69 if (current >= 1) { 70 String newState = mStateList.get(current - 1); 71 return newState; 72 } else { 73 return null; 74 } 75 } 76 77 78 81 protected void saveProperties() throws PropertyValueVetoException { 82 Properties userProperties = createUserProperties(); 83 Properties smtpProperties = createSmtpProperties(); 84 86 addAll(userProperties); 87 addAll(smtpProperties); 88 89 String accountName = getManager().getCurrentProperty("UserProfile._newValueWizard.userName.userName", "testUserProfile"); 92 MultiEditorPane mep = (MultiEditorPane) getManager().getPropertyEditor("UserProfile"); 93 if (mep != null) { 94 mep.addNewValue(accountName); 95 } else { 96 appendProperty("UserProfile", accountName); 97 } 98 99 String defaultSmtpServer= getManager().getCurrentProperty("NewStoreWizard.editors.smtp.outgoingServer", "__default"); 100 if (defaultSmtpServer.equals("__new")) { 101 String smtpServerName = getManager().getCurrentProperty("UserProfile._newValueWizard.userName.smtpServerName", ""); 102 mep = (MultiEditorPane) getManager().getPropertyEditor("OutgoingServer"); 103 if (mep != null) { 104 mep.addNewValue(smtpServerName); 105 } else { 106 appendProperty("OutgoingServer", smtpServerName); 108 } 109 } 110 } 111 112 115 public void finishWizard() throws PropertyValueVetoException { 116 saveProperties(); 117 getEditorPane().getWizardContainer().closeWizard(); 118 } 119 120 123 public Properties createUserProperties() { 124 Properties returnValue = new Properties(); 125 126 String userName = getManager().getCurrentProperty("UserProfile._newValueWizard.userName.userName", "testUserProfile"); 127 128 String from = getManager().getCurrentProperty("UserProfile._newValueWizard.user.from", "test@example.com"); 129 String fromPersonal = getManager().getCurrentProperty("UserProfile._newValueWizard.user.fromPersonal", ""); 130 String replyTo = getManager().getCurrentProperty("UserProfile._newValueWizard.user.replyTo", ""); 131 String replyToPersonal = getManager().getCurrentProperty("UserProfile._newValueWizard.user.replyToPersonal", ""); 132 133 returnValue.setProperty("UserProfile." + userName + ".mailHeaders.From", from ); 134 returnValue.setProperty("UserProfile." + userName + ".mailHeaders.FromPersonal", fromPersonal); 135 returnValue.setProperty("UserProfile." + userName + ".mailHeaders.ReplyTo", replyTo); 136 returnValue.setProperty("UserProfile." + userName + ".mailHeaders.ReplyToPersonal", replyToPersonal); 137 138 returnValue.setProperty("UserProfile." + userName + ".mailHeaders.ReplyToPersonal", replyToPersonal); 139 140 return returnValue; 141 } 142 143 146 public Properties createSmtpProperties() { 147 Properties returnValue = new Properties(); 148 149 String userName = getManager().getCurrentProperty("UserProfile._newValueWizard.userName.userName", "testUserProfile"); 150 151 String defaultSmtpServer = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.outgoingServer", "__default"); 152 if (defaultSmtpServer.equals("__new")) { 153 String serverName = getManager().getCurrentProperty("UserProfile._newValueWizard.userName.smtpServerName", ""); 154 155 String server = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.server", ""); 156 String port = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.port", ""); 157 String authenticated = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.authenticated", ""); 158 String user = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.user", ""); 159 String password = getManager().getCurrentProperty("NewStoreWizard.editors.smtp.password", ""); 160 161 returnValue.setProperty("OutgoingServer." + serverName + ".server", server); 162 returnValue.setProperty("OutgoingServer." + serverName + ".port", port); 163 returnValue.setProperty("OutgoingServer." + serverName + ".authenticated", authenticated); 164 if (authenticated.equalsIgnoreCase("true")) { 165 166 returnValue.setProperty("OutgoingServer." + serverName + ".user", user ); 167 returnValue.setProperty("OutgoingServer." + serverName + ".password", password); 168 } 169 170 returnValue.setProperty("UserProfile." + userName + ".mailServer", serverName); 171 } else { 172 returnValue.setProperty("UserProfile." + userName + ".mailServer", defaultSmtpServer); 173 } 174 return returnValue; 175 } 176 177 181 void addAll(Properties props) { 182 Set<String > names = props.stringPropertyNames(); 183 for (String name: names) { 184 getManager().setProperty(name, props.getProperty(name)); 185 } 186 } 187 188 public void setUniqueProperty(PropertyEditorUI editor, String originalValue, String propertyName) { 189 String value = originalValue; 190 boolean success = false; 191 for (int i = 0 ; ! success && i < 10; i++) { 192 if (i != 0) { 193 value = originalValue + "_" + i; 194 } 195 try { 196 editor.setOriginalValue(value); 197 editor.resetDefaultValue(); 198 getManager().setTemporaryProperty(propertyName, value); 199 success = true; 200 } catch (PropertyValueVetoException pvve) { 201 } 203 } 204 } 205 206 209 public void appendProperty(String property, String value) { 210 List<String > current = getManager().getPropertyAsList(property, ""); 211 current.add(value); 212 getManager().setProperty(property, VariableBundle.convertToString(current)); 213 } 214 } 215 | Popular Tags |