1 56 57 package org.objectstyle.cayenne.dataview.dvmodeler; 58 59 import java.awt.BorderLayout ; 60 61 import javax.swing.DefaultComboBoxModel ; 62 import javax.swing.JCheckBox ; 63 import javax.swing.JComboBox ; 64 import javax.swing.JComponent ; 65 import javax.swing.JPanel ; 66 import javax.swing.JScrollPane ; 67 import javax.swing.JSpinner ; 68 import javax.swing.JTabbedPane ; 69 import javax.swing.JTextField ; 70 import javax.swing.SpinnerNumberModel ; 71 72 import com.jgoodies.forms.builder.DefaultFormBuilder; 73 import com.jgoodies.forms.factories.Borders; 74 import com.jgoodies.forms.layout.FormLayout; 75 import com.jgoodies.looks.Options; 76 77 83 84 public class FieldEditor extends JPanel { 85 ObjEntityViewField objEntityViewField; 86 private BorderLayout borderLayout = new BorderLayout (); 87 88 private JTextField viewNameField; 89 private JComboBox objEntityCombo; 90 private JTextField fieldNameField; 91 private JComboBox dataTypeCombo; 92 private JComboBox calcTypeCombo; 93 private JComboBox objAttributeCombo; 94 private JTextField defaultValueField; 95 private JTextField captionField; 96 private JCheckBox editableCheckBox; 97 private JCheckBox visibleCheckBox; 98 private JTextField displayPatternField; 99 private JTextField displayClassField; 100 private JTextField editPatternField; 101 private JTextField editClassField; 102 private JSpinner preferredIndexField; 103 private JComboBox lookupViewCombo; 104 private JComboBox lookupFieldCombo; 105 private JComboBox objRelationshipCombo; 106 107 private FieldEditorHelper fieldEditorHelper; 108 109 110 public FieldEditor() { 111 try { 112 jbInit(); 113 } 114 catch(Exception ex) { 115 ex.printStackTrace(); 116 } 117 fieldEditorHelper = new FieldEditorHelper(this); 118 } 119 void jbInit() throws Exception { 120 this.setLayout(borderLayout); 121 this.add(buildPanel(), BorderLayout.CENTER); 122 } 123 124 private void initComponents() { 125 viewNameField = new JTextField (); 126 objEntityCombo = new JComboBox (); 127 fieldNameField = new JTextField (); 128 dataTypeCombo = new JComboBox (new String [] { 129 "String", "Money", "Integer", "Double", "Percent", 130 "Date", "Datetime", "Boolean", "Object" }); 131 calcTypeCombo = new JComboBox (new String [] {"No Calculation", "Lookup"}); 132 lookupViewCombo = new JComboBox (); 133 lookupFieldCombo = new JComboBox (); 134 objRelationshipCombo = new JComboBox (); 135 objAttributeCombo = new JComboBox (); 136 defaultValueField = new JTextField (); 137 captionField = new JTextField (); 138 editableCheckBox = new JCheckBox ("", true); 139 visibleCheckBox = new JCheckBox ("", true); 140 displayClassField = new JTextField (); 141 displayPatternField = new JTextField (); 142 editClassField = new JTextField (); 143 editPatternField = new JTextField (); 144 SpinnerNumberModel preferredIndexNumberModel = new SpinnerNumberModel (-1, -1, 1024, 1); 145 preferredIndexField = new JSpinner (preferredIndexNumberModel); 146 } 147 148 149 private JComponent buildPanel() { 150 initComponents(); 151 152 FormLayout layout = new FormLayout( 153 "right:55dlu, 3dlu, 170dlu, 3dlu, " + 154 "right:25dlu, 3dlu, 55dlu", 155 ""); 156 DefaultFormBuilder generalBuilder = new DefaultFormBuilder(layout); 157 generalBuilder.setDefaultDialogBorder(); 158 159 generalBuilder.append("Name:", fieldNameField); 160 generalBuilder.append("Type:", dataTypeCombo); 161 generalBuilder.append("Default:", defaultValueField); 162 generalBuilder.appendUnrelatedComponentsGapRow(); 163 generalBuilder.nextLine(2); 164 165 generalBuilder.append("Calc Type:", calcTypeCombo); 166 generalBuilder.nextLine(); 167 generalBuilder.append("Attribute:", objAttributeCombo); 168 generalBuilder.nextLine(); 169 170 generalBuilder.appendSeparator("Value Lookup"); 171 172 generalBuilder.append("Relationship:", objRelationshipCombo); 173 generalBuilder.nextLine(); 174 generalBuilder.append("Lookup View:", lookupViewCombo); 175 generalBuilder.nextLine(); 176 generalBuilder.append("Lookup Field:", lookupFieldCombo); 177 178 layout = new FormLayout( 179 "right:55dlu, 3dlu, 170dlu, 3dlu, " + 180 "right:25dlu, 3dlu, pref", 181 ""); 182 DefaultFormBuilder displayBuilder = new DefaultFormBuilder(layout); 183 displayBuilder.setDefaultDialogBorder(); 184 185 displayBuilder.append("Caption:", captionField); 186 displayBuilder.append("Index:", preferredIndexField); 187 displayBuilder.append("Visible:", visibleCheckBox); 188 displayBuilder.nextLine(); 189 displayBuilder.append("Editable:", editableCheckBox); 190 displayBuilder.appendUnrelatedComponentsGapRow(); 191 displayBuilder.nextLine(2); 192 193 displayBuilder.append("Display Format:", displayClassField); 194 displayBuilder.nextLine(); 195 displayBuilder.append("Display Pattern:", displayPatternField); 196 displayBuilder.appendUnrelatedComponentsGapRow(); 197 displayBuilder.nextLine(2); 198 199 displayBuilder.append("Edit Format:", editClassField); 200 displayBuilder.nextLine(); 201 displayBuilder.append("Edit Pattern:", editPatternField); 202 203 JScrollPane generalScrollPane = new JScrollPane (generalBuilder.getPanel()); 204 generalScrollPane.setBorder(Borders.EMPTY_BORDER); 205 206 JScrollPane displayScrollPane = new JScrollPane (displayBuilder.getPanel()); 207 displayScrollPane.setBorder(Borders.EMPTY_BORDER); 208 209 JTabbedPane fieldPane = new JTabbedPane (JTabbedPane.BOTTOM); 210 fieldPane.putClientProperty(Options.NO_CONTENT_BORDER_KEY, Boolean.TRUE); 211 212 fieldPane.addTab("General", generalScrollPane); 213 fieldPane.addTab("Display", displayScrollPane); 214 215 return fieldPane; 216 } 217 218 public void setFieldProperties(ObjEntityViewField field){ 219 fieldEditorHelper.setObjEntityViewField(field); 220 221 objEntityViewField = field; 222 ObjEntityView objEntityView = field.getObjEntityView(); 223 viewNameField.setText(objEntityView.getName()); 224 225 fieldNameField.setText(field.getName()); 226 dataTypeCombo.setSelectedItem(field.getDataType()); 227 if (field.getCalcType().equals("nocalc")){ 228 calcTypeCombo.setSelectedItem("No Calculation"); 229 objRelationshipCombo.setModel(new DefaultComboBoxModel ()); 230 objRelationshipCombo.setEnabled(false); 231 lookupViewCombo.setModel(new DefaultComboBoxModel ()); 232 lookupViewCombo.setEnabled(false); 233 lookupFieldCombo.setModel(new DefaultComboBoxModel ()); 234 lookupFieldCombo.setEnabled(false); 235 } 236 if (field.getCalcType().equals("lookup")){ 237 calcTypeCombo.setSelectedItem("Lookup"); 238 objAttributeCombo.setModel(new DefaultComboBoxModel ()); 239 objAttributeCombo.setEnabled(false); 240 } 241 242 defaultValueField.setText(field.getDefaultValue()); 243 captionField.setText(field.getCaption()); 244 editableCheckBox.setSelected(field.getEditable()); 245 visibleCheckBox.setSelected(field.getVisible()); 246 displayClassField.setText(field.getDisplayFormat().getClassName()); 247 displayPatternField.setText(field.getDisplayFormat().getPattern()); 248 editClassField.setText(field.getEditFormat().getClassName()); 249 editPatternField.setText(field.getEditFormat().getPattern()); 250 preferredIndexField.setValue(new Integer (field.getPrefIndex())); 251 } 252 253 public ObjEntityViewField getObjEntityViewField(){ 254 return objEntityViewField; 255 } 256 257 public JTextField getViewNameField(){ 258 return viewNameField; 259 } 260 public JComboBox getObjEntityCombo(){ 261 return objEntityCombo; 262 } 263 264 public JTextField getFieldNameField(){ 265 return fieldNameField; 266 } 267 public JComboBox getDataTypeCombo(){ 268 return dataTypeCombo; 269 } 270 public JComboBox getCalcTypeCombo(){ 271 return calcTypeCombo; 272 } 273 public JComboBox getObjAttributeCombo(){ 274 return objAttributeCombo; 275 } 276 public JTextField getDefaultValueField(){ 277 return defaultValueField; 278 } 279 public JTextField getCaptionField(){ 280 return captionField; 281 } 282 public JCheckBox getEditableCheckBox(){ 283 return editableCheckBox; 284 } 285 public JCheckBox getVisibleCheckBox(){ 286 return visibleCheckBox; 287 } 288 public JTextField getDisplayClassField(){ 289 return displayClassField; 290 } 291 public JTextField getDisplayPatternField(){ 292 return displayPatternField; 293 } 294 public JTextField getEditClassField(){ 295 return editClassField; 296 } 297 public JTextField getEditPatternField(){ 298 return editPatternField; 299 } 300 public JSpinner getPreferredIndexField(){ 301 return preferredIndexField; 302 } 303 public JComboBox getLookupViewCombo(){ 304 return lookupViewCombo; 305 } 306 public JComboBox getLookupFieldCombo(){ 307 return lookupFieldCombo; 308 } 309 public JComboBox getObjRelationshipCombo(){ 310 return objRelationshipCombo; 311 } 312 313 public void setModels(DataMapTreeModel mapModel, 314 DataViewTreeModel viewModel, 315 FieldsTableModel tableModel){ 316 fieldEditorHelper.setModels(mapModel, viewModel, tableModel); 317 } 318 } 319 320 | Popular Tags |