1 package org.argosfields.wizard;
2
3 import org.argosfields.resource.ResourceManager;
4 import org.argosfields.persistence.Account;
5 import org.eclipse.jface.preference.IPreferenceStore;
6 import org.eclipse.jface.preference.JFacePreferences;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.jface.wizard.WizardPage;
9 import org.eclipse.swt.SWT;
10 import org.eclipse.swt.events.ModifyEvent;
11 import org.eclipse.swt.events.ModifyListener;
12 import org.eclipse.swt.layout.FormAttachment;
13 import org.eclipse.swt.layout.FormData;
14 import org.eclipse.swt.layout.FormLayout;
15 import org.eclipse.swt.layout.GridData;
16 import org.eclipse.swt.layout.GridLayout;
17 import org.eclipse.swt.widgets.Composite;
18 import org.eclipse.swt.widgets.Label;
19 import org.eclipse.swt.widgets.Text;
20
21 /***
22 * AccountWizardPage1.java
23 *
24 * @author Xavier Cho
25 * @version $Revision: 1.6 $ $Date: 2004/04/17 18:21:01 $
26 */
27 public class AccountWizardPage1 extends WizardPage {
28
29 private Text textHost;
30 private Text textUser;
31 private Text textName;
32 private Text textEmail;
33 private Text textPassword;
34 private Text textConfirm;
35
36 public AccountWizardPage1(final String pageName) {
37 super(pageName);
38 }
39
40 public AccountWizardPage1(final String pageName, final String title,
41 final ImageDescriptor pageImage) {
42 super(pageName, title, pageImage);
43 }
44
45 public void createControl(final Composite parent) {
46 IPreferenceStore preferences = JFacePreferences.getPreferenceStore();
47 ResourceManager resources = ResourceManager.getInstance();
48
49 Composite panel = new Composite(parent, SWT.NONE);
50
51 panel.setLayout(new FormLayout());
52
53 Label label = new Label(panel, SWT.WRAP);
54 label.setText(resources.getString("wizard.account.page1.message"));
55
56 FormData data1 = new FormData();
57 data1.left = new FormAttachment(0, 10);
58 data1.top = new FormAttachment(0, 10);
59
60 label.setLayoutData(data1);
61
62 FormData data2 = new FormData();
63 data2.top = new FormAttachment(label, 20, SWT.BOTTOM);
64 data2.left = new FormAttachment(label, 20, SWT.LEFT);
65 data2.right = new FormAttachment(100);
66
67 Composite panel2 = new Composite(panel, SWT.NONE);
68
69 GridLayout gridLayout = new GridLayout();
70 gridLayout.numColumns = 2;
71 gridLayout.horizontalSpacing = 5;
72 gridLayout.verticalSpacing = 5;
73
74 panel2.setLayout(gridLayout);
75 panel2.setLayoutData(data2);
76
77 Label labelHost = new Label(panel2, SWT.NONE);
78 labelHost.setText(resources.getString("wizard.login.page1.host"));
79
80 GridData data3 = new GridData();
81 data3.horizontalAlignment = GridData.END;
82 data3.verticalAlignment = GridData.CENTER;
83
84 labelHost.setLayoutData(data3);
85
86 this.textHost = new Text(panel2, SWT.BORDER);
87
88 String host = preferences.getString("remote.server.host");
89 int port = preferences.getInt("remote.server.port");
90
91 textHost.setText(host + ":" + port);
92
93 GridData data4 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
94 data4.widthHint = 300;
95 data4.horizontalIndent = 5;
96
97 textHost.setLayoutData(data4);
98
99 Label labelUser = new Label(panel2, SWT.NONE);
100 labelUser.setText(resources.getString("wizard.login.page1.username"));
101
102 GridData data5 = new GridData();
103 data5.horizontalAlignment = GridData.END;
104 data5.verticalAlignment = GridData.CENTER;
105
106 labelUser.setLayoutData(data5);
107
108 this.textUser = new Text(panel2, SWT.BORDER);
109
110 GridData data6 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
111 data6.widthHint = 300;
112 data6.horizontalIndent = 5;
113
114 textUser.setLayoutData(data6);
115
116 Label labelEmail = new Label(panel2, SWT.NONE);
117 labelEmail.setText(resources.getString("wizard.login.page1.email"));
118
119 GridData data7 = new GridData();
120 data7.horizontalAlignment = GridData.END;
121 data7.verticalAlignment = GridData.CENTER;
122
123 labelEmail.setLayoutData(data7);
124
125 this.textEmail = new Text(panel2, SWT.BORDER);
126
127 GridData data8 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
128 data8.widthHint = 300;
129 data8.horizontalIndent = 5;
130
131 textEmail.setLayoutData(data8);
132
133 Label labelName = new Label(panel2, SWT.NONE);
134 labelName.setText(resources.getString("wizard.login.page1.realname"));
135
136 GridData data9 = new GridData();
137 data9.horizontalAlignment = GridData.END;
138 data9.verticalAlignment = GridData.CENTER;
139
140 labelName.setLayoutData(data9);
141
142 this.textName = new Text(panel2, SWT.BORDER);
143
144 GridData data10 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
145 data10.widthHint = 300;
146 data10.horizontalIndent = 5;
147
148 textName.setLayoutData(data10);
149
150 Label labelPassword = new Label(panel2, SWT.NONE);
151 labelPassword.setText(resources
152 .getString("wizard.login.page1.password"));
153
154 GridData data11 = new GridData();
155 data11.horizontalAlignment = GridData.END;
156 data11.verticalAlignment = GridData.CENTER;
157
158 labelPassword.setLayoutData(data11);
159
160 this.textPassword = new Text(panel2, SWT.BORDER);
161 textPassword.setEchoChar('*');
162
163 GridData data12 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
164 data12.widthHint = 300;
165 data12.horizontalIndent = 5;
166
167 textPassword.setLayoutData(data12);
168
169 Label labelConfirm = new Label(panel2, SWT.NONE);
170 labelConfirm.setText(resources.getString("wizard.login.page1.confirm"));
171
172 GridData data13 = new GridData();
173 data13.horizontalAlignment = GridData.END;
174 data13.verticalAlignment = GridData.CENTER;
175
176 labelConfirm.setLayoutData(data13);
177
178 this.textConfirm = new Text(panel2, SWT.BORDER);
179 textConfirm.setEchoChar('*');
180
181 GridData data14 = new GridData(GridData.VERTICAL_ALIGN_CENTER);
182 data14.widthHint = 300;
183 data14.horizontalIndent = 5;
184
185 textConfirm.setLayoutData(data14);
186
187 setControl(panel);
188
189 ModifyListener listener = new ModifyListener() {
190
191 public void modifyText(final ModifyEvent event) {
192 checkInput();
193 }
194 };
195
196 textHost.setTextLimit(40);
197 textHost.addModifyListener(listener);
198
199 textUser.setTextLimit(Account.MAX_USERNAME_LENGTH);
200 textUser.addModifyListener(listener);
201
202 textName.setTextLimit(Account.MAX_REALNAME_LENGTH);
203 textName.addModifyListener(listener);
204
205 textPassword.setTextLimit(Account.MAX_PASSWORD_LENGTH);
206 textPassword.addModifyListener(listener);
207
208 textConfirm.setTextLimit(Account.MAX_PASSWORD_LENGTH);
209 textConfirm.addModifyListener(listener);
210
211 setPageComplete(false);
212
213 textHost.setFocus();
214 }
215
216 private void checkInput() {
217 boolean isCompleted = true;
218
219 String message = null;
220
221 String host = textHost.getText().trim();
222 String userName = textUser.getText().trim();
223 String realName = textName.getText().trim();
224 String password = textPassword.getText().trim();
225 String confirm = textConfirm.getText().trim();
226
227 if (host.length() == 0) {
228 isCompleted = false;
229 } else if (userName.length() == 0) {
230 isCompleted = false;
231 } else if (userName.length() < Account.MIN_USERNAME_LENGTH) {
232 ResourceManager resources = ResourceManager.getInstance();
233 message = resources.getString("error.username.min.length");
234
235 isCompleted = false;
236 } else if (password.length() == 0 || realName.length() == 0) {
237 isCompleted = false;
238 } else if (password.length() < Account.MIN_PASSWORD_LENGTH) {
239 ResourceManager resources = ResourceManager.getInstance();
240 message = resources.getString("error.password.min.length");
241
242 isCompleted = false;
243 } else if (confirm.length() == 0) {
244 isCompleted = false;
245 } else if (!confirm.equals(password)) {
246 ResourceManager resources = ResourceManager.getInstance();
247 message = resources.getString("error.password.not.match");
248
249 isCompleted = false;
250 }
251
252 if (getErrorMessage() == null) {
253 if (message != null) {
254 setErrorMessage(message);
255 }
256 } else if (!getErrorMessage().equals(message)) {
257 setErrorMessage(message);
258 }
259
260 setPageComplete(isCompleted);
261 }
262
263 public Account getAccount() {
264 String userName = textUser.getText().trim();
265 String realName = textName.getText().trim();
266 String email = textEmail.getText().trim();
267 String password = textPassword.getText().trim();
268
269 if (email.length() == 0) {
270 email = null;
271 }
272
273 Account account = new Account();
274
275 account.setUserName(userName);
276 account.setRealName(realName);
277 account.setEmail(email);
278 account.setPassword(password);
279
280 return account;
281 }
282
283 public String getHostAddress() {
284 return textHost.getText().trim();
285 }
286 }
This page was automatically generated by Maven