root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / FPanelCreateField.java @ 6629
History | View | Annotate | Download (8.92 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 |
|
64 |
public class FPanelCreateField extends JPanel implements View { |
65 |
|
66 |
private JLabel jLblFieldName = null; |
67 |
private JTextField jTxtFieldName = null; |
68 |
private JLabel jLblFieldType = null; |
69 |
private JComboBox jCboFieldType = null; |
70 |
private JLabel jLblFieldLength = null; |
71 |
private JTextField jTxtFieldLength = null; |
72 |
private JLabel jLblFieldPrecision = null; |
73 |
private JTextField jTxtFieldPrecision = null; |
74 |
private JLabel jLblDefaultValue = null; |
75 |
private JTextField jTxtDefaultValue = null; |
76 |
private ViewInfo viewInfo;
|
77 |
private JPanel jPanel = null; // @jve:decl-index=0:visual-constraint="299,27" |
78 |
private AcceptCancelPanel jPanelOkCancel = null; |
79 |
public FPanelCreateField() {
|
80 |
super();
|
81 |
// TODO Auto-generated constructor stub
|
82 |
initialize(); |
83 |
} |
84 |
|
85 |
public FPanelCreateField(boolean isDoubleBuffered) { |
86 |
super(isDoubleBuffered);
|
87 |
// TODO Auto-generated constructor stub
|
88 |
initialize(); |
89 |
} |
90 |
|
91 |
public FPanelCreateField(LayoutManager layout) { |
92 |
super(layout);
|
93 |
// TODO Auto-generated constructor stub
|
94 |
initialize(); |
95 |
} |
96 |
|
97 |
public FPanelCreateField(LayoutManager layout, boolean isDoubleBuffered) { |
98 |
super(layout, isDoubleBuffered);
|
99 |
// TODO Auto-generated constructor stub
|
100 |
initialize(); |
101 |
} |
102 |
|
103 |
public ViewInfo getViewInfo() {
|
104 |
if (viewInfo == null) |
105 |
{ |
106 |
viewInfo = new ViewInfo(ViewInfo.MODALDIALOG);
|
107 |
} |
108 |
return viewInfo;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* This method initializes this
|
113 |
*
|
114 |
* @return void
|
115 |
*/
|
116 |
private void initialize() { |
117 |
|
118 |
this.setLayout(new BorderLayout()); |
119 |
this.setSize(300, 250); |
120 |
this.setPreferredSize(new java.awt.Dimension(400,300)); |
121 |
this.add(getJPanel(), java.awt.BorderLayout.CENTER);
|
122 |
this.add(getJPanelOkCancel(), java.awt.BorderLayout.SOUTH);
|
123 |
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* This method initializes jTxtFieldName
|
128 |
*
|
129 |
* @return javax.swing.JTextField
|
130 |
*/
|
131 |
private JTextField getJTxtFieldName() { |
132 |
if (jTxtFieldName == null) { |
133 |
jTxtFieldName = new JTextField(); |
134 |
jTxtFieldName.setBounds(new java.awt.Rectangle(147,15,138,22)); |
135 |
} |
136 |
return jTxtFieldName;
|
137 |
} |
138 |
|
139 |
/**
|
140 |
* This method initializes jCboFieldType
|
141 |
*
|
142 |
* @return javax.swing.JComboBox
|
143 |
*/
|
144 |
private JComboBox getJCboFieldType() { |
145 |
if (jCboFieldType == null) { |
146 |
jCboFieldType = new JComboBox(); |
147 |
jCboFieldType.setBounds(new java.awt.Rectangle(147,52,138,22)); |
148 |
jCboFieldType.addItem("Boolean");
|
149 |
jCboFieldType.addItem("Date");
|
150 |
jCboFieldType.addItem("Integer");
|
151 |
jCboFieldType.addItem("Double");
|
152 |
jCboFieldType.addItem("String");
|
153 |
|
154 |
jCboFieldType.setSelectedIndex(4);
|
155 |
jCboFieldType.addActionListener(new java.awt.event.ActionListener() {
|
156 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
157 |
// System.out.println("actionPerformed()" + e.getActionCommand()); // TODO Auto-generated Event stub actionPerformed()
|
158 |
String strType = (String) getJCboFieldType().getModel().getSelectedItem(); |
159 |
int fieldType = FieldDescription.stringToType(strType);
|
160 |
getJTxtFieldPrecision().setEnabled((fieldType == Types.DOUBLE));
|
161 |
if (fieldType == Types.BOOLEAN) |
162 |
{ |
163 |
getJTxtFieldLength().setText("0");
|
164 |
getJTxtFieldLength().setEnabled(false);
|
165 |
} |
166 |
else
|
167 |
getJTxtFieldLength().setEnabled(true);
|
168 |
|
169 |
} |
170 |
}); |
171 |
|
172 |
} |
173 |
return jCboFieldType;
|
174 |
} |
175 |
|
176 |
/**
|
177 |
* This method initializes jTxtFieldLength
|
178 |
*
|
179 |
* @return javax.swing.JTextField
|
180 |
*/
|
181 |
private JTextField getJTxtFieldLength() { |
182 |
if (jTxtFieldLength == null) { |
183 |
jTxtFieldLength = new JTextField(); |
184 |
jTxtFieldLength.setBounds(new java.awt.Rectangle(147,89,138,22)); |
185 |
} |
186 |
return jTxtFieldLength;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* This method initializes jTxtFieldPrecision
|
191 |
*
|
192 |
* @return javax.swing.JTextField
|
193 |
*/
|
194 |
private JTextField getJTxtFieldPrecision() { |
195 |
if (jTxtFieldPrecision == null) { |
196 |
jTxtFieldPrecision = new JTextField(); |
197 |
jTxtFieldPrecision.setBounds(new java.awt.Rectangle(147,126,138,22)); |
198 |
jTxtFieldPrecision.setEnabled(false);
|
199 |
} |
200 |
return jTxtFieldPrecision;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* This method initializes jTxtDefaultValue
|
205 |
*
|
206 |
* @return javax.swing.JTextField
|
207 |
*/
|
208 |
private JTextField getJTxtDefaultValue() { |
209 |
if (jTxtDefaultValue == null) { |
210 |
jTxtDefaultValue = new JTextField(); |
211 |
jTxtDefaultValue.setBounds(new java.awt.Rectangle(147,163,138,22)); |
212 |
} |
213 |
return jTxtDefaultValue;
|
214 |
} |
215 |
|
216 |
public FieldDescription getFieldDescription() throws ParseException |
217 |
{ |
218 |
FieldDescription newField = new FieldDescription();
|
219 |
newField.setFieldName(getJTxtFieldName().getText()); |
220 |
String strType = (String) getJCboFieldType().getModel().getSelectedItem(); |
221 |
int fieldType = FieldDescription.stringToType(strType);
|
222 |
newField.setFieldType(fieldType); |
223 |
int fieldLength = Integer.parseInt(getJTxtFieldLength().getText()); |
224 |
newField.setFieldLength(fieldLength); |
225 |
if (fieldType == Types.DOUBLE) |
226 |
{ |
227 |
newField.setFieldDecimalCount( |
228 |
Integer.parseInt(
|
229 |
getJTxtFieldPrecision().getText())); |
230 |
} |
231 |
else
|
232 |
newField.setFieldDecimalCount(0);
|
233 |
String defaultValue = getJTxtDefaultValue().getText();
|
234 |
if (defaultValue != null) |
235 |
{ |
236 |
|
237 |
if (defaultValue.compareTo("")==0) |
238 |
newField.setDefaultValue(ValueFactory.createNullValue()); |
239 |
else
|
240 |
newField.setDefaultValue(ValueFactory.createValueByType(defaultValue, fieldType)); |
241 |
} |
242 |
|
243 |
return newField;
|
244 |
} |
245 |
|
246 |
public void setOkAction(ActionListener okAction) { |
247 |
getJPanelOkCancel().setOkButtonActionListener(okAction); |
248 |
|
249 |
} |
250 |
|
251 |
/**
|
252 |
* This method initializes jPanel
|
253 |
*
|
254 |
* @return javax.swing.JPanel
|
255 |
*/
|
256 |
private JPanel getJPanel() { |
257 |
if (jPanel == null) { |
258 |
jLblDefaultValue = new JLabel(); |
259 |
jLblDefaultValue.setBounds(new java.awt.Rectangle(14,163,125,22)); |
260 |
jLblDefaultValue.setText("default_value");
|
261 |
jLblFieldPrecision = new JLabel(); |
262 |
jLblFieldPrecision.setBounds(new java.awt.Rectangle(14,126,112,22)); |
263 |
jLblFieldPrecision.setText("precision");
|
264 |
jLblFieldLength = new JLabel(); |
265 |
jLblFieldLength.setBounds(new java.awt.Rectangle(14,89,99,22)); |
266 |
jLblFieldLength.setText("field_length");
|
267 |
jLblFieldType = new JLabel(); |
268 |
jLblFieldType.setBounds(new java.awt.Rectangle(14,52,94,22)); |
269 |
jLblFieldType.setText("field_type");
|
270 |
jLblFieldName = new JLabel(); |
271 |
jLblFieldName.setText("field_name");
|
272 |
jLblFieldName.setBounds(new java.awt.Rectangle(14,15,99,22)); |
273 |
|
274 |
jPanel = new JPanel(); |
275 |
jPanel.setLayout(null);
|
276 |
|
277 |
jPanel.add(jLblFieldName, null);
|
278 |
jPanel.add(getJTxtFieldName(), null);
|
279 |
jPanel.add(jLblFieldType, null);
|
280 |
jPanel.add(getJCboFieldType(), null);
|
281 |
jPanel.add(jLblFieldLength, null);
|
282 |
jPanel.add(getJTxtFieldLength(), null);
|
283 |
jPanel.add(jLblFieldPrecision, null);
|
284 |
jPanel.add(getJTxtFieldPrecision(), null);
|
285 |
jPanel.add(jLblDefaultValue, null);
|
286 |
jPanel.add(getJTxtDefaultValue(), null);
|
287 |
|
288 |
} |
289 |
return jPanel;
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* This method initializes jPanelOkCancel
|
294 |
*
|
295 |
* @return javax.swing.JPanel
|
296 |
*/
|
297 |
private AcceptCancelPanel getJPanelOkCancel() {
|
298 |
if (jPanelOkCancel == null) { |
299 |
jPanelOkCancel = new AcceptCancelPanel();
|
300 |
jPanelOkCancel.setCancelButtonActionListener(new ActionListener(){ |
301 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
302 |
PluginServices.getMDIManager().closeView(FPanelCreateField.this); |
303 |
}; |
304 |
}); |
305 |
jPanelOkCancel.setPreferredSize(new java.awt.Dimension(10,50)); |
306 |
} |
307 |
return jPanelOkCancel;
|
308 |
} |
309 |
|
310 |
} // @jve:decl-index=0:visual-constraint="9,10"
|