KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectstyle > cayenne > dataview > dvmodeler > FieldEditor


1 /* ====================================================================
2  *
3  * The ObjectStyle Group Software License, version 1.1
4  * ObjectStyle Group - http://objectstyle.org/
5  *
6  * Copyright (c) 2002-2005, Andrei (Andrus) Adamchik and individual authors
7  * of the software. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if any,
22  * must include the following acknowlegement:
23  * "This product includes software developed by independent contributors
24  * and hosted on ObjectStyle Group web site (http://objectstyle.org/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The names "ObjectStyle Group" and "Cayenne" must not be used to endorse
29  * or promote products derived from this software without prior written
30  * permission. For written permission, email
31  * "andrus at objectstyle dot org".
32  *
33  * 5. Products derived from this software may not be called "ObjectStyle"
34  * or "Cayenne", nor may "ObjectStyle" or "Cayenne" appear in their
35  * names without prior written permission.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE OBJECTSTYLE GROUP OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals and hosted on ObjectStyle Group web site. For more
53  * information on the ObjectStyle Group, please see
54  * <http://objectstyle.org/>.
55  */

56
57 package org.objectstyle.cayenne.dataview.dvmodeler;
58
59 import java.awt.BorderLayout JavaDoc;
60
61 import javax.swing.DefaultComboBoxModel JavaDoc;
62 import javax.swing.JCheckBox JavaDoc;
63 import javax.swing.JComboBox JavaDoc;
64 import javax.swing.JComponent JavaDoc;
65 import javax.swing.JPanel JavaDoc;
66 import javax.swing.JScrollPane JavaDoc;
67 import javax.swing.JSpinner JavaDoc;
68 import javax.swing.JTabbedPane JavaDoc;
69 import javax.swing.JTextField JavaDoc;
70 import javax.swing.SpinnerNumberModel JavaDoc;
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 /**
78  *
79  * @author Nataliya Kholodna
80  * @author Andriy Shapochka
81  * @version 1.0
82  */

83
84 public class FieldEditor extends JPanel JavaDoc {
85   ObjEntityViewField objEntityViewField;
86   private BorderLayout JavaDoc borderLayout = new BorderLayout JavaDoc();
87
88   private JTextField JavaDoc viewNameField;
89   private JComboBox JavaDoc objEntityCombo;
90   private JTextField JavaDoc fieldNameField;
91   private JComboBox JavaDoc dataTypeCombo;
92   private JComboBox JavaDoc calcTypeCombo;
93   private JComboBox JavaDoc objAttributeCombo;
94   private JTextField JavaDoc defaultValueField;
95   private JTextField JavaDoc captionField;
96   private JCheckBox JavaDoc editableCheckBox;
97   private JCheckBox JavaDoc visibleCheckBox;
98   private JTextField JavaDoc displayPatternField;
99   private JTextField JavaDoc displayClassField;
100   private JTextField JavaDoc editPatternField;
101   private JTextField JavaDoc editClassField;
102   private JSpinner JavaDoc preferredIndexField;
103   private JComboBox JavaDoc lookupViewCombo;
104   private JComboBox JavaDoc lookupFieldCombo;
105   private JComboBox JavaDoc objRelationshipCombo;
106
107   private FieldEditorHelper fieldEditorHelper;
108
109
110   public FieldEditor() {
111     try {
112       jbInit();
113     }
114     catch(Exception JavaDoc ex) {
115       ex.printStackTrace();
116     }
117     fieldEditorHelper = new FieldEditorHelper(this);
118   }
119   void jbInit() throws Exception JavaDoc {
120     this.setLayout(borderLayout);
121     this.add(buildPanel(), BorderLayout.CENTER);
122   }
123
124   private void initComponents() {
125     viewNameField = new JTextField JavaDoc();
126     objEntityCombo = new JComboBox JavaDoc();
127     fieldNameField = new JTextField JavaDoc();
128     dataTypeCombo = new JComboBox JavaDoc(new String JavaDoc[] {
129       "String", "Money", "Integer", "Double", "Percent",
130       "Date", "Datetime", "Boolean", "Object" });
131     calcTypeCombo = new JComboBox JavaDoc(new String JavaDoc[] {"No Calculation", "Lookup"});
132     lookupViewCombo = new JComboBox JavaDoc();
133     lookupFieldCombo = new JComboBox JavaDoc();
134     objRelationshipCombo = new JComboBox JavaDoc();
135     objAttributeCombo = new JComboBox JavaDoc();
136     defaultValueField = new JTextField JavaDoc();
137     captionField = new JTextField JavaDoc();
138     editableCheckBox = new JCheckBox JavaDoc("", true);
139     visibleCheckBox = new JCheckBox JavaDoc("", true);
140     displayClassField = new JTextField JavaDoc();
141     displayPatternField = new JTextField JavaDoc();
142     editClassField = new JTextField JavaDoc();
143     editPatternField = new JTextField JavaDoc();
144     SpinnerNumberModel JavaDoc preferredIndexNumberModel = new SpinnerNumberModel JavaDoc(-1, -1, 1024, 1);
145     preferredIndexField = new JSpinner JavaDoc(preferredIndexNumberModel);
146   }
147
148
149   private JComponent JavaDoc 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 JavaDoc generalScrollPane = new JScrollPane JavaDoc(generalBuilder.getPanel());
204     generalScrollPane.setBorder(Borders.EMPTY_BORDER);
205
206     JScrollPane JavaDoc displayScrollPane = new JScrollPane JavaDoc(displayBuilder.getPanel());
207     displayScrollPane.setBorder(Borders.EMPTY_BORDER);
208
209     JTabbedPane JavaDoc fieldPane = new JTabbedPane JavaDoc(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 JavaDoc());
230       objRelationshipCombo.setEnabled(false);
231       lookupViewCombo.setModel(new DefaultComboBoxModel JavaDoc());
232       lookupViewCombo.setEnabled(false);
233       lookupFieldCombo.setModel(new DefaultComboBoxModel JavaDoc());
234       lookupFieldCombo.setEnabled(false);
235     }
236     if (field.getCalcType().equals("lookup")){
237       calcTypeCombo.setSelectedItem("Lookup");
238       objAttributeCombo.setModel(new DefaultComboBoxModel JavaDoc());
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 JavaDoc(field.getPrefIndex()));
251   }
252
253   public ObjEntityViewField getObjEntityViewField(){
254     return objEntityViewField;
255   }
256
257   public JTextField JavaDoc getViewNameField(){
258     return viewNameField;
259   }
260   public JComboBox JavaDoc getObjEntityCombo(){
261     return objEntityCombo;
262   }
263
264   public JTextField JavaDoc getFieldNameField(){
265     return fieldNameField;
266   }
267   public JComboBox JavaDoc getDataTypeCombo(){
268     return dataTypeCombo;
269   }
270   public JComboBox JavaDoc getCalcTypeCombo(){
271     return calcTypeCombo;
272   }
273   public JComboBox JavaDoc getObjAttributeCombo(){
274     return objAttributeCombo;
275   }
276   public JTextField JavaDoc getDefaultValueField(){
277     return defaultValueField;
278   }
279   public JTextField JavaDoc getCaptionField(){
280     return captionField;
281   }
282   public JCheckBox JavaDoc getEditableCheckBox(){
283     return editableCheckBox;
284   }
285   public JCheckBox JavaDoc getVisibleCheckBox(){
286     return visibleCheckBox;
287   }
288   public JTextField JavaDoc getDisplayClassField(){
289     return displayClassField;
290   }
291   public JTextField JavaDoc getDisplayPatternField(){
292     return displayPatternField;
293   }
294   public JTextField JavaDoc getEditClassField(){
295     return editClassField;
296   }
297   public JTextField JavaDoc getEditPatternField(){
298     return editPatternField;
299   }
300   public JSpinner JavaDoc getPreferredIndexField(){
301     return preferredIndexField;
302   }
303   public JComboBox JavaDoc getLookupViewCombo(){
304     return lookupViewCombo;
305   }
306   public JComboBox JavaDoc getLookupFieldCombo(){
307     return lookupFieldCombo;
308   }
309   public JComboBox JavaDoc 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