KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > suberic > pooka > gui > propedit > NewOutgoingServerWizardController


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 /**
7  * The controller class for the NewOutgoingServerWizard.
8  */

9 public class NewOutgoingServerWizardController extends WizardController {
10
11   /**
12    * Creates a NewOutgoingServerWizardController.
13    */

14   public NewOutgoingServerWizardController(String JavaDoc sourceTemplate, WizardEditorPane wep) {
15     super(sourceTemplate, wep);
16   }
17
18   /**
19    * Checks the state transition to make sure that we can move from
20    * state to state.
21    */

22   public void checkStateTransition(String JavaDoc oldState, String JavaDoc newState) throws PropertyValueVetoException {
23     getEditorPane().validateProperty(oldState);
24     if (newState.equals("name")) {
25
26       String JavaDoc smtpServerName = "";
27
28       // set the smtp servername
29
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   /**
37    * Gets the next state.
38    */

39   /*
40     public String getNextState(String currentState) {
41     int current = mStateList.indexOf(mState);
42     if (current > -1 && current < (mStateList.size() -1)) {
43     String newState = mStateList.get(current + 1);
44     return newState;
45     } else {
46     return null;
47     }
48     }
49
50   */

51   /**
52    * Gets the state that should be displayed next from a back request.
53    */

54   /*
55     public String getBackState(String currentState) {
56     int current = mStateList.indexOf(currentState);
57     if (current >= 1) {
58     String newState = mStateList.get(current - 1);
59     return newState;
60     } else {
61     return null;
62     }
63     }
64   */

65
66
67   /**
68    * Saves all of the properties for this wizard.
69    */

70   protected void saveProperties() throws PropertyValueVetoException {
71     Properties smtpProperties = createSmtpProperties();
72     //getManager().clearValues();
73

74     addAll(smtpProperties);
75
76     String JavaDoc 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       // if there's no editor, then set the value itself.
82
appendProperty("OutgoingServer", smtpServerName);
83     }
84   }
85
86   /**
87    * Finsihes the wizard.
88    */

89   public void finishWizard() throws PropertyValueVetoException {
90     saveProperties();
91     getEditorPane().getWizardContainer().closeWizard();
92   }
93
94   /**
95    * Creates the smtpProperties from the wizard values.
96    */

97   public Properties createSmtpProperties() {
98     Properties returnValue = new Properties();
99
100     String JavaDoc serverName = getManager().getCurrentProperty("OutgoingServer._newValueWizard.name.smtpServerName", "");
101
102     String JavaDoc server = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.server", "");
103     String JavaDoc port = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.port", "");
104     String JavaDoc authenticated = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.authenticated", "");
105     String JavaDoc user = getManager().getCurrentProperty("OutgoingServer._newValueWizard.serverInfo.user", "");
106     String JavaDoc 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   /**
121    * Adds all of the values from the given Properties to the
122    * PropertyEditorManager.
123    */

124   void addAll(Properties props) {
125     Set<String JavaDoc> names = props.stringPropertyNames();
126     for (String JavaDoc name: names) {
127       getManager().setProperty(name, props.getProperty(name));
128     }
129   }
130
131   public void setUniqueProperty(PropertyEditorUI editor, String JavaDoc originalValue, String JavaDoc propertyName) {
132     String JavaDoc 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         // on an exception, just start over.
145
}
146     }
147   }
148
149   /**
150    * Appends the given value to the property.
151    */

152   public void appendProperty(String JavaDoc property, String JavaDoc value) {
153     List<String JavaDoc> current = getManager().getPropertyAsList(property, "");
154     current.add(value);
155     getManager().setProperty(property, VariableBundle.convertToString(current));
156   }
157 }
158
Popular Tags