Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / FPanelCreateField.java @ 6837

History | View | Annotate | Download (9.94 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package com.iver.cit.gvsig.gui.panels;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.LayoutManager;
45
import java.awt.event.ActionListener;
46
import java.sql.Types;
47
import java.text.ParseException;
48
import java.util.Vector;
49

    
50
import javax.swing.JComboBox;
51
import javax.swing.JLabel;
52
import javax.swing.JPanel;
53
import javax.swing.JTextField;
54

    
55
import org.gvsig.gui.beans.AcceptCancelPanel;
56

    
57
import com.hardcode.gdbms.engine.instruction.SemanticException;
58
import com.hardcode.gdbms.engine.values.ValueFactory;
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.ui.mdiManager.View;
61
import com.iver.andami.ui.mdiManager.ViewInfo;
62
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
63
import java.awt.GridLayout;
64

    
65
public class FPanelCreateField extends JPanel implements View {
66

    
67
        private static final String DEFAULT_FIELD_LENGTH = "50";
68
        private JLabel jLblFieldName = null;
69
        private JTextField jTxtFieldName = null;
70
        private JLabel jLblFieldType = null;
71
        private JComboBox jCboFieldType = null;
72
        private JLabel jLblFieldLength = null;
73
        private JTextField jTxtFieldLength = null;
74
        private JLabel jLblFieldPrecision = null;
75
        private JTextField jTxtFieldPrecision = null;
76
        private JLabel jLblDefaultValue = null;
77
        private JTextField jTxtDefaultValue = null;
78
        private ViewInfo viewInfo;
79
        private JPanel jPanel = null;  //  @jve:decl-index=0:visual-constraint="299,27"
80
        private AcceptCancelPanel jPanelOkCancel = null;
81
        private JPanel jPnlFields = null;
82
        public FPanelCreateField() {
83
                super();
84
                // TODO Auto-generated constructor stub
85
                initialize();
86
        }
87

    
88
        public FPanelCreateField(boolean isDoubleBuffered) {
89
                super(isDoubleBuffered);
90
                // TODO Auto-generated constructor stub
91
                initialize();
92
        }
93

    
94
        public FPanelCreateField(LayoutManager layout) {
95
                super(layout);
96
                // TODO Auto-generated constructor stub
97
                initialize();
98
        }
99

    
100
        public FPanelCreateField(LayoutManager layout, boolean isDoubleBuffered) {
101
                super(layout, isDoubleBuffered);
102
                // TODO Auto-generated constructor stub
103
                initialize();
104
        }
105

    
106
        public ViewInfo getViewInfo() {
107
                if (viewInfo == null)
108
                {
109
                        viewInfo = new ViewInfo(ViewInfo.MODALDIALOG);
110
                        viewInfo.setWidth(this.getWidth()+8);
111
                        viewInfo.setHeight(this.getHeight());
112
                        viewInfo.setTitle(PluginServices.getText(this, "field_properties"));
113
                }
114
                return viewInfo;
115
        }
116

    
117
        /**
118
         * This method initializes this
119
         *
120
         * @return void
121
         */
122
        private void initialize() {
123

    
124
                this.setLayout(new BorderLayout());
125
                this.setSize(300, 210);
126
                this.setPreferredSize(new java.awt.Dimension(300,210));
127
                this.add(getJPanel(), java.awt.BorderLayout.CENTER);
128
                this.add(getJPanelOkCancel(), java.awt.BorderLayout.SOUTH);
129

    
130
        }
131

    
132
        /**
133
         * This method initializes jTxtFieldName
134
         *
135
         * @return javax.swing.JTextField
136
         */
137
        private JTextField getJTxtFieldName() {
138
                if (jTxtFieldName == null) {
139
                        jTxtFieldName = new JTextField();
140
                        jTxtFieldName.setBounds(new java.awt.Rectangle(147,15,138,22));
141
                }
142
                return jTxtFieldName;
143
        }
144

    
145
        /**
146
         * This method initializes jCboFieldType
147
         *
148
         * @return javax.swing.JComboBox
149
         */
150
        private JComboBox getJCboFieldType() {
151
                if (jCboFieldType == null) {
152
                        jCboFieldType = new JComboBox();
153
                        jCboFieldType.setBounds(new java.awt.Rectangle(147,52,138,22));
154
                        jCboFieldType.addItem("Boolean");
155
                        jCboFieldType.addItem("Date");
156
                        jCboFieldType.addItem("Integer");
157
                        jCboFieldType.addItem("Double");
158
                        jCboFieldType.addItem("String");
159

    
160
                        jCboFieldType.setSelectedIndex(4);
161
                        jCboFieldType.addActionListener(new java.awt.event.ActionListener() {
162
                                public void actionPerformed(java.awt.event.ActionEvent e) {
163
                                        // System.out.println("actionPerformed()" + e.getActionCommand()); // TODO Auto-generated Event stub actionPerformed()
164
                                        String strType = (String) getJCboFieldType().getModel().getSelectedItem();
165
                                        int fieldType = FieldDescription.stringToType(strType);
166
                                        getJTxtFieldPrecision().setEnabled((fieldType == Types.DOUBLE));
167
                                        if (fieldType == Types.BOOLEAN)
168
                                        {
169
                                                getJTxtFieldLength().setText("0");
170
                                                getJTxtFieldLength().setEnabled(false);
171
                                        }
172
                                        else
173
                                                getJTxtFieldLength().setEnabled(true);
174

    
175
                                }
176
                        });
177

    
178
                }
179
                return jCboFieldType;
180
        }
181

    
182
        /**
183
         * This method initializes jTxtFieldLength
184
         *
185
         * @return javax.swing.JTextField
186
         */
187
        private JTextField getJTxtFieldLength() {
188
                if (jTxtFieldLength == null) {
189
                        jTxtFieldLength = new JTextField();
190
                        jTxtFieldLength.setBounds(new java.awt.Rectangle(147,89,138,22));
191
                        jTxtFieldLength.setText(DEFAULT_FIELD_LENGTH);
192
                }
193
                return jTxtFieldLength;
194
        }
195

    
196
        /**
197
         * This method initializes jTxtFieldPrecision
198
         *
199
         * @return javax.swing.JTextField
200
         */
201
        private JTextField getJTxtFieldPrecision() {
202
                if (jTxtFieldPrecision == null) {
203
                        jTxtFieldPrecision = new JTextField();
204
                        jTxtFieldPrecision.setBounds(new java.awt.Rectangle(147,126,138,22));
205
                        jTxtFieldPrecision.setEnabled(false);
206
                }
207
                return jTxtFieldPrecision;
208
        }
209

    
210
        /**
211
         * This method initializes jTxtDefaultValue
212
         *
213
         * @return javax.swing.JTextField
214
         */
215
        private JTextField getJTxtDefaultValue() {
216
                if (jTxtDefaultValue == null) {
217
                        jTxtDefaultValue = new JTextField();
218
                        jTxtDefaultValue.setBounds(new java.awt.Rectangle(147,163,138,22));
219
                }
220
                return jTxtDefaultValue;
221
        }
222

    
223
        public FieldDescription getFieldDescription() throws ParseException
224
        {
225
                FieldDescription newField = new FieldDescription();
226
                newField.setFieldName(getJTxtFieldName().getText());
227
                String strType = (String) getJCboFieldType().getModel().getSelectedItem();
228
                int fieldType = FieldDescription.stringToType(strType);
229
                newField.setFieldType(fieldType);
230
                try {
231
                        int fieldLength = Integer.parseInt(getJTxtFieldLength().getText());
232
                        newField.setFieldLength(fieldLength);
233
                } catch (Exception e) {
234
                        throw new ParseException(e.getMessage(), 0);
235
                }
236

    
237
                if (fieldType == Types.DOUBLE)
238
                {
239
                        newField.setFieldDecimalCount(
240
                                        Integer.parseInt(
241
                                                        getJTxtFieldPrecision().getText()));
242
                }
243
                else
244
                        newField.setFieldDecimalCount(0);
245
                String defaultValue = getJTxtDefaultValue().getText();
246
                if (defaultValue != null)
247
                {
248

    
249
                        if (defaultValue.compareTo("")==0)
250
                                newField.setDefaultValue(ValueFactory.createNullValue());
251
                        else
252
                                newField.setDefaultValue(ValueFactory.createValueByType(defaultValue, fieldType));
253
                }
254

    
255
                return newField;
256
        }
257

    
258
        public void setOkAction(ActionListener okAction) {
259
                getJPanelOkCancel().setOkButtonActionListener(okAction);
260

    
261
        }
262

    
263
        /**
264
         * This method initializes jPanel
265
         *
266
         * @return javax.swing.JPanel
267
         */
268
        private JPanel getJPanel() {
269
                if (jPanel == null) {
270
                        jPanel = new JPanel();
271
                        jPanel.setLayout(null);
272

    
273
                        jPanel.add(getJPnlFields(), null);
274
                }
275
                return jPanel;
276
        }
277

    
278
        /**
279
         * This method initializes jPanelOkCancel
280
         *
281
         * @return javax.swing.JPanel
282
         */
283
        private AcceptCancelPanel getJPanelOkCancel() {
284
                if (jPanelOkCancel == null) {
285
                        jPanelOkCancel = new AcceptCancelPanel();
286
                        jPanelOkCancel.setCancelButtonActionListener(new ActionListener(){
287
                                public void actionPerformed(java.awt.event.ActionEvent e) {
288
                                        PluginServices.getMDIManager().closeView(FPanelCreateField.this);
289
                                };
290
                        });
291
                        jPanelOkCancel.setPreferredSize(new java.awt.Dimension(10,50));
292
                }
293
                return jPanelOkCancel;
294
        }
295

    
296
        /**
297
         * This method initializes jPnlFields
298
         *
299
         * @return javax.swing.JPanel
300
         */
301
        private JPanel getJPnlFields() {
302
                if (jPnlFields == null) {
303
                        GridLayout gridLayout = new GridLayout();
304
                        gridLayout.setRows(6);
305
                        gridLayout.setVgap(3);
306
                        gridLayout.setHgap(5);
307
                        gridLayout.setColumns(2);
308
                        jPnlFields = new JPanel();
309
                        jPnlFields.setLayout(gridLayout);
310
                        jPnlFields.setBounds(new java.awt.Rectangle(5,12,290,142));
311
                        jLblDefaultValue = new JLabel();
312
                        jLblDefaultValue.setBounds(new java.awt.Rectangle(14,163,125,22));
313
                        jLblDefaultValue.setText(PluginServices.getText(this, "default_value"));
314
                        jLblFieldPrecision = new JLabel();
315
                        jLblFieldPrecision.setBounds(new java.awt.Rectangle(14,126,112,22));
316
                        jLblFieldPrecision.setText(PluginServices.getText(this, "precision"));
317
                        jLblFieldLength = new JLabel();
318
                        jLblFieldLength.setBounds(new java.awt.Rectangle(14,89,99,22));
319
                        jLblFieldLength.setText(PluginServices.getText(this, "field_length"));
320
                        jLblFieldType = new JLabel();
321
                        jLblFieldType.setBounds(new java.awt.Rectangle(14,52,94,22));
322
                        jLblFieldType.setText(PluginServices.getText(this, "field_type"));
323
                        jLblFieldName = new JLabel();
324
                        jLblFieldName.setText(PluginServices.getText(this, "field_name"));
325
                        jLblFieldName.setBounds(new java.awt.Rectangle(14,15,99,22));
326
                        jPnlFields.add(jLblFieldName, null);
327
                        jPnlFields.add(getJTxtFieldName(), null);
328
                        jPnlFields.add(jLblFieldType, null);
329
                        jPnlFields.add(getJCboFieldType(), null);
330
                        jPnlFields.add(jLblFieldLength, null);
331
                        jPnlFields.add(getJTxtFieldLength(), null);
332
                        jPnlFields.add(jLblFieldPrecision, null);
333
                        jPnlFields.add(getJTxtFieldPrecision(), null);
334
                        jPnlFields.add(jLblDefaultValue, null);
335
                        jPnlFields.add(getJTxtDefaultValue(), null);
336
                }
337
                return jPnlFields;
338
        }
339

    
340
}  //  @jve:decl-index=0:visual-constraint="9,10"