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 NewOutgoingServerWizardController extends WizardController { 10 11 14 public NewOutgoingServerWizardController(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("name")) { 25 26 String smtpServerName = ""; 27 28 PropertyEditorUI smtpServerNameEditor = getManager().getPropertyEditor("OutgoingServer._newValueWizard.name.smtpServerName"); 30 31 smtpServerName = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.server", ""); 32 setUniqueProperty(smtpServerNameEditor, smtpServerName, "OutgoingServer._newValueWizard.name.smtpServerName"); 33 } 34 } 35 36 39 51 54 65 66 67 70 protected void saveProperties() throws PropertyValueVetoException { 71 Properties smtpProperties = createSmtpProperties(); 72 74 addAll(smtpProperties); 75 76 String smtpServerName = getManager().getCurrentProperty("OutgoingServer._newValueWizard.name.smtpServerName", ""); 77 MultiEditorPane mep = (MultiEditorPane) getManager().getPropertyEditor("OutgoingServer"); 78 if (mep != null) { 79 mep.addNewValue(smtpServerName); 80 } else { 81 appendProperty("OutgoingServer", smtpServerName); 83 } 84 } 85 86 89 public void finishWizard() throws PropertyValueVetoException { 90 saveProperties(); 91 getEditorPane().getWizardContainer().closeWizard(); 92 } 93 94 97 public Properties createSmtpProperties() { 98 Properties returnValue = new Properties(); 99 100 String serverName = getManager().getCurrentProperty("OutgoingServer._newValueWizard.name.smtpServerName", ""); 101 102 String server = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.server", ""); 103 String port = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.port", ""); 104 String authenticated = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.authenticated", ""); 105 String user = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.user", ""); 106 String password = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.password", ""); 107 108 returnValue.setProperty("OutgoingServer." + serverName + ".server", server); 109 returnValue.setProperty("OutgoingServer." + serverName + ".port", port); 110 returnValue.setProperty("OutgoingServer." + serverName + ".authenticated", authenticated); 111 if (authenticated.equalsIgnoreCase("true")) { 112 113 returnValue.setProperty("OutgoingServer." + serverName + ".user", user ); 114 returnValue.setProperty("OutgoingServer." + serverName + ".password", password); 115 } 116 117 return returnValue; 118 } 119 120 124 void addAll(Properties props) { 125 Set<String > names = props.stringPropertyNames(); 126 for (String name: names) { 127 getManager().setProperty(name, props.getProperty(name)); 128 } 129 } 130 131 public void setUniqueProperty(PropertyEditorUI editor, String originalValue, String propertyName) { 132 String value = originalValue; 133 boolean success = false; 134 for (int i = 0 ; ! success && i < 10; i++) { 135 if (i != 0) { 136 value = originalValue + "_" + i; 137 } 138 try { 139 editor.setOriginalValue(value); 140 editor.resetDefaultValue(); 141 getManager().setTemporaryProperty(propertyName, value); 142 success = true; 143 } catch (PropertyValueVetoException pvve) { 144 } 146 } 147 } 148 149 152 public void appendProperty(String property, String value) { 153 List<String > current = getManager().getPropertyAsList(property, ""); 154 current.add(value); 155 getManager().setProperty(property, VariableBundle.convertToString(current)); 156 } 157 } 158 | Popular Tags |