KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > person > edit > blockbased > special > PersonalDataBlockEditor


1 /*
2  * Created on Jan 21, 2005
3  * by alex
4  *
5  */

6 package com.nightlabs.ipanema.person.edit.blockbased.special;
7
8 import org.apache.log4j.Logger;
9 import org.eclipse.swt.layout.GridData;
10 import org.eclipse.swt.layout.GridLayout;
11 import org.eclipse.swt.widgets.Composite;
12 import org.eclipse.swt.widgets.Control;
13
14 import com.nightlabs.ipanema.person.AbstractPersonDataField;
15 import com.nightlabs.ipanema.person.PersonDataBlock;
16 import com.nightlabs.ipanema.person.PersonDataFieldNotFoundException;
17 import com.nightlabs.ipanema.person.PersonStruct;
18 import com.nightlabs.ipanema.person.edit.PersonDataFieldEditor;
19 import com.nightlabs.ipanema.person.edit.PersonDataFieldEditorFactoryRegistry;
20 import com.nightlabs.ipanema.person.edit.PersonDataFieldEditorNotFoundException;
21 import com.nightlabs.ipanema.person.edit.blockbased.ExpandableBlocksPersonEditor;
22 import com.nightlabs.ipanema.person.edit.blockbased.PersonDataBlockEditor;
23 import com.nightlabs.ipanema.person.edit.blockbased.PersonDataBlockEditorFactory;
24 import com.nightlabs.ipanema.person.id.PersonStructBlockID;
25 import com.nightlabs.ipanema.person.id.PersonStructFieldID;
26
27 /**
28  *
29  * @author Alexander Bieber <alex[AT]nightlabs[DOT]de>
30  *
31  */

32 public class PersonalDataBlockEditor extends PersonDataBlockEditor {
33
34     public static final Logger LOGGER = Logger.getLogger(PersonalDataBlockEditor.class);
35     
36     public PersonalDataBlockEditor(PersonDataBlock dataBlock, Composite parent, int style) {
37         super(dataBlock, parent, style);
38         try {
39             setLayoutData(new GridData(GridData.FILL_BOTH));
40             GridLayout thisLayout = new GridLayout();
41             thisLayout.horizontalSpacing = 2;
42             thisLayout.numColumns = 3;
43             thisLayout.verticalSpacing = 2;
44             thisLayout.makeColumnsEqualWidth = true;
45             this.setLayout(thisLayout);
46
47             createFieldEditors();
48             
49             this.layout();
50         } catch (Exception JavaDoc e) {
51             e.printStackTrace();
52         }
53     }
54     
55     private void createFieldEditors() {
56         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_NAME,3);
57         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_FIRSTNAME,3);
58         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_COMPANY,3);
59         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_SALUTATION,1);
60         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_TITLE,1);
61         addPersonalDataFieldEditor(PersonStruct.PERSONALDATA_DATEOFBIRTH,1);
62     }
63
64     private void addPersonalDataFieldEditor(PersonStructFieldID fieldID, int horizontalSpan)
65     {
66      
67         AbstractPersonDataField field = null;
68         try {
69             field = dataBlock.getPersonDataField(fieldID);
70         } catch (PersonDataFieldNotFoundException e) {
71             LOGGER.error("addPersonalDataFieldEditor(PersonStructFieldID fieldID) PersonDataField not found for fieldID continuing: "+fieldID.toString(),e);
72         }
73         PersonDataFieldEditor editor = null;
74         if (!hasFieldEditorFor(field)) {
75             try {
76                 editor = PersonDataFieldEditorFactoryRegistry.getSharedInstance().getNewEditorInstance(
77                     field,
78                     ExpandableBlocksPersonEditor.EDITORTYPE_BLOCK_BASED_EXPANDABLE
79                 );
80             } catch (PersonDataFieldEditorNotFoundException e1) {
81                 LOGGER.error("addPersonalDataFieldEditor(PersonStructFieldID fieldID) PersonDataFieldEditor not found for fieldID continuing: "+fieldID.toString(),e1);
82             }
83             Control editorControl = editor.createControl(this);
84             GridData editorLData = new GridData();
85             editorLData.horizontalSpan = horizontalSpan;
86             editorLData.grabExcessHorizontalSpace = true;
87             editorLData.horizontalAlignment = GridData.FILL;
88             editorControl.setLayoutData(editorLData);
89             addFieldEditor(field, editor);
90         }
91         else {
92             editor = getFieldEditor(field);
93         }
94         editor.setData(field);
95         editor.refresh();
96     }
97
98     /**
99      * @see com.nightlabs.ipanema.person.edit.blockbased.PersonDataBlockEditor#refresh(com.nightlabs.ipanema.person.PersonDataBlock)
100      */

101     public void refresh(PersonDataBlock block) {
102         this.dataBlock = block;
103         createFieldEditors();
104     }
105
106
107     public static class Factory implements PersonDataBlockEditorFactory {
108         /**
109          * @see com.nightlabs.ipanema.person.edit.blockbased.PersonDataBlockEditorFactory#getProviderStructBlockID()
110          */

111         public PersonStructBlockID getProviderStructBlockID() {
112             return PersonStruct.PERSONALDATA;
113         }
114         
115         /**
116          * @see com.nightlabs.ipanema.person.edit.blockbased.PersonDataBlockEditorFactory#createPersonDataBlockEditor(com.nightlabs.ipanema.person.PersonDataBlock, org.eclipse.swt.widgets.Composite, int)
117          */

118         public PersonDataBlockEditor createPersonDataBlockEditor(PersonDataBlock dataBlock, Composite parent, int style) {
119             return new PersonalDataBlockEditor(dataBlock,parent,style);
120         }
121     }
122 }
123
Popular Tags