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