Fixed stuff.
[FinalKeyGui.git] / src / fkgui / NewAccountDialog.java
1 package fkgui;
2
3 import org.eclipse.swt.widgets.Dialog;
4 import org.eclipse.swt.widgets.Display;
5 import org.eclipse.swt.widgets.Shell;
6 import org.eclipse.swt.layout.FormLayout;
7 import org.eclipse.swt.layout.FillLayout;
8 import org.eclipse.swt.SWT;
9 import org.eclipse.swt.layout.FormData;
10 import org.eclipse.swt.layout.FormAttachment;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13 import org.eclipse.swt.widgets.Label;
14 import org.eclipse.swt.widgets.MessageBox;
15 import org.eclipse.swt.widgets.Text;
16 import org.eclipse.swt.widgets.Button;
17 import org.eclipse.swt.events.ModifyEvent;
18 import org.eclipse.swt.events.ModifyListener;
19 import org.eclipse.swt.events.SelectionAdapter;
20 import org.eclipse.swt.events.SelectionEvent;
21 import org.eclipse.swt.events.SelectionListener;
22 import org.eclipse.swt.graphics.Point;
23 import org.eclipse.swt.widgets.Spinner;
24
25 public class NewAccountDialog extends Dialog implements FkActionEventListener {
26
27         protected Object result;
28         protected Shell shlNewAccount;
29         private Text txtAccountName;
30         private Text txtUserName;
31         private Text txtManPSW;
32         private Text txtSpecials;
33         
34         private enum FkNewAccStep { NAMES, PASSTYPE, PASS_MAN, PASS_AUT, SEPERATOR, REVIEW, CLICKBTN, SAVING };
35         private enum FkNewAccAutoSpecials { ALL, SELECTED, NONE };
36         
37         private String strAccountName = ""; //$NON-NLS-1$
38         private String strUserName = ""; //$NON-NLS-1$
39         private String strPassword = ""; //$NON-NLS-1$
40         private String autoPassSpecials = "!@#,.-_()"; //$NON-NLS-1$
41         private FkNewAccAutoSpecials allowedAutoSpecials = FkNewAccAutoSpecials.ALL;
42         private Boolean autoPassword = true;
43         private int autoPassLen = 16;
44         private Boolean seperatorTab=true;
45         private Button btnManPassBack;
46
47         //NamePage
48         Button btnNext0;
49
50         
51         //PassType
52         Button radAutPSW;
53         Button radManPSW;
54         
55         //ManPass
56         Label lblTypeThePassword;
57         Label lblPassword;
58         Button chkShowPsw;
59         Button btnManPassPageNext;
60         
61         //Autopass
62         Button radAllSymbols;
63         Button radOnlySelected;
64         Spinner spnLen;
65         
66         //Seperator
67         Button radTabSep;
68         
69         //Saving
70         Label txtBUSYMSG;
71         Animation animation;
72         
73         NewAccountDialog mySelf;
74
75         
76         
77         Composite composite;
78         /**
79          * Create the dialog.
80          * @param parent
81          * @param style
82          */
83         public NewAccountDialog(Shell parent, int style) {
84                 super(parent, style);
85                 
86         }
87
88         /**
89          * Open the dialog.
90          * @return the result
91          */
92         public Object open() {
93                 createContents();
94                 Point p = getParent().getSize();
95                 p.x /= 2;
96                 p.y /= 2;
97                 p.x -= shlNewAccount.getSize().x/2;
98                 p.y -= shlNewAccount.getSize().y/2;
99                 p.x += getParent().getLocation().x;
100                 p.y += getParent().getLocation().y;
101                 shlNewAccount.setLocation( p );
102
103                 
104                 shlNewAccount.open();
105                 shlNewAccount.layout();
106                 Display display = getParent().getDisplay();
107                 mySelf = this;
108                 while (!shlNewAccount.isDisposed()) {
109                         if (!display.readAndDispatch()) {
110                                 display.sleep();
111                         }
112                 }
113                 return result;
114         }
115         
116         private void checkNamePage()
117         {
118                 if( txtAccountName.getText().length() > 0 && txtUserName.getText().length() > 0 )
119                 {
120                         btnNext0.setVisible(true);
121                 } else {
122                         btnNext0.setVisible(false);
123                 }
124         }
125
126         private void createNamePage()
127         {
128                 composite = new Composite(shlNewAccount, SWT.NONE);
129         //      tbtmStepUsername.setControl(composite);
130                 composite.setLayout(new FormLayout());
131                 
132                 
133                 
134                 Label lblEnterNewName = new Label(composite, SWT.NONE);
135                 FormData fd_lblEnterNewName = new FormData();
136                 fd_lblEnterNewName.bottom = new FormAttachment(0, 112);
137                 fd_lblEnterNewName.right = new FormAttachment(0, 613);
138                 fd_lblEnterNewName.top = new FormAttachment(0, 10);
139                 fd_lblEnterNewName.left = new FormAttachment(0, 10);
140                 lblEnterNewName.setLayoutData(fd_lblEnterNewName);
141                 lblEnterNewName.setText(Messages.NewAccountDialog_4);
142                 Label lblUsername = new Label(composite, SWT.NONE);
143                 FormData fd_lblUsername = new FormData();
144                 lblUsername.setLayoutData(fd_lblUsername);
145                 lblUsername.setText(Messages.NewAccountDialog_5);
146                 
147                 txtAccountName = new Text(composite, SWT.BORDER);
148                 fd_lblUsername.bottom = new FormAttachment(txtAccountName, 0, SWT.BOTTOM);
149                 fd_lblUsername.right = new FormAttachment(txtAccountName, -6);
150                 FormData fd_txtAccountName = new FormData();
151                 fd_txtAccountName.top = new FormAttachment(lblEnterNewName, 6);
152                 fd_txtAccountName.right = new FormAttachment(100, -274);
153                 fd_txtAccountName.left = new FormAttachment(0, 180);
154                 txtAccountName.setLayoutData(fd_txtAccountName);
155                 txtAccountName.setTextLimit(31);
156                 txtAccountName.addModifyListener( new ModifyListener() {
157                         @Override
158                         public void modifyText(ModifyEvent arg0) {
159                                 checkNamePage();
160
161                         }
162                 });
163                 
164                 Label lblNewLabel = new Label(composite, SWT.NONE);
165                 FormData fd_lblNewLabel = new FormData();
166                 fd_lblNewLabel.left = new FormAttachment(0, 10);
167                 fd_lblNewLabel.right = new FormAttachment(100);
168                 fd_lblNewLabel.top = new FormAttachment(lblUsername, 20);
169                 lblNewLabel.setLayoutData(fd_lblNewLabel);
170                 lblNewLabel.setText(Messages.NewAccountDialog_6);
171                 
172                 Label lblUsername_1 = new Label(composite, SWT.NONE);
173                 FormData fd_lblUsername_1 = new FormData();
174                 fd_lblUsername_1.top = new FormAttachment(lblNewLabel, 6);
175                 fd_lblUsername_1.right = new FormAttachment(lblUsername, 0, SWT.RIGHT);
176                 lblUsername_1.setLayoutData(fd_lblUsername_1);
177                 lblUsername_1.setText(Messages.NewAccountDialog_7);
178                 
179                 txtUserName = new Text(composite, SWT.BORDER);
180                 FormData fd_txtUserName = new FormData();
181                 fd_txtUserName.left = new FormAttachment(txtAccountName, 0, SWT.LEFT);
182                 fd_txtUserName.right = new FormAttachment(txtAccountName, 0, SWT.RIGHT);
183                 fd_txtUserName.top = new FormAttachment(lblNewLabel, 6);
184                 txtUserName.setLayoutData(fd_txtUserName);
185                 txtUserName.addModifyListener( new ModifyListener() {
186                         @Override
187                         public void modifyText(ModifyEvent arg0) {
188                                 checkNamePage();
189                         }
190                 });
191                 
192                 Button btnCancel = new Button(composite, SWT.NONE);
193                 btnCancel.addSelectionListener(new SelectionAdapter() {
194                         @Override
195                         public void widgetSelected(SelectionEvent e) {
196                                 shlNewAccount.close();
197                         }
198                 });
199                 FormData fd_btnCancel = new FormData();
200                 fd_btnCancel.bottom = new FormAttachment(100, -10);
201                 fd_btnCancel.left = new FormAttachment(lblEnterNewName, 0, SWT.LEFT);
202                 btnCancel.setLayoutData(fd_btnCancel);
203                 btnCancel.setText(Messages.NewAccountDialog_8);
204                 
205                 btnNext0 = new Button(composite, SWT.NONE);
206                 btnNext0.addSelectionListener(new SelectionAdapter() {
207                         @Override
208                         public void widgetSelected(SelectionEvent e) {
209                                 strAccountName = txtAccountName.getText();
210                                 strUserName = txtUserName.getText();
211                                 updatePage(FkNewAccStep.PASSTYPE);
212                         }
213                 });
214                 btnNext0.setText(Messages.NewAccountDialog_9);
215                 FormData fd_btnNext0 = new FormData();
216                 fd_btnNext0.top = new FormAttachment(btnCancel, 0, SWT.TOP);
217                 fd_btnNext0.right = new FormAttachment(100, -10);
218                 btnNext0.setLayoutData(fd_btnNext0);
219                 btnNext0.setVisible(false);
220                 
221                 txtUserName.setText( strUserName );
222                 txtAccountName.setText( strAccountName );
223
224         Control[] controls = new Control[] { txtAccountName, txtUserName, btnNext0, btnCancel };
225         composite.setTabList(controls);
226         txtAccountName.setFocus();
227                 
228         }
229         
230         
231         private void createPassTypePage()
232         {
233                 composite = new Composite(shlNewAccount, SWT.NONE);
234                 composite.setLayout(new FormLayout());
235                 
236                 Label lblNextUpSetting = new Label(composite, SWT.NONE);
237                 FormData fd_lblNextUpSetting = new FormData();
238                 fd_lblNextUpSetting.right = new FormAttachment(0, 603);
239                 fd_lblNextUpSetting.top = new FormAttachment(0, 10);
240                 fd_lblNextUpSetting.left = new FormAttachment(0, 10);
241                 lblNextUpSetting.setLayoutData(fd_lblNextUpSetting);
242                 lblNextUpSetting.setText(Messages.NewAccountDialog_10);
243                 
244                 radAutPSW = new Button(composite, SWT.RADIO);
245                 if( autoPassword )
246                 {
247                         radAutPSW.setSelection(true);
248                 }
249                 FormData fd_radAutPSW = new FormData();
250                 fd_radAutPSW.top = new FormAttachment(lblNextUpSetting, 37);
251                 fd_radAutPSW.left = new FormAttachment(0, 213);
252                 radAutPSW.setLayoutData(fd_radAutPSW);
253                 radAutPSW.setText(Messages.NewAccountDialog_11);
254                 
255                 radManPSW = new Button(composite, SWT.RADIO);
256                 if( !autoPassword )
257                 {
258                         radManPSW.setSelection(true);
259                 }               
260                 FormData fd_radManPSW = new FormData();
261                 fd_radManPSW.top = new FormAttachment(radAutPSW, 6);
262                 fd_radManPSW.left = new FormAttachment(radAutPSW, 0, SWT.LEFT);
263                 radManPSW.setLayoutData(fd_radManPSW);
264                 radManPSW.setText(Messages.NewAccountDialog_12);
265                 
266                 Button btnNext1 = new Button(composite, SWT.NONE);
267                 btnNext1.setText(Messages.NewAccountDialog_13);
268                 FormData fd_btnNext1 = new FormData();
269                 fd_btnNext1.right = new FormAttachment(100, -10);
270                 btnNext1.setLayoutData(fd_btnNext1);
271                 btnNext1.addSelectionListener(new SelectionListener() {
272                         
273                         @Override
274                         public void widgetSelected(SelectionEvent arg0) {
275                                 if( radAutPSW.getSelection() )
276                                 {
277                                         updatePage(FkNewAccStep.PASS_AUT);
278                                         autoPassword = true;
279                                 } else {
280                                         updatePage(FkNewAccStep.PASS_MAN);
281                                         autoPassword = false;
282                                 }
283                         }
284                         
285                         @Override
286                         public void widgetDefaultSelected(SelectionEvent arg0) {
287                                 // TODO Auto-generated method stub
288                                 
289                         }
290                 });
291                 
292                 Button btnBack0 = new Button(composite, SWT.NONE);
293                 fd_btnNext1.top = new FormAttachment(btnBack0, 0, SWT.TOP);
294                 btnBack0.setText(Messages.NewAccountDialog_14);
295                 FormData fd_btnBack0 = new FormData();
296                 fd_btnBack0.bottom = new FormAttachment(100, -10);
297                 fd_btnBack0.left = new FormAttachment(lblNextUpSetting, 0, SWT.LEFT);
298                 btnBack0.setLayoutData(fd_btnBack0);
299                 btnBack0.addSelectionListener( new SelectionListener() {
300                         
301                         @Override
302                         public void widgetSelected(SelectionEvent arg0) {
303                                 updatePage( FkNewAccStep.NAMES );
304                                 
305                         }
306                         
307                         @Override
308                         public void widgetDefaultSelected(SelectionEvent arg0) {
309                                 // TODO Auto-generated method stub
310                                 
311                         }
312                 });
313                 
314         Control[] controls = new Control[] { radAutPSW, radManPSW, btnNext1, btnBack0 };
315         composite.setTabList(controls);
316         radAutPSW.setFocus();
317 }
318         
319         void autoPassPageSaveValues()
320         {
321                 if( radAllSymbols.getSelection() )
322                 {
323                         allowedAutoSpecials = FkNewAccAutoSpecials.ALL;
324                 } else if( radOnlySelected.getSelection() )
325                 {
326                         allowedAutoSpecials = FkNewAccAutoSpecials.SELECTED;
327                 } else {
328                         allowedAutoSpecials = FkNewAccAutoSpecials.NONE;
329                 }
330                 autoPassSpecials = txtSpecials.getText();
331                 autoPassLen = spnLen.getSelection();            
332         }
333         void createPassAutPage()
334         {
335                 composite = new Composite(shlNewAccount, SWT.NONE);
336                 composite.setLayout(new FormLayout());
337                 
338                 Label lblBeforeCreatingA = new Label(composite, SWT.NONE);
339                 FormData fd_lblBeforeCreatingA = new FormData();
340                 fd_lblBeforeCreatingA.left = new FormAttachment(0, 10);
341                 fd_lblBeforeCreatingA.right = new FormAttachment(100, -10);
342                 fd_lblBeforeCreatingA.top = new FormAttachment(0, 10);
343                 lblBeforeCreatingA.setLayoutData(fd_lblBeforeCreatingA);
344                 
345                 lblBeforeCreatingA.setText(Messages.NewAccountDialog_15);
346                 
347                 Label lblPasswordLength = new Label(composite, SWT.NONE);
348                 fd_lblBeforeCreatingA.bottom = new FormAttachment(100, -257);
349                 FormData fd_lblPasswordLength = new FormData();
350                 lblPasswordLength.setLayoutData(fd_lblPasswordLength);
351                 lblPasswordLength.setText(Messages.NewAccountDialog_16);
352                 
353                 spnLen = new Spinner(composite, SWT.BORDER);
354                 fd_lblPasswordLength.bottom = new FormAttachment(spnLen, 0, SWT.BOTTOM);
355                 fd_lblPasswordLength.right = new FormAttachment(spnLen, -9);
356                 FormData fd_spnLen = new FormData();
357                 fd_spnLen.top = new FormAttachment(0, 119);
358                 fd_spnLen.left = new FormAttachment(0, 310);
359                 spnLen.setLayoutData(fd_spnLen);
360                 spnLen.setMaximum(128);
361                 spnLen.setSelection(autoPassLen);
362                 
363                 Label lblASafePassword = new Label(composite, SWT.NONE);
364                 FormData fd_lblASafePassword = new FormData();
365                 fd_lblASafePassword.right = new FormAttachment(lblBeforeCreatingA, 0, SWT.RIGHT);
366                 fd_lblASafePassword.top = new FormAttachment(lblPasswordLength, 47);
367                 fd_lblASafePassword.left = new FormAttachment(0, 10);
368                 lblASafePassword.setLayoutData(fd_lblASafePassword);
369                 lblASafePassword.setText(Messages.NewAccountDialog_17);
370                 
371                 radAllSymbols = new Button(composite, SWT.RADIO);
372                 fd_lblASafePassword.bottom = new FormAttachment(100, -100);
373                 FormData fd_radAllSymbols = new FormData();
374                 fd_radAllSymbols.top = new FormAttachment(lblASafePassword, 6);
375                 fd_radAllSymbols.left = new FormAttachment(0, 10);
376                 radAllSymbols.setLayoutData(fd_radAllSymbols);
377                 if( allowedAutoSpecials == FkNewAccAutoSpecials.ALL )
378                 {
379                         radAllSymbols.setSelection(true);
380                 }
381                 radAllSymbols.setText(Messages.NewAccountDialog_18);
382                 radAllSymbols.pack();
383                 
384                 radOnlySelected = new Button(composite, SWT.RADIO);
385                 FormData fd_radOnlySelected = new FormData();
386                 fd_radOnlySelected.top = new FormAttachment(lblASafePassword, 6);
387                 fd_radOnlySelected.left = new FormAttachment(lblPasswordLength, 0, SWT.LEFT);
388                 radOnlySelected.setLayoutData(fd_radOnlySelected);
389                 if( allowedAutoSpecials == FkNewAccAutoSpecials.SELECTED )
390                 {
391                         radOnlySelected.setSelection(true);
392                 }
393                 radOnlySelected.setText(Messages.NewAccountDialog_19);
394                 
395                 
396                 
397                 txtSpecials = new Text(composite, SWT.BORDER);
398                 FormData fd_txtSpecials = new FormData();
399                 fd_txtSpecials.bottom = new FormAttachment(radAllSymbols, 0, SWT.BOTTOM);
400                 fd_txtSpecials.left = new FormAttachment(radOnlySelected, 6);
401                 txtSpecials.setLayoutData(fd_txtSpecials);
402                 txtSpecials.setText(autoPassSpecials);
403                 txtSpecials.setBounds(291, 243, 312, 35);
404                 
405                 
406                 Button button_6 = new Button(composite, SWT.NONE);
407                 button_6.setText(Messages.NewAccountDialog_21);
408                 FormData fd_button_6 = new FormData();
409                 fd_button_6.right = new FormAttachment(lblBeforeCreatingA, 0, SWT.RIGHT);
410                 button_6.setLayoutData(fd_button_6);
411                 
412                 button_6.addSelectionListener(new SelectionListener() {
413                         
414                         @Override
415                         public void widgetSelected(SelectionEvent arg0) {
416                                 autoPassPageSaveValues();
417                                 updatePage( FkNewAccStep.SEPERATOR );
418                         }
419                         
420                         @Override
421                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
422                         }
423                 });
424                 
425
426                 Button button_5 = new Button(composite, SWT.NONE);
427                 fd_button_6.top = new FormAttachment(button_5, 0, SWT.TOP);
428                 button_5.setText(Messages.NewAccountDialog_20);
429                 FormData fd_button_5 = new FormData();
430                 fd_button_5.bottom = new FormAttachment(100, -10);
431                 fd_button_5.left = new FormAttachment(0, 10);
432                 button_5.setLayoutData(fd_button_5);
433                 
434                 button_5.addSelectionListener(new SelectionListener() {
435                         
436                         @Override
437                         public void widgetSelected(SelectionEvent arg0) {
438                                 autoPassPageSaveValues();
439                                 updatePage( FkNewAccStep.PASSTYPE );
440                         }
441                         
442                         @Override
443                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
444                         }
445                 });
446                 
447                 
448         
449         Button radNoSpecialSymbols = new Button(composite, SWT.RADIO);
450         FormData fd_radNoSpecialSymbols = new FormData();
451         fd_radNoSpecialSymbols.top = new FormAttachment(lblASafePassword, 6);
452         fd_radNoSpecialSymbols.left = new FormAttachment(txtSpecials, 57);
453         radNoSpecialSymbols.setLayoutData(fd_radNoSpecialSymbols);
454         radNoSpecialSymbols.setText(Messages.NewAccountDialog_btnNoSpecialSymbols_text);
455                 if( allowedAutoSpecials == FkNewAccAutoSpecials.NONE )
456                 {
457                         radNoSpecialSymbols.setSelection(true);
458                 }        
459         
460
461                 Control[] controls = new Control[] { spnLen, radAllSymbols, radOnlySelected, radNoSpecialSymbols, button_6, button_5 };
462         composite.setTabList(controls);                 
463                 spnLen.setFocus();
464
465                 
466         }
467         
468         
469         void makePswField(Boolean showPsw)
470         {
471                 txtManPSW = new Text(composite, SWT.BORDER | ((showPsw)?0:SWT.PASSWORD) );
472                 FormData fd_txtManPSW = new FormData();
473                 fd_txtManPSW.right = new FormAttachment(0, 613);
474                 fd_txtManPSW.top = new FormAttachment(0, 62);
475                 fd_txtManPSW.left = new FormAttachment(0, 92);
476                 txtManPSW.setLayoutData(fd_txtManPSW);
477                 txtManPSW.setText(strPassword);
478                 txtManPSW.addModifyListener( new ModifyListener() {
479                         
480                         @Override
481                         public void modifyText(ModifyEvent arg0) {
482                                 strPassword = txtManPSW.getText();
483                                 if( txtManPSW.getText().length() > 0 )
484                                 {
485                                         btnManPassPageNext.setVisible(true);
486                                 } else {
487                                         btnManPassPageNext.setVisible(false);
488                                 }
489                                 
490                         }
491                 });
492                 
493
494                 composite.layout();
495         }
496         
497
498         
499         void createPassManPage()
500         {
501                 composite = new Composite(shlNewAccount, SWT.NONE);
502                 composite.setLayout(new FormLayout());
503
504                 btnManPassBack = new Button(composite, SWT.NONE);
505                 FormData fd_BtnBack1 = new FormData();
506                 fd_BtnBack1.bottom = new FormAttachment(100, -10);
507                 btnManPassBack.setLayoutData(fd_BtnBack1);
508                 btnManPassBack.setText(Messages.NewAccountDialog_23);
509                 btnManPassBack.addSelectionListener( new SelectionListener() {
510                         
511                         @Override
512                         public void widgetSelected(SelectionEvent arg0) {
513                                 updatePage(FkNewAccStep.PASSTYPE);
514                         }
515                         
516                         @Override
517                         public void widgetDefaultSelected(SelectionEvent arg0) {
518                                 
519                         }
520                 });
521                 
522                 btnManPassPageNext = new Button(composite, SWT.NONE);
523                 FormData fd_btnManPassPageNext = new FormData();
524                 fd_btnManPassPageNext.top = new FormAttachment(btnManPassBack, 0, SWT.TOP);
525                 fd_btnManPassPageNext.right = new FormAttachment(100, -10);
526                 btnManPassPageNext.setLayoutData(fd_btnManPassPageNext);
527                 btnManPassPageNext.setText(Messages.NewAccountDialog_24);
528                 
529                 btnManPassPageNext.addSelectionListener( new SelectionListener() {
530                         
531                         @Override
532                         public void widgetSelected(SelectionEvent arg0) {
533                                 updatePage(FkNewAccStep.SEPERATOR);
534                         }
535                         
536                         @Override
537                         public void widgetDefaultSelected(SelectionEvent arg0) {                                
538                         }
539                 });
540                 
541                 lblTypeThePassword = new Label(composite, SWT.NONE);
542                 fd_BtnBack1.left = new FormAttachment(lblTypeThePassword, 0, SWT.LEFT);
543                 FormData fd_lblTypeThePassword = new FormData();
544                 fd_lblTypeThePassword.right = new FormAttachment(0, 613);
545                 fd_lblTypeThePassword.top = new FormAttachment(0, 10);
546                 fd_lblTypeThePassword.left = new FormAttachment(0, 10);
547                 lblTypeThePassword.setLayoutData(fd_lblTypeThePassword);
548                 lblTypeThePassword.setText(Messages.NewAccountDialog_25);
549                 
550                 lblPassword = new Label(composite, SWT.NONE);
551                 FormData fd_lblPassword = new FormData();
552                 fd_lblPassword.top = new FormAttachment(0, 62);
553                 fd_lblPassword.left = new FormAttachment(0, 10);
554                 lblPassword.setLayoutData(fd_lblPassword);
555                 lblPassword.setText(Messages.NewAccountDialog_26);
556                 
557                 makePswField(false);
558
559                 chkShowPsw = new Button(composite, SWT.CHECK);
560                 FormData fd_chkShowPsw = new FormData();
561                 fd_chkShowPsw.right = new FormAttachment(0, 613);
562                 fd_chkShowPsw.top = new FormAttachment(0, 103);
563                 fd_chkShowPsw.left = new FormAttachment(0, 92);
564                 chkShowPsw.setLayoutData(fd_chkShowPsw);
565                 chkShowPsw.setText(Messages.NewAccountDialog_22);
566                 chkShowPsw.setSelection(false);
567                 
568                 chkShowPsw.addSelectionListener( new SelectionListener() {
569
570                         @Override
571                         public void widgetSelected(SelectionEvent arg0) {
572                                 Button btnChk = (Button)arg0.getSource();
573
574                                 txtManPSW.dispose();
575                                 
576                                 makePswField(btnChk.getSelection());
577                         Control[] controls = new Control[] { txtManPSW, chkShowPsw, btnManPassPageNext, btnManPassBack };
578                         composite.setTabList(controls);                                 
579                         }
580                         
581                         @Override
582                         public void widgetDefaultSelected(SelectionEvent arg0) {
583                         }
584                 });             
585                 
586         Control[] controls = new Control[] { txtManPSW, chkShowPsw, btnManPassPageNext, btnManPassBack };
587         composite.setTabList(controls); 
588         txtManPSW.setFocus();
589         btnManPassPageNext.setVisible( (txtManPSW.getText().length() > 0) );
590                 
591         }
592         
593
594         void createSeperatorPage()
595         {
596                 composite = new Composite(shlNewAccount, SWT.NONE);
597                 composite.setLayout(new FormLayout());
598                 
599                 Label lblToMakeFinalkey = new Label(composite, SWT.NONE);
600                 FormData fd_lblToMakeFinalkey = new FormData();
601                 fd_lblToMakeFinalkey.right = new FormAttachment(0, 613);
602                 fd_lblToMakeFinalkey.top = new FormAttachment(0, 10);
603                 fd_lblToMakeFinalkey.left = new FormAttachment(0, 10);
604                 lblToMakeFinalkey.setLayoutData(fd_lblToMakeFinalkey);
605                 lblToMakeFinalkey.setText(Messages.NewAccountDialog_27);
606                 
607                 radTabSep = new Button(composite, SWT.RADIO);
608                 FormData fd_radTabSep = new FormData();
609                 fd_radTabSep.right = new FormAttachment(0, 613);
610                 fd_radTabSep.top = new FormAttachment(0, 172);
611                 fd_radTabSep.left = new FormAttachment(0, 231);
612                 radTabSep.setLayoutData(fd_radTabSep);
613                 if( seperatorTab )
614                 {
615                         radTabSep.setSelection(true);
616                 }
617                 radTabSep.setText(Messages.NewAccountDialog_28);
618                 
619                 Button radEnterSep = new Button(composite, SWT.RADIO);
620                 FormData fd_radEnterSep = new FormData();
621                 fd_radEnterSep.right = new FormAttachment(0, 613);
622                 fd_radEnterSep.top = new FormAttachment(0, 205);
623                 fd_radEnterSep.left = new FormAttachment(0, 231);
624                 radEnterSep.setLayoutData(fd_radEnterSep);
625                 if( !seperatorTab )
626                 {
627                         radEnterSep.setSelection(true);
628                 }
629                 radEnterSep.setText(Messages.NewAccountDialog_29);
630                 
631                 Button button_7 = new Button(composite, SWT.NONE);
632                 FormData fd_button_7 = new FormData();
633                 fd_button_7.left = new FormAttachment(lblToMakeFinalkey, 0, SWT.LEFT);
634                 button_7.setLayoutData(fd_button_7);
635                 button_7.setText(Messages.NewAccountDialog_30);
636                 button_7.addSelectionListener(new SelectionListener() {
637                         
638                         @Override
639                         public void widgetSelected(SelectionEvent arg0) {
640                                 seperatorTab = radTabSep.getSelection();
641                                 if( autoPassword )
642                                 {
643                                         updatePage(FkNewAccStep.PASS_AUT);
644                                 } else {
645                                         updatePage(FkNewAccStep.PASS_MAN);
646                                 }
647                         }
648                         
649                         @Override
650                         public void widgetDefaultSelected(SelectionEvent arg0) {
651                         }
652                 });
653                 
654                 Button button_8 = new Button(composite, SWT.NONE);
655                 fd_button_7.top = new FormAttachment(button_8, 0, SWT.TOP);
656                 FormData fd_button_8 = new FormData();
657                 fd_button_8.bottom = new FormAttachment(100, -10);
658                 fd_button_8.right = new FormAttachment(100, -10);
659                 button_8.setLayoutData(fd_button_8);
660                 button_8.setText(Messages.NewAccountDialog_31);
661                 button_8.addSelectionListener(new SelectionListener() {
662                         
663                         @Override
664                         public void widgetSelected(SelectionEvent arg0) {
665                                 seperatorTab = radTabSep.getSelection();
666                                 updatePage(FkNewAccStep.REVIEW);
667                         }
668                         
669                         @Override
670                         public void widgetDefaultSelected(SelectionEvent arg0) {
671                         }
672                 });
673                 
674
675         Control[] controls = new Control[] { radTabSep, radEnterSep, button_8, button_7 };
676         composite.setTabList(controls);         
677         radTabSep.setFocus();
678                 
679         }
680         
681
682         void createReviewPage()
683         {
684                 composite = new Composite(shlNewAccount, SWT.NONE);
685                 composite.setLayout(new FormLayout());
686                 
687                 Label lblHeresAnOverview = new Label(composite, SWT.NONE);
688                 FormData fd_lblHeresAnOverview = new FormData();
689                 fd_lblHeresAnOverview.right = new FormAttachment(0, 613);
690                 fd_lblHeresAnOverview.top = new FormAttachment(0, 10);
691                 fd_lblHeresAnOverview.left = new FormAttachment(0, 10);
692                 lblHeresAnOverview.setLayoutData(fd_lblHeresAnOverview);
693                 lblHeresAnOverview.setText(Messages.NewAccountDialog_32);
694                 
695                 Label lblAccountName = new Label(composite, SWT.NONE);
696                 lblAccountName.setAlignment(SWT.RIGHT);
697                 FormData fd_lblAccountName = new FormData();
698                 fd_lblAccountName.left = new FormAttachment(0, 10);
699                 fd_lblAccountName.top = new FormAttachment(0, 51);
700                 lblAccountName.setLayoutData(fd_lblAccountName);
701                 lblAccountName.setText(Messages.NewAccountDialog_33);
702                 
703                 Label lblPasswordType = new Label(composite, SWT.NONE);
704                 lblPasswordType.setAlignment(SWT.RIGHT);
705                 FormData fd_lblPasswordType = new FormData();
706                 fd_lblPasswordType.right = new FormAttachment(lblAccountName, 0, SWT.RIGHT);
707                 fd_lblPasswordType.left = new FormAttachment(lblHeresAnOverview, 0, SWT.LEFT);
708                 fd_lblPasswordType.top = new FormAttachment(0, 109);
709                 lblPasswordType.setLayoutData(fd_lblPasswordType);
710                 lblPasswordType.setText(Messages.NewAccountDialog_34);
711                 
712                 Label lblUserName = new Label(composite, SWT.NONE);
713                 lblUserName.setAlignment(SWT.RIGHT);
714                 FormData fd_lblUserName = new FormData();
715                 fd_lblUserName.right = new FormAttachment(lblHeresAnOverview, 220);
716                 fd_lblUserName.left = new FormAttachment(lblHeresAnOverview, 0, SWT.LEFT);
717                 fd_lblUserName.top = new FormAttachment(0, 80);
718                 lblUserName.setLayoutData(fd_lblUserName);
719                 lblUserName.setText(Messages.NewAccountDialog_35);
720                 
721                 Label lblIfEverythingLooks = new Label(composite, SWT.NONE);
722                 FormData fd_lblIfEverythingLooks = new FormData();
723                 fd_lblIfEverythingLooks.bottom = new FormAttachment(0, 287);
724                 fd_lblIfEverythingLooks.right = new FormAttachment(lblHeresAnOverview, 0, SWT.RIGHT);
725                 fd_lblIfEverythingLooks.top = new FormAttachment(0, 181);
726                 fd_lblIfEverythingLooks.left = new FormAttachment(0, 10);
727                 lblIfEverythingLooks.setLayoutData(fd_lblIfEverythingLooks);
728                 lblIfEverythingLooks.setText(Messages.NewAccountDialog_36);
729                 
730                 Label lblSeperator = new Label(composite, SWT.NONE);
731                 lblSeperator.setAlignment(SWT.RIGHT);
732                 FormData fd_lblSeperator = new FormData();
733                 fd_lblSeperator.right = new FormAttachment(0, 230);
734                 fd_lblSeperator.top = new FormAttachment(0, 138);
735                 fd_lblSeperator.left = new FormAttachment(0, 10);
736                 lblSeperator.setLayoutData(fd_lblSeperator);
737                 lblSeperator.setText(Messages.NewAccountDialog_37);
738                 
739                 Button button_9 = new Button(composite, SWT.NONE);
740                 FormData fd_button_9 = new FormData();
741                 fd_button_9.bottom = new FormAttachment(100, -10);
742                 fd_button_9.left = new FormAttachment(lblHeresAnOverview, 0, SWT.LEFT);
743                 button_9.setLayoutData(fd_button_9);
744                 button_9.setText(Messages.NewAccountDialog_38);
745                 button_9.addSelectionListener( new SelectionListener() {
746                         
747                         @Override
748                         public void widgetSelected(SelectionEvent arg0) {
749                                 updatePage(FkNewAccStep.SEPERATOR);
750                         }
751                         
752                         @Override
753                         public void widgetDefaultSelected(SelectionEvent arg0) {                
754                         }
755                 });
756                 
757                 Button btnSave = new Button(composite, SWT.NONE);
758                 FormData fd_btnSave = new FormData();
759                 fd_btnSave.top = new FormAttachment(button_9, 0, SWT.TOP);
760                 fd_btnSave.right = new FormAttachment(100, -10);
761                 btnSave.setLayoutData(fd_btnSave);
762                 btnSave.setText(Messages.NewAccountDialog_39);
763                 btnSave.setFocus();
764                 
765                 btnSave.addSelectionListener( new SelectionListener() {
766                         
767                         @Override
768                         public void widgetSelected(SelectionEvent arg0) {
769                                 MessageBox dialog = new MessageBox(shlNewAccount, SWT.ICON_INFORMATION | SWT.OK );
770                                 dialog.setText(Messages.NewAccountDialog_40);
771                                 dialog.setMessage(Messages.NewAccountDialog_41);
772                                 dialog.open();
773                                 
774                                 //In case of automatic password the
775                                 //FkManager takes a boolean after AutoPassLen telling if it should use all specials (true) or only those from the string in the next argument (autoPassSpecials) (false) 
776                                 //If then the no-specials radiobutton is selected, remove content of that string such that no specials are selected
777                                 if( allowedAutoSpecials == FkNewAccAutoSpecials.NONE)
778                                 {
779                                         autoPassSpecials = ""; //$NON-NLS-1$
780                                 }
781                                 
782                                 FkManager.getInstance().createAccount( strAccountName, strUserName, autoPassword, autoPassLen, (allowedAutoSpecials == FkNewAccAutoSpecials.ALL), autoPassSpecials, strPassword, seperatorTab, mySelf );
783                                 updatePage(FkNewAccStep.SAVING);
784                         }
785                         
786                         @Override
787                         public void widgetDefaultSelected(SelectionEvent arg0) {
788                                 
789                         }
790                 });
791                 
792                 Label lblAccName = new Label(composite, SWT.NONE);
793                 fd_lblAccountName.right = new FormAttachment(lblAccName, -6);
794                 FormData fd_lblAccName = new FormData();
795                 fd_lblAccName.right = new FormAttachment(0, 603);
796                 fd_lblAccName.top = new FormAttachment(0, 51);
797                 fd_lblAccName.left = new FormAttachment(0, 236);
798                 lblAccName.setLayoutData(fd_lblAccName);
799                 lblAccName.setText(strAccountName);
800                 
801                 Label lblUsrName = new Label(composite, SWT.NONE);
802                 FormData fd_lblUsrName = new FormData();
803                 fd_lblUsrName.right = new FormAttachment(0, 613);
804                 fd_lblUsrName.top = new FormAttachment(0, 80);
805                 fd_lblUsrName.left = new FormAttachment(0, 236);
806                 lblUsrName.setLayoutData(fd_lblUsrName);
807                 lblUsrName.setText(strUserName);
808                 
809                 Label lblPasswordInfo = new Label(composite, SWT.NONE);
810                 FormData fd_lblPasswordInfo = new FormData();
811                 fd_lblPasswordInfo.right = new FormAttachment(0, 603);
812                 fd_lblPasswordInfo.top = new FormAttachment(0, 109);
813                 fd_lblPasswordInfo.left = new FormAttachment(0, 236);
814                 lblPasswordInfo.setLayoutData(fd_lblPasswordInfo);
815                 
816                 String passInfo;
817                 if( autoPassword )
818                 {
819                         passInfo = Messages.NewAccountDialog_42 + autoPassLen + Messages.NewAccountDialog_43;
820                         if( allowedAutoSpecials == FkNewAccAutoSpecials.ALL )
821                         {
822                                 passInfo += Messages.NewAccountDialog_44;
823                         } else if( allowedAutoSpecials == FkNewAccAutoSpecials.SELECTED )
824                         {
825                                 passInfo += "{"+autoPassSpecials+ "}"; //$NON-NLS-1$ //$NON-NLS-2$
826                         } else {
827                                 passInfo += Messages.NewAccountDialog_45;
828                         }
829                         
830                 } else {
831                         passInfo =Messages.NewAccountDialog_47 + strPassword.length() +Messages.NewAccountDialog_48;
832                 }
833                 
834                 lblPasswordInfo.setText(passInfo);
835                 
836                 Label lblSeperatorInfo = new Label(composite, SWT.NONE);
837                 FormData fd_lblSeperatorInfo = new FormData();
838                 fd_lblSeperatorInfo.right = new FormAttachment(0, 603);
839                 fd_lblSeperatorInfo.top = new FormAttachment(0, 138);
840                 fd_lblSeperatorInfo.left = new FormAttachment(0, 236);
841                 lblSeperatorInfo.setLayoutData(fd_lblSeperatorInfo);
842                 
843                 String sepInfo;
844                 if( seperatorTab )
845                 {
846                         sepInfo = Messages.NewAccountDialog_49;
847                 } else {
848                         sepInfo = Messages.NewAccountDialog_50;
849                 }
850                 
851                 lblSeperatorInfo.setText(sepInfo);
852                 
853         Control[] controls = new Control[] { btnSave, button_9 };
854         composite.setTabList(controls); 
855
856         }
857         
858         void createSavingPage()
859         {
860                 composite = new Composite(shlNewAccount, SWT.NONE);
861                 composite.setLayout(new FormLayout());
862                 
863                 txtBUSYMSG = new Label(composite, SWT.NONE);
864                 FormData fd_txtBUSYMSG = new FormData();
865                 fd_txtBUSYMSG.bottom = new FormAttachment(0, 113);
866                 fd_txtBUSYMSG.top = new FormAttachment(0, 10);
867                 fd_txtBUSYMSG.right = new FormAttachment(100, -10);
868                 fd_txtBUSYMSG.left = new FormAttachment(0, 78);
869                 txtBUSYMSG.setLayoutData(fd_txtBUSYMSG);
870                 txtBUSYMSG.setText(Messages.NewAccountDialog_51);
871                 FormData fdAni = new FormData();
872                 fdAni.top = new FormAttachment(txtBUSYMSG);
873                 
874                 animation = new Animation(composite, SWT.NONE, 4);
875                 FormData fd_animation = new FormData();
876                 fd_animation.top = new FormAttachment(0, 10);
877                 fd_animation.left = new FormAttachment(0, 10);
878                 animation.setLayoutData(fd_animation);
879                 animation.setBounds(10, 32, 32, 32);
880                 animation.setVisible(true);
881                 animation.setPlaying(true);
882
883         }
884         
885         
886         private void updatePage(FkNewAccStep curPage)
887         {
888                 if(composite != null && !composite.isDisposed() )
889                 {
890                         composite.dispose();
891                 }
892
893                 switch(curPage)
894                 {
895                 case CLICKBTN:
896                         break;
897                 case NAMES:
898                         createNamePage();
899                         break;
900                 case PASSTYPE:
901                         createPassTypePage();
902                         break;
903                 case PASS_AUT:
904                         createPassAutPage();
905                         break;
906                 case PASS_MAN:
907                         createPassManPage();
908                         break;
909                 case REVIEW:
910                         createReviewPage();
911                         break;
912                 case SEPERATOR:
913                         createSeperatorPage();
914                         break;
915                 case SAVING:
916                         createSavingPage();
917                         break;
918
919                         
920                 }
921                 
922                 shlNewAccount.layout();
923         }
924         /**
925          * Create contents of the dialog.
926          */
927         private void createContents() {
928                 shlNewAccount = new Shell(getParent(), getStyle());
929                 shlNewAccount.setSize(625, 394);
930                 shlNewAccount.setText(Messages.NewAccountDialog_54);
931                 shlNewAccount.setLayout(new FillLayout(SWT.HORIZONTAL));
932                                 
933                 updatePage(FkNewAccStep.NAMES);
934
935         }
936
937         @Override
938         public void fkActionEvent(FkActionEvent event) {
939                 //System.out.println( "Event data:"+ event.data );
940                 MessageBox dialog;
941                 Boolean closeSelf=false;
942                 
943                 switch(event.type)
944                 {
945                 case ACTION_ABORTED:
946                         txtBUSYMSG.setText(Messages.NewAccountDialog_55);
947                         dialog = new MessageBox(shlNewAccount, SWT.ICON_WARNING);
948                         dialog.setText(Messages.NewAccountDialog_56);
949                         dialog.setMessage(Messages.NewAccountDialog_57);
950                         dialog.open();
951                         updatePage(FkNewAccStep.REVIEW);                        
952                         break;
953                 case ACTION_ERROR:
954                         txtBUSYMSG.setText(Messages.NewAccountDialog_58);
955                         dialog = new MessageBox(shlNewAccount, SWT.ICON_ERROR);
956                         dialog.setText(Messages.NewAccountDialog_59);
957                         dialog.setMessage(Messages.NewAccountDialog_60);
958                         dialog.open();
959                         closeSelf=true;
960                         break;
961                 case ACTION_OKAY:
962                         txtBUSYMSG.setText(Messages.NewAccountDialog_61);
963                         dialog = new MessageBox(shlNewAccount, SWT.ICON_INFORMATION);
964                         dialog.setText(Messages.NewAccountDialog_62);
965                         dialog.setMessage(Messages.NewAccountDialog_63);
966                         dialog.open();
967                         closeSelf=true;
968                         break;
969                 case ACTION_WAITING:
970                         txtBUSYMSG.setText(Messages.NewAccountDialog_64);
971                         break;
972                 case ACTION_WORKING:
973                         txtBUSYMSG.setText(Messages.NewAccountDialog_65);
974                         animation.setVisible(false);
975                         break;
976                 case STATE_ERROR:
977                         txtBUSYMSG.setText(Messages.NewAccountDialog_0);
978                         dialog = new MessageBox(shlNewAccount, SWT.ICON_ERROR);
979                         dialog.setText(Messages.NewAccountDialog_1);
980                         dialog.setMessage(Messages.NewAccountDialog_2);
981                         dialog.open();
982                         closeSelf=true;
983                         break;
984
985                 }
986                 
987                 if( !shlNewAccount.isDisposed() && closeSelf )
988                 {
989                         shlNewAccount.close();
990                 }
991         }
992 }