KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > demo > ContactForm


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18 package sync4j.syncclient.demo;
19
20 import java.awt.Button JavaDoc;
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.CardLayout JavaDoc;
23 import java.awt.CheckboxGroup JavaDoc;
24 import java.awt.GridLayout JavaDoc;
25 import java.awt.Label JavaDoc;
26 import java.awt.Panel JavaDoc;
27 import java.awt.ScrollPane JavaDoc;
28 import java.awt.TextField JavaDoc;
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31 import java.awt.event.MouseEvent JavaDoc;
32 import java.awt.event.MouseListener JavaDoc;
33
34 import java.util.List JavaDoc;
35 import java.util.Iterator JavaDoc;
36
37 import sync4j.foundation.pdi.contact.Contact;
38 import sync4j.foundation.pdi.contact.Email;
39 import sync4j.foundation.pdi.contact.Note;
40 import sync4j.foundation.pdi.contact.Phone;
41 import sync4j.foundation.pdi.contact.Title;
42 import sync4j.foundation.pdi.contact.WebPage;
43 import sync4j.foundation.pdi.common.*;
44
45 /**
46  * A form containing all the fields concerning a contact.
47  * This form will be a subpanel for ContactModify and ContactNew
48  *
49  * @author Fabio Maggi @ Funambol
50  * @author Alessandro Morandi, Giorgio Orsi
51  * @version $Id: ContactForm.java,v 1.13 2005/05/27 11:08:34 luigiafassina Exp $
52  */

53 public class ContactForm extends Panel JavaDoc
54 implements ActionListener JavaDoc, MouseListener JavaDoc, ConfigurationParameters {
55
56     //---------------------------------------------------------- Constants
57

58     //
59
// Note this is NOT the actual size of the TextField.
60
// It's just a way to avoid horizontal scrolling
61
//
62
public static final int TF_COLUMNS = 10 ;
63     
64     private static final String JavaDoc TK_MOBILEPHONE = "MobileTelephoneNumber" ;
65     private static final String JavaDoc TK_HOMEPHONE = "HomeTelephoneNumber" ;
66     private static final String JavaDoc TK_HOME2PHONE = "Home2TelephoneNumber" ;
67     private static final String JavaDoc TK_HOMEFAX = "HomeFaxNumber" ;
68     private static final String JavaDoc TK_OTHERPHONE = "OtherTelephoneNumber" ;
69     private static final String JavaDoc TK_BUSINESSPHONE = "BusinessTelephoneNumber" ;
70     private static final String JavaDoc TK_BUSINESS2PHONE = "Business2TelephoneNumber";
71     private static final String JavaDoc TK_BUSINESSFAX = "BusinessFaxNumber" ;
72     private static final String JavaDoc TK_PAGERNUMBER = "PagerNumber" ;
73     private static final String JavaDoc TK_EMAIL1 = "Email1Address" ;
74     private static final String JavaDoc TK_EMAIL2 = "Email2Address" ;
75     private static final String JavaDoc TK_EMAIL3 = "Email3Address" ;
76
77     //---------------------------------------------------------- Private data
78

79     //
80
// The window containing this panel
81
//
82
private MainWindow mw = null;
83
84     private Language ln = new Language();
85     
86     //
87
// The currently displayed tab (general,personal,business)
88
//
89
private String JavaDoc currentTab = null;
90
91     private TextField JavaDoc tf2 = null;
92     private TextField JavaDoc tf3 = null;
93     private TextField JavaDoc tf4 = null;
94     private TextField JavaDoc tf5 = null;
95     private TextField JavaDoc tf6 = null;
96     private TextField JavaDoc tf7 = null;
97     private TextField JavaDoc tf11 = null;
98     private TextField JavaDoc tf13 = null;
99     private TextField JavaDoc tf14 = null;
100     private TextField JavaDoc tf15 = null;
101     private TextField JavaDoc tf16 = null;
102     private TextField JavaDoc tf17 = null;
103     private TextField JavaDoc tf19 = null;
104     private TextField JavaDoc tf20 = null;
105     private TextField JavaDoc tf22 = null;
106     private TextField JavaDoc tf23 = null;
107     private TextField JavaDoc tf24 = null;
108     private TextField JavaDoc tf25 = null;
109     private TextField JavaDoc tf31 = null;
110     private TextField JavaDoc tf32 = null;
111     private TextField JavaDoc tf33 = null;
112     private TextField JavaDoc tf34 = null;
113     private TextField JavaDoc tf35 = null;
114     private TextField JavaDoc tf36 = null;
115     private TextField JavaDoc tf37 = null;
116     private TextField JavaDoc tf38 = null;
117     private TextField JavaDoc tf39 = null;
118     private TextField JavaDoc tf41 = null;
119     private TextField JavaDoc tf42 = null;
120     private TextField JavaDoc tf45 = null;
121     private TextField JavaDoc tf46 = null;
122     private TextField JavaDoc tf47 = null;
123     private TextField JavaDoc tf48 = null;
124     private TextField JavaDoc tf49 = null;
125     private TextField JavaDoc tf50 = null;
126
127     private Button JavaDoc butGeneral = null;
128     private Button JavaDoc butPersonal = null;
129     private Button JavaDoc butBusiness = null;
130     private CardLayout JavaDoc cardLayout = null;
131     private Panel JavaDoc fieldPanel = null;
132     private ScrollPane JavaDoc scrollGeneralPane = null;
133     private ScrollPane JavaDoc scrollPersonalPane = null;
134     private ScrollPane JavaDoc scrollBusinessPane = null;
135
136     //---------------------------------------------------------- Public methods
137

138     public String JavaDoc getBirthdayDate() {
139         return tf19.getText();
140     }
141
142     /**
143      * Creates the form subpanel.
144      *
145      * @param mw the window containing this panel
146      */

147     public ContactForm(MainWindow mw) {
148
149         Panel JavaDoc generalPanel = null;
150         Panel JavaDoc personalPanel = null;
151         Panel JavaDoc businessPanel = null;
152
153         //
154
// Generic Labels
155
//
156
Label JavaDoc lb2 = null;
157         Label JavaDoc lb3 = null;
158         Label JavaDoc lb4 = null;
159         Label JavaDoc lb5 = null;
160         Label JavaDoc lb6 = null;
161         Label JavaDoc lb7 = null;
162         Label JavaDoc lb11 = null;
163
164         //
165
// Personal Labels
166
//
167
Label JavaDoc lb13 = null;
168         Label JavaDoc lb14 = null;
169         Label JavaDoc lb15 = null;
170         Label JavaDoc lb16 = null;
171         Label JavaDoc lb17 = null;
172         Label JavaDoc lb19 = null;
173         Label JavaDoc lb20 = null;
174         Label JavaDoc lb22 = null;
175         Label JavaDoc lb23 = null;
176         Label JavaDoc lb24 = null;
177         Label JavaDoc lb25 = null;
178
179         //
180
// Business Labels
181
//
182
Label JavaDoc lb31 = null;
183         Label JavaDoc lb32 = null;
184         Label JavaDoc lb33 = null;
185         Label JavaDoc lb34 = null;
186         Label JavaDoc lb35 = null;
187         Label JavaDoc lb36 = null;
188         Label JavaDoc lb37 = null;
189         Label JavaDoc lb38 = null;
190         Label JavaDoc lb39 = null;
191         Label JavaDoc lb41 = null;
192         Label JavaDoc lb42 = null;
193         Label JavaDoc lb45 = null;
194         Label JavaDoc lb46 = null;
195         Label JavaDoc lb47 = null;
196         Label JavaDoc lb48 = null;
197         Label JavaDoc lb49 = null;
198         Label JavaDoc lb50 = null;
199
200         this.mw = mw;
201
202         Panel JavaDoc buttonMenu = new Panel JavaDoc();
203         buttonMenu.setLayout(new GridLayout JavaDoc(1,3));
204
205         butGeneral = new Button JavaDoc (ln.getString("general") );
206         butGeneral.setActionCommand ("general" );
207         butGeneral.addActionListener (this );
208         butGeneral.setEnabled (false );
209         butPersonal = new Button JavaDoc (ln.getString("personal"));
210         butPersonal.setActionCommand ("personal" );
211         butPersonal.addActionListener(this );
212         butBusiness = new Button JavaDoc (ln.getString("business"));
213         butBusiness.setActionCommand ("business" );
214         butBusiness.addActionListener(this );
215
216         buttonMenu.add(butGeneral );
217         buttonMenu.add(butPersonal);
218         buttonMenu.add(butBusiness);
219
220         //
221
// Generic Textfields
222
//
223
tf2 = new TextField JavaDoc(TF_COLUMNS);
224         tf3 = new TextField JavaDoc(TF_COLUMNS);
225         tf4 = new TextField JavaDoc(TF_COLUMNS);
226         tf5 = new TextField JavaDoc(TF_COLUMNS);
227         tf6 = new TextField JavaDoc(TF_COLUMNS);
228         tf7 = new TextField JavaDoc(TF_COLUMNS);
229         tf11 = new TextField JavaDoc(TF_COLUMNS);
230
231         tf2.addMouseListener (this);
232         tf3.addMouseListener (this);
233         tf4.addMouseListener (this);
234         tf5.addMouseListener (this);
235         tf6.addMouseListener (this);
236         tf7.addMouseListener (this);
237         tf11.addMouseListener(this);
238
239         //
240
// Personal Textfields
241
//
242
tf13 = new TextField JavaDoc(TF_COLUMNS);
243         tf14 = new TextField JavaDoc(TF_COLUMNS);
244         tf15 = new TextField JavaDoc(TF_COLUMNS);
245         tf16 = new TextField JavaDoc(TF_COLUMNS);
246         tf17 = new TextField JavaDoc(TF_COLUMNS);
247         tf19 = new TextField JavaDoc(TF_COLUMNS);
248         tf20 = new TextField JavaDoc(TF_COLUMNS);
249         tf22 = new TextField JavaDoc(TF_COLUMNS);
250         tf23 = new TextField JavaDoc(TF_COLUMNS);
251         tf24 = new TextField JavaDoc(TF_COLUMNS);
252         tf25 = new TextField JavaDoc(TF_COLUMNS);
253
254         tf13.addMouseListener(this);
255         tf14.addMouseListener(this);
256         tf15.addMouseListener(this);
257         tf16.addMouseListener(this);
258         tf17.addMouseListener(this);
259         tf19.addMouseListener(this);
260         tf20.addMouseListener(this);
261         tf22.addMouseListener(this);
262         tf23.addMouseListener(this);
263         tf24.addMouseListener(this);
264         tf25.addMouseListener(this);
265
266         //
267
// Business Textfields
268
//
269
tf31 = new TextField JavaDoc(TF_COLUMNS);
270         tf32 = new TextField JavaDoc(TF_COLUMNS);
271         tf33 = new TextField JavaDoc(TF_COLUMNS);
272         tf34 = new TextField JavaDoc(TF_COLUMNS);
273         tf35 = new TextField JavaDoc(TF_COLUMNS);
274         tf36 = new TextField JavaDoc(TF_COLUMNS);
275         tf37 = new TextField JavaDoc(TF_COLUMNS);
276         tf38 = new TextField JavaDoc(TF_COLUMNS);
277         tf39 = new TextField JavaDoc(TF_COLUMNS);
278         tf41 = new TextField JavaDoc(TF_COLUMNS);
279         tf42 = new TextField JavaDoc(TF_COLUMNS);
280         tf45 = new TextField JavaDoc(TF_COLUMNS);
281         tf46 = new TextField JavaDoc(TF_COLUMNS);
282         tf47 = new TextField JavaDoc(TF_COLUMNS);
283         tf48 = new TextField JavaDoc(TF_COLUMNS);
284         tf49 = new TextField JavaDoc(TF_COLUMNS);
285         tf50 = new TextField JavaDoc(TF_COLUMNS);
286
287         tf31.addMouseListener(this);
288         tf32.addMouseListener(this);
289         tf33.addMouseListener(this);
290         tf34.addMouseListener(this);
291         tf35.addMouseListener(this);
292         tf36.addMouseListener(this);
293         tf37.addMouseListener(this);
294         tf38.addMouseListener(this);
295         tf39.addMouseListener(this);
296         tf41.addMouseListener(this);
297         tf42.addMouseListener(this);
298         tf45.addMouseListener(this);
299         tf46.addMouseListener(this);
300         tf47.addMouseListener(this);
301         tf48.addMouseListener(this);
302         tf49.addMouseListener(this);
303         tf50.addMouseListener(this);
304
305         //
306
// General Labels
307
//
308
lb2 = new Label JavaDoc(ln.getString("title" ));
309         lb3 = new Label JavaDoc(ln.getString("first_name" ));
310         lb4 = new Label JavaDoc(ln.getString("middle_name" ));
311         lb5 = new Label JavaDoc(ln.getString("last_name" ));
312         lb6 = new Label JavaDoc(ln.getString("suffix" ));
313         lb7 = new Label JavaDoc(ln.getString("nickname" ));
314         lb11 = new Label JavaDoc(ln.getString("note" ));
315
316         //
317
// Personal Labels
318
//
319
lb13 = new Label JavaDoc(ln.getString("street" ));
320         lb14 = new Label JavaDoc(ln.getString("city" ));
321         lb15 = new Label JavaDoc(ln.getString("state" ));
322         lb16 = new Label JavaDoc(ln.getString("postal_code" ));
323         lb17 = new Label JavaDoc(ln.getString("country" ));
324         lb19 = new Label JavaDoc(ln.getString("birthday" ));
325         lb20 = new Label JavaDoc(ln.getString("cell_phone" ));
326         lb22 = new Label JavaDoc(ln.getString("home_phone" ));
327         lb23 = new Label JavaDoc(ln.getString("home_phone2" ));
328         lb24 = new Label JavaDoc(ln.getString("home_fax" ));
329         lb25 = new Label JavaDoc(ln.getString("gen_phone" ));
330
331         //
332
// Business Labels
333
//
334
lb31 = new Label JavaDoc(ln.getString("street" ));
335         lb32 = new Label JavaDoc(ln.getString("city" ));
336         lb33 = new Label JavaDoc(ln.getString("state" ));
337         lb34 = new Label JavaDoc(ln.getString("postal_code" ));
338         lb35 = new Label JavaDoc(ln.getString("country" ));
339         lb36 = new Label JavaDoc(ln.getString("role" ));
340         lb37 = new Label JavaDoc(ln.getString("job_title" ));
341         lb38 = new Label JavaDoc(ln.getString("company" ));
342         lb39 = new Label JavaDoc(ln.getString("department" ));
343         lb41 = new Label JavaDoc(ln.getString("business_phone" ));
344         lb42 = new Label JavaDoc(ln.getString("business_phone2"));
345         lb45 = new Label JavaDoc(ln.getString("business_fax" ));
346         lb46 = new Label JavaDoc(ln.getString("pager_number" ));
347         lb47 = new Label JavaDoc(ln.getString("email1" ));
348         lb48 = new Label JavaDoc(ln.getString("email2" ));
349         lb49 = new Label JavaDoc(ln.getString("email3" ));
350         lb50 = new Label JavaDoc(ln.getString("webpage" ));
351
352         //
353
// Generic panel
354
//
355
generalPanel = new Panel JavaDoc();
356         generalPanel.setLayout(new GridLayout JavaDoc(17, 2));
357
358         generalPanel.add(lb2 );
359         generalPanel.add(tf2 );
360         generalPanel.add(lb3 );
361         generalPanel.add(tf3 );
362         generalPanel.add(lb4 );
363         generalPanel.add(tf4 );
364         generalPanel.add(lb5 );
365         generalPanel.add(tf5 );
366         generalPanel.add(lb6 );
367         generalPanel.add(tf6 );
368         generalPanel.add(lb7 );
369         generalPanel.add(tf7 );
370         generalPanel.add(lb11 );
371         generalPanel.add(tf11 );
372         generalPanel.add(new Label JavaDoc());
373         generalPanel.add(new Label JavaDoc());
374         generalPanel.add(new Label JavaDoc());
375         generalPanel.add(new Label JavaDoc());
376         generalPanel.add(new Label JavaDoc());
377         generalPanel.add(new Label JavaDoc());
378         generalPanel.add(new Label JavaDoc());
379         generalPanel.add(new Label JavaDoc());
380         generalPanel.add(new Label JavaDoc());
381         generalPanel.add(new Label JavaDoc());
382
383         //
384
// Personal panel
385
//
386
personalPanel = new Panel JavaDoc();
387         personalPanel.setLayout(new GridLayout JavaDoc(22, 2));
388
389         personalPanel.add(lb13 );
390         personalPanel.add(tf13 );
391         personalPanel.add(lb14 );
392         personalPanel.add(tf14 );
393         personalPanel.add(lb15 );
394         personalPanel.add(tf15 );
395         personalPanel.add(lb16 );
396         personalPanel.add(tf16 );
397         personalPanel.add(lb17 );
398         personalPanel.add(tf17 );
399         personalPanel.add(lb19 );
400         personalPanel.add(tf19 );
401         personalPanel.add(lb25 );
402         personalPanel.add(tf25 );
403         personalPanel.add(lb20 );
404         personalPanel.add(tf20 );
405         personalPanel.add(lb22 );
406         personalPanel.add(tf22 );
407         personalPanel.add(lb23 );
408         personalPanel.add(tf23 );
409         personalPanel.add(lb24 );
410         personalPanel.add(tf24 );
411         personalPanel.add(new Label JavaDoc());
412         personalPanel.add(new Label JavaDoc());
413         personalPanel.add(new Label JavaDoc());
414         personalPanel.add(new Label JavaDoc());
415         personalPanel.add(new Label JavaDoc());
416         personalPanel.add(new Label JavaDoc());
417         personalPanel.add(new Label JavaDoc());
418         personalPanel.add(new Label JavaDoc());
419         personalPanel.add(new Label JavaDoc());
420         personalPanel.add(new Label JavaDoc());
421
422         //
423
// Business panel
424
//
425
businessPanel = new Panel JavaDoc();
426         businessPanel.setLayout(new GridLayout JavaDoc(27, 2));
427
428         businessPanel.add(lb31 );
429         businessPanel.add(tf31 );
430         businessPanel.add(lb32 );
431         businessPanel.add(tf32 );
432         businessPanel.add(lb33 );
433         businessPanel.add(tf33 );
434         businessPanel.add(lb34 );
435         businessPanel.add(tf34 );
436         businessPanel.add(lb35 );
437         businessPanel.add(tf35 );
438         businessPanel.add(lb36 );
439         businessPanel.add(tf36 );
440         businessPanel.add(lb37 );
441         businessPanel.add(tf37 );
442         businessPanel.add(lb38 );
443         businessPanel.add(tf38 );
444         businessPanel.add(lb39 );
445         businessPanel.add(tf39 );
446         businessPanel.add(lb41 );
447         businessPanel.add(tf41 );
448         businessPanel.add(lb42 );
449         businessPanel.add(tf42 );
450         businessPanel.add(lb45 );
451         businessPanel.add(tf45 );
452         businessPanel.add(lb46 );
453         businessPanel.add(tf46 );
454         businessPanel.add(lb47 );
455         businessPanel.add(tf47 );
456         businessPanel.add(lb48 );
457         businessPanel.add(tf48 );
458         businessPanel.add(lb49 );
459         businessPanel.add(tf49 );
460         businessPanel.add(lb50 );
461         businessPanel.add(tf50 );
462         businessPanel.add(new Label JavaDoc());
463         businessPanel.add(new Label JavaDoc());
464         businessPanel.add(new Label JavaDoc());
465         businessPanel.add(new Label JavaDoc());
466         businessPanel.add(new Label JavaDoc());
467         businessPanel.add(new Label JavaDoc());
468         businessPanel.add(new Label JavaDoc());
469         businessPanel.add(new Label JavaDoc());
470         businessPanel.add(new Label JavaDoc());
471         businessPanel.add(new Label JavaDoc());
472
473         scrollGeneralPane = new ScrollPane JavaDoc(ScrollPane.SCROLLBARS_NEVER );
474         scrollGeneralPane.add(generalPanel );
475
476         scrollPersonalPane = new ScrollPane JavaDoc(ScrollPane.SCROLLBARS_NEVER );
477         scrollPersonalPane.add(personalPanel);
478
479         scrollBusinessPane = new ScrollPane JavaDoc(ScrollPane.SCROLLBARS_AS_NEEDED);
480         scrollBusinessPane.add(businessPanel);
481
482         fieldPanel = new Panel JavaDoc();
483         fieldPanel.setSize(100,100);
484         cardLayout = new CardLayout JavaDoc();
485         fieldPanel.setLayout(cardLayout);
486
487         fieldPanel.add(scrollGeneralPane , "general" );
488         fieldPanel.add(scrollPersonalPane, "personal");
489         fieldPanel.add(scrollBusinessPane, "business");
490
491         cardLayout.show(fieldPanel, "general");
492         currentTab = "general";
493
494         setLayout(new BorderLayout JavaDoc());
495
496         add (buttonMenu, BorderLayout.NORTH );
497         add (fieldPanel, BorderLayout.CENTER);
498     }
499
500     /**
501      * Invoked when an action occurs (i.e. a button is pressed).
502      *
503      * @param evt the occurred action
504      */

505     public void actionPerformed(ActionEvent JavaDoc evt) {
506
507         if (evt.getActionCommand().equals ("general")) {
508             butGeneral.setEnabled (false);
509             butPersonal.setEnabled(true );
510             butBusiness.setEnabled(true );
511             cardLayout.show(fieldPanel,"general");
512             currentTab = "general";
513         } else if (evt.getActionCommand().equals ("personal")) {
514             butGeneral.setEnabled (true );
515             butPersonal.setEnabled(false);
516             butBusiness.setEnabled(true );
517             cardLayout.show(fieldPanel,"personal");
518             currentTab = "personal";
519         } else if (evt.getActionCommand().equals ("business")) {
520             butGeneral.setEnabled (true );
521             butPersonal.setEnabled(true );
522             butBusiness.setEnabled(false);
523             cardLayout.show(fieldPanel,"business");
524             currentTab = "business";
525         }
526     }
527
528     /**
529      * Invoked when the mouse button has been clicked
530      * (pressed and released) on a component.
531      * This method adjusts the scrollpanes so that
532      * the selected textfield is placed
533      * on top of the pane.
534      *
535      * @param evt the occurred event
536      */

537     public void mouseClicked(MouseEvent JavaDoc evt) {
538         TextField JavaDoc tmptxt = (TextField JavaDoc)evt.getComponent();
539         if (currentTab.equals("business")) {
540             scrollBusinessPane.setScrollPosition(0, tmptxt.getLocation().y);
541         }
542     }
543
544     /**
545      * Invoked when a mouse button has been
546      * pressed on a component.
547      * Not used.
548      *
549      * @param evt the occurred event
550      */

551     public void mousePressed(MouseEvent JavaDoc evt) {
552         // do nothing
553
}
554
555     /**
556      * Invoked when a mouse button has been
557      * released on a component.
558      * Not used.
559      *
560      * @param evt the occurred event
561      */

562     public void mouseReleased(MouseEvent JavaDoc evt) {
563         // do nothing
564
}
565
566     /**
567      * Invoked when the mouse enters a component.
568      * Not used.
569      *
570      * @param evt the occurred event
571      */

572     public void mouseEntered(MouseEvent JavaDoc evt) {
573         // do nothing
574
}
575
576     /**
577      * Invoked when the mouse exits a component.
578      * Not used.
579      *
580      * @param evt the occurred event
581      */

582     public void mouseExited(MouseEvent JavaDoc evt) {
583         // do nothing
584
}
585
586     //---------------------------------------------------------- Protected methods
587

588     /**
589      * Sets the fields with the values contained in the specified Contact object.
590      * Used to display the old value of contact
591      *
592      * @param contact the Contact object which is the source of the values
593      */

594     protected void setFields(Contact contact) {
595
596         //
597
// General
598
//
599
tf2.setText((String JavaDoc)contact.getName().getSalutation().getPropertyValue());
600         tf3.setText((String JavaDoc)contact.getName().getFirstName().getPropertyValue());
601         tf4.setText((String JavaDoc)contact.getName().getMiddleName().getPropertyValue());
602         tf5.setText((String JavaDoc)contact.getName().getLastName().getPropertyValue());
603         tf6.setText((String JavaDoc)contact.getName().getSuffix().getPropertyValue());
604         tf7.setText((String JavaDoc)contact.getName().getNickname().getPropertyValue());
605
606         List JavaDoc notes = contact.getNotes();
607         if (notes != null && notes.size() > 0) {
608             Note tmpNote = (Note)notes.get(0);
609             tf11.setText((String JavaDoc)tmpNote.getPropertyValue());
610         } else {
611             tf11.setText("");
612         }
613
614         //
615
// Personal
616
//
617
tf13.setText((String JavaDoc)contact.getPersonalDetail()
618                              .getAddress().getStreet().getPropertyValue());
619         tf14.setText((String JavaDoc)contact.getPersonalDetail()
620                              .getAddress().getCity().getPropertyValue());
621         tf15.setText((String JavaDoc)contact.getPersonalDetail()
622                              .getAddress().getState().getPropertyValue());
623         tf16.setText((String JavaDoc)contact.getPersonalDetail()
624                              .getAddress().getPostalCode().getPropertyValue());
625         tf17.setText((String JavaDoc)contact.getPersonalDetail()
626                              .getAddress().getCountry().getPropertyValue());
627
628         String JavaDoc birthday = null;
629         birthday = FieldsHelper.convertBirthdayFrom(
630             (String JavaDoc)contact.getPersonalDetail().getBirthday()
631         );
632
633         if (birthday.length() > 10) {
634             birthday = birthday.substring(0, 10);
635         }
636
637         //
638
// 01/01/4501 is the dummy date of outlook...
639
//
640
if (birthday.indexOf("01/01/4501") != -1) {
641             birthday = "";
642         }
643
644         tf19.setText(birthday);
645
646         List JavaDoc phones = contact.getPersonalDetail().getPhones();
647
648         tf20.setText("");
649         tf22.setText("");
650         tf23.setText("");
651         tf24.setText("");
652         tf25.setText("");
653
654         if (phones != null) {
655             Iterator JavaDoc itPhones = phones.iterator();
656             while(itPhones.hasNext()) {
657                 Phone phone = (Phone)itPhones.next();
658                 if (phone.getPhoneType() == null) {
659                     continue;
660                 }
661                 if (phone.getPhoneType().equals(TK_MOBILEPHONE)) {
662                     tf20.setText((String JavaDoc)phone.getPropertyValue());
663                 } else if (phone.getPhoneType().equals(TK_HOMEPHONE)) {
664                     tf22.setText((String JavaDoc)phone.getPropertyValue());
665                 } else if (phone.getPhoneType().equals(TK_HOME2PHONE)) {
666                     tf23.setText((String JavaDoc)phone.getPropertyValue());
667                 } else if (phone.getPhoneType().equals(TK_HOMEFAX)) {
668                     tf24.setText((String JavaDoc)phone.getPropertyValue());
669                 } else if (phone.getPhoneType().equals(TK_OTHERPHONE)) {
670                     tf25.setText((String JavaDoc)phone.getPropertyValue());
671                 }
672             }
673         }
674         
675         //
676
// Business
677
//
678
tf31.setText((String JavaDoc)contact.getBusinessDetail()
679                              .getAddress().getStreet().getPropertyValue());
680         tf32.setText((String JavaDoc)contact.getBusinessDetail()
681                              .getAddress().getCity().getPropertyValue());
682         tf33.setText((String JavaDoc)contact.getBusinessDetail()
683                              .getAddress().getState().getPropertyValue());
684         tf34.setText((String JavaDoc)contact.getBusinessDetail()
685                              .getAddress().getPostalCode().getPropertyValue());
686         tf35.setText((String JavaDoc)contact.getBusinessDetail()
687                              .getAddress().getCountry().getPropertyValue());
688         tf36.setText((String JavaDoc)contact.getBusinessDetail()
689                              .getRole().getPropertyValue());
690         tf38.setText((String JavaDoc)contact.getBusinessDetail()
691                              .getCompany().getPropertyValue());
692         tf39.setText((String JavaDoc)contact.getBusinessDetail()
693                              .getDepartment().getPropertyValue());
694
695         List JavaDoc titles = contact.getBusinessDetail().getTitles();
696         if (titles != null && titles.size() > 0) {
697             Title title = (Title)titles.get(0);
698             tf37.setText((String JavaDoc)title.getPropertyValue());
699         } else {
700             tf37.setText("");
701         }
702         
703         List JavaDoc phonesBus = contact.getBusinessDetail().getPhones();
704
705         tf41.setText("");
706         tf42.setText("");
707         tf45.setText("");
708         tf46.setText("");
709
710         if (phonesBus != null) {
711             Iterator JavaDoc itPhones = phonesBus.iterator();
712             while(itPhones.hasNext()) {
713                 Phone phone = (Phone)itPhones.next();
714                 if (phone.getPhoneType() == null) {
715                     continue;
716                 }
717                 if (phone.getPhoneType().equals(TK_BUSINESSPHONE)) {
718                     tf41.setText((String JavaDoc)phone.getPropertyValue());
719                 } else if (phone.getPhoneType().equals(TK_BUSINESS2PHONE)) {
720                     tf42.setText((String JavaDoc)phone.getPropertyValue());
721                 } else if (phone.getPhoneType().equals(TK_BUSINESSFAX)) {
722                     tf45.setText((String JavaDoc)phone.getPropertyValue());
723                 } else if (phone.getPhoneType().equals(TK_PAGERNUMBER)) {
724                     tf46.setText((String JavaDoc)phone.getPropertyValue());
725                 }
726             }
727         }
728
729         tf47.setText("");
730         tf48.setText("");
731         tf49.setText("");
732
733         List JavaDoc emails = contact.getPersonalDetail().getEmails();
734
735         if (emails != null) {
736             Iterator JavaDoc itEmails = emails.iterator();
737             while(itEmails.hasNext()) {
738                 Email email = (Email)itEmails.next();
739                 if (email.getEmailType() == null) {
740                     continue;
741                 }
742                 if (email.getEmailType().equals(TK_EMAIL1)) {
743                     tf47.setText((String JavaDoc)email.getPropertyValue());
744                 } else if (email.getEmailType().equals(TK_EMAIL2)) {
745                     tf48.setText((String JavaDoc)email.getPropertyValue());
746                 }
747             }
748         }
749         
750         List JavaDoc emailsBus = contact.getBusinessDetail().getEmails();
751
752         if (emailsBus != null) {
753             Iterator JavaDoc itEmails = emailsBus.iterator();
754             while(itEmails.hasNext()) {
755                 Email email = (Email)itEmails.next();
756                 if (email.getEmailType() == null) {
757                     continue;
758                 }
759                 if (email.getEmailType().equals(TK_EMAIL3)) {
760                     tf49.setText((String JavaDoc)email.getPropertyValue());
761                 }
762             }
763         }
764
765         List JavaDoc webpages = contact.getBusinessDetail().getWebPages();
766         if (webpages != null && webpages.size() > 0) {
767             WebPage webpage = (WebPage)webpages.get(0);
768             tf50.setText((String JavaDoc)webpage.getPropertyValue());
769         } else {
770             tf50.setText("");
771         }
772     }
773
774     /**
775      * Returns a new Contact object containing the informations
776      * set in the textfields.
777      * This method also builds the LABELs from the provided addresses,
778      * when at least street, city, state, postal code and country are specified.
779      *
780      * @return the Contact object containing the informations set in the form
781      */

782     protected Contact getFields() {
783
784         Contact contact = new Contact ();
785         StringBuffer JavaDoc display_name = new StringBuffer JavaDoc("");
786         
787         //
788
// General
789
//
790
contact.getName().getSalutation().setPropertyValue(tf2.getText());
791         contact.getName().getFirstName ().setPropertyValue(tf3.getText());
792         contact.getName().getMiddleName().setPropertyValue(tf4.getText());
793         contact.getName().getLastName ().setPropertyValue(tf5.getText());
794         contact.getName().getSuffix ().setPropertyValue(tf6.getText());
795         contact.getName().getNickname ().setPropertyValue(tf7.getText());
796
797         String JavaDoc lastname = contact.getName().getLastName().getPropertyValueAsString();
798         String JavaDoc firstname = contact.getName().getFirstName().getPropertyValueAsString();
799         
800         if (lastname != null && !lastname.equals("")) {
801             display_name.append(lastname);
802         }
803         if (firstname != null && !firstname.equals("")) {
804             
805             if (!display_name.equals("")) {
806                 display_name.append(",");
807             }
808             display_name.append(firstname);
809         }
810
811         if (display_name.equals("")) {
812             display_name.append("Unknow");
813         }
814         contact.getName().getDisplayName().setPropertyValue(display_name.toString());
815
816         if (!tf11.getText().equals("")) {
817             Note tmpNote = new Note();
818             tmpNote.setPropertyValue(tf11.getText());
819             tmpNote.setNoteType("Body");
820             contact.addNote(tmpNote);
821         }
822
823         //
824
// Personal
825
//
826
if (!tf13.getText().equals("")) {
827             contact.getPersonalDetail().getAddress()
828                    .getStreet().setPropertyValue(tf13.getText());
829         }
830         if (!tf14.getText().equals("")) {
831             contact.getPersonalDetail().getAddress()
832                    .getCity().setPropertyValue(tf14.getText());
833         }
834         if (!tf15.getText().equals("")) {
835             contact.getPersonalDetail().getAddress()
836                    .getState().setPropertyValue(tf15.getText());
837         }
838         if (!tf16.getText().equals("")) {
839             contact.getPersonalDetail().getAddress()
840                    .getPostalCode().setPropertyValue(tf16.getText());
841         }
842         if (!tf17.getText().equals("")) {
843             contact.getPersonalDetail().getAddress()
844                    .getCountry().setPropertyValue(tf17.getText());
845         }
846         if (!tf19.getText().equals("")) {
847             try {
848                 contact.getPersonalDetail().setBirthday(
849                     FieldsHelper.convertBirthdayTo(tf19.getText())
850                 );
851             } catch(Exception JavaDoc e) {
852                 e.printStackTrace();
853             }
854         }
855         if (!tf20.getText().equals("")) {
856             Phone tmpPhone = new Phone();
857             tmpPhone.setPropertyValue(tf20.getText());
858             tmpPhone.setPhoneType(TK_MOBILEPHONE);
859             contact.getPersonalDetail().addPhone(tmpPhone);
860         }
861
862         if (!tf22.getText().equals("")) {
863             Phone tmpPhone = new Phone();
864             tmpPhone.setPropertyValue(tf22.getText());
865             tmpPhone.setPhoneType(TK_HOMEPHONE);
866             contact.getPersonalDetail().addPhone(tmpPhone);
867         }
868         if (!tf23.getText().equals("")) {
869             Phone tmpPhone = new Phone();
870             tmpPhone.setPropertyValue(tf23.getText());
871             tmpPhone.setPhoneType(TK_HOME2PHONE);
872             contact.getPersonalDetail().addPhone(tmpPhone);
873         }
874         if (!tf24.getText().equals("")) {
875             Phone tmpPhone = new Phone();
876             tmpPhone.setPropertyValue(tf24.getText());
877             tmpPhone.setPhoneType(TK_HOMEFAX);
878             contact.getPersonalDetail().addPhone(tmpPhone);
879         }
880         if (!tf25.getText().equals("")) {
881             Phone tmpPhone = new Phone();
882             tmpPhone.setPropertyValue(tf25.getText());
883             tmpPhone.setPhoneType(TK_OTHERPHONE);
884             contact.getPersonalDetail().addPhone(tmpPhone);
885         }
886
887         //
888
// Business
889
//
890
if (!tf31.getText().equals("")) {
891             contact.getBusinessDetail().getAddress()
892                    .getStreet().setPropertyValue(tf31.getText());
893         }
894         if (!tf32.getText().equals("")) {
895             contact.getBusinessDetail().getAddress()
896                    .getCity().setPropertyValue(tf32.getText());
897         }
898         if (!tf33.getText().equals("")) {
899             contact.getBusinessDetail().getAddress()
900                    .getState().setPropertyValue(tf33.getText());
901         }
902         if (!tf34.getText().equals("")) {
903             contact.getBusinessDetail().getAddress()
904                    .getPostalCode().setPropertyValue(tf34.getText());
905         }
906         if (!tf35.getText().equals("")) {
907             contact.getBusinessDetail().getAddress()
908                    .getCountry().setPropertyValue(tf35.getText());
909         }
910         if (!tf36.getText().equals("")) {
911             contact.getBusinessDetail()
912                    .getRole().setPropertyValue(tf36.getText());
913         }
914         if (!tf38.getText().equals("")) {
915             contact.getBusinessDetail()
916                    .getCompany().setPropertyValue(tf38.getText());
917         }
918         if (!tf39.getText().equals("")) {
919             contact.getBusinessDetail()
920                    .getDepartment().setPropertyValue(tf39.getText());
921         }
922         if (!tf37.getText().equals("")) {
923             Title tmpTitle = new Title();
924             tmpTitle.setPropertyValue(tf37.getText());
925             tmpTitle.setTitleType("JobTitle");
926             contact.getBusinessDetail().addTitle(tmpTitle);
927         }
928         if (!tf41.getText().equals("")) {
929             Phone tmpPhone = new Phone();
930             tmpPhone.setPropertyValue(tf41.getText());
931             tmpPhone.setPhoneType(TK_BUSINESSPHONE);
932             contact.getBusinessDetail().addPhone(tmpPhone);
933         }
934         if (!tf42.getText().equals("")) {
935             Phone tmpPhone = new Phone();
936             tmpPhone.setPropertyValue(tf42.getText());
937             tmpPhone.setPhoneType(TK_BUSINESS2PHONE);
938             contact.getBusinessDetail().addPhone(tmpPhone);
939         }
940         if (!tf45.getText().equals("")) {
941             Phone tmpPhone = new Phone();
942             tmpPhone.setPropertyValue(tf45.getText());
943             tmpPhone.setPhoneType(TK_BUSINESSFAX);
944             contact.getBusinessDetail().addPhone(tmpPhone);
945         }
946         if (!tf46.getText().equals("")) {
947             Phone tmpPhone = new Phone();
948             tmpPhone.setPropertyValue(tf46.getText());
949             tmpPhone.setPhoneType(TK_PAGERNUMBER);
950             contact.getBusinessDetail().addPhone(tmpPhone);
951         }
952         if (!tf47.getText().equals("")) {
953             Email tmpEmail = new Email();
954             tmpEmail.setPropertyValue(tf47.getText());
955             tmpEmail.setEmailType(TK_EMAIL1);
956             contact.getPersonalDetail().addEmail(tmpEmail);
957         }
958         if (!tf48.getText().equals("")) {
959             Email tmpEmail = new Email();
960             tmpEmail.setPropertyValue(tf48.getText());
961             tmpEmail.setEmailType(TK_EMAIL2);
962             contact.getPersonalDetail().addEmail(tmpEmail);
963         }
964         if (!tf49.getText().equals("")) {
965             Email tmpEmail = new Email();
966             tmpEmail.setPropertyValue(tf49.getText());
967             tmpEmail.setEmailType(TK_EMAIL3);
968             contact.getBusinessDetail().addEmail(tmpEmail);
969         }
970
971         if (!tf50.getText().equals("")) {
972             WebPage tmpWebPage = new WebPage();
973             tmpWebPage.setPropertyValue(tf50.getText());
974             tmpWebPage.setWebPageType("BusinessWebPage");
975             contact.getBusinessDetail().addWebPage(tmpWebPage);
976         }
977
978         //
979
// Personal Label(all fields are mandatory except POBox)
980
//
981
if (!tf13.getText().equals("") &&
982             !tf14.getText().equals("") && !tf15.getText().equals("") &&
983             !tf16.getText().equals("") && !tf17.getText().equals("")) {
984             StringBuffer JavaDoc tmpPersonalLabel = new StringBuffer JavaDoc("");
985
986             //
987
// Street
988
//
989
tmpPersonalLabel.append(tf13.getText()).append("\r\n");
990             //
991
// City
992
//
993
tmpPersonalLabel.append(tf14.getText()).append(", ");
994             //
995
// State
996
//
997
tmpPersonalLabel.append(tf15.getText()).append(" ");
998             //
999
// PostalCode
1000
//
1001
tmpPersonalLabel.append(tf16.getText()).append("\r\n");
1002            //
1003
// Country
1004
//
1005
tmpPersonalLabel.append(tf17.getText());
1006            contact.getPersonalDetail()
1007                   .getAddress()
1008                   .getLabel().setPropertyValue(tmpPersonalLabel.toString());
1009        }
1010
1011        //
1012
// Business Label(all fields are mandatory except POBox and RoomNumber)
1013
//
1014
if (!tf31.getText().equals("") &&
1015            !tf32.getText().equals("") && !tf33.getText().equals("") &&
1016            !tf34.getText().equals("") && !tf35.getText().equals("")) {
1017            StringBuffer JavaDoc tmpBusinessLabel = new StringBuffer JavaDoc("");
1018
1019            //
1020
// Street
1021
//
1022
tmpBusinessLabel.append(tf31.getText()).append("\r\n");
1023            //
1024
// City
1025
//
1026
tmpBusinessLabel.append(tf32.getText()).append(", ");
1027            //
1028
// State
1029
//
1030
tmpBusinessLabel.append(tf33.getText()).append(" ");
1031            //
1032
// PostalCode
1033
//
1034
tmpBusinessLabel.append(tf34.getText()).append("\r\n");
1035            //
1036
// Country
1037
//
1038
tmpBusinessLabel.append(tf35.getText());
1039            contact.getBusinessDetail()
1040                   .getAddress()
1041                   .getLabel().setPropertyValue(tmpBusinessLabel.toString());
1042        }
1043
1044        return contact;
1045    }
1046
1047    /**
1048     * Sets all the textfields to an empty string.
1049     */

1050    protected void blankFields() {
1051
1052        tf2.setText ("");
1053        tf3.setText ("");
1054        tf4.setText ("");
1055        tf5.setText ("");
1056        tf6.setText ("");
1057        tf7.setText ("");
1058        tf11.setText("");
1059        tf13.setText("");
1060        tf14.setText("");
1061        tf15.setText("");
1062        tf16.setText("");
1063        tf17.setText("");
1064        tf19.setText("");
1065        tf20.setText("");
1066        tf22.setText("");
1067        tf23.setText("");
1068        tf24.setText("");
1069        tf25.setText("");
1070        tf31.setText("");
1071        tf32.setText("");
1072        tf33.setText("");
1073        tf34.setText("");
1074        tf35.setText("");
1075        tf36.setText("");
1076        tf37.setText("");
1077        tf38.setText("");
1078        tf39.setText("");
1079        tf41.setText("");
1080        tf42.setText("");
1081        tf45.setText("");
1082        tf46.setText("");
1083        tf47.setText("");
1084        tf48.setText("");
1085        tf49.setText("");
1086        tf50.setText("");
1087    }
1088
1089}
Popular Tags