svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / dialogs / DlgFieldManager.java @ 8745
History | View | Annotate | Download (17.6 KB)
1 | 6127 | fjp | /* 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.dialogs; |
||
42 | |||
43 | 6923 | jaume | import java.awt.BorderLayout; |
44 | 6802 | fjp | import java.awt.Component; |
45 | 6923 | jaume | import java.awt.FlowLayout; |
46 | import java.awt.GridLayout; |
||
47 | 6458 | fjp | import java.awt.event.ActionListener; |
48 | 6127 | fjp | import java.sql.Types; |
49 | 6478 | fjp | import java.text.ParseException; |
50 | 7268 | jaume | import java.util.ArrayList; |
51 | 6127 | fjp | |
52 | import javax.swing.DefaultCellEditor; |
||
53 | import javax.swing.JComboBox; |
||
54 | import javax.swing.JLabel; |
||
55 | 6399 | fjp | import javax.swing.JOptionPane; |
56 | 6127 | fjp | import javax.swing.JPanel; |
57 | import javax.swing.JScrollPane; |
||
58 | import javax.swing.JTable; |
||
59 | import javax.swing.ListSelectionModel; |
||
60 | import javax.swing.event.ListSelectionEvent; |
||
61 | import javax.swing.event.ListSelectionListener; |
||
62 | import javax.swing.table.AbstractTableModel; |
||
63 | import javax.swing.table.DefaultTableModel; |
||
64 | import javax.swing.table.TableColumn; |
||
65 | import javax.swing.table.TableModel; |
||
66 | |||
67 | 6923 | jaume | import org.gvsig.gui.beans.swing.JButton; |
68 | |||
69 | 6356 | fjp | import com.hardcode.driverManager.DriverLoadException; |
70 | import com.hardcode.gdbms.engine.data.driver.DriverException; |
||
71 | 6127 | fjp | import com.iver.andami.PluginServices; |
72 | 6458 | fjp | import com.iver.andami.messages.NotificationManager; |
73 | 6877 | cesar | import com.iver.andami.ui.mdiManager.IWindow; |
74 | 6880 | cesar | import com.iver.andami.ui.mdiManager.WindowInfo; |
75 | 6127 | fjp | import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
76 | 6356 | fjp | import com.iver.cit.gvsig.fmap.edition.EditableAdapter; |
77 | 6365 | fjp | import com.iver.cit.gvsig.fmap.edition.EditionException; |
78 | 6356 | fjp | import com.iver.cit.gvsig.fmap.edition.IEditableSource; |
79 | 6458 | fjp | import com.iver.cit.gvsig.gui.panels.FPanelCreateField; |
80 | 6127 | fjp | |
81 | 6877 | cesar | public class DlgFieldManager extends JPanel implements IWindow { |
82 | 6127 | fjp | |
83 | /**
|
||
84 | 6828 | jaume | *
|
85 | 6127 | fjp | */
|
86 | private static final long serialVersionUID = -4284879326692474318L; |
||
87 | 7250 | jaume | private int MAX_FIELD_LENGTH = 254; |
88 | 6365 | fjp | |
89 | 6923 | jaume | WindowInfo windowInfo = null;
|
90 | 6365 | fjp | |
91 | 6127 | fjp | private JLabel jLabel = null; |
92 | 6365 | fjp | |
93 | 6127 | fjp | private JScrollPane jScrollPane = null; |
94 | 6365 | fjp | |
95 | 6127 | fjp | private JTable jTableFields = null; |
96 | 6365 | fjp | |
97 | 6127 | fjp | private JButton jBtnNewField = null; |
98 | 6365 | fjp | |
99 | 6127 | fjp | private JButton jBtnDeleteField = null; |
100 | 6365 | fjp | |
101 | 6127 | fjp | private JButton jBtnRenameField = null; |
102 | 6365 | fjp | |
103 | 6127 | fjp | private JButton jBtnOK = null; |
104 | 6365 | fjp | |
105 | 6127 | fjp | private JButton jBtnCancel = null; |
106 | 6828 | jaume | |
107 | 6458 | fjp | private FPanelCreateField panelNewField = new FPanelCreateField(); |
108 | 6365 | fjp | |
109 | // private IFieldManager fieldManager;;
|
||
110 | 6356 | fjp | private EditableAdapter edAdapter = null; |
111 | 6365 | fjp | |
112 | 6923 | jaume | private JPanel jPanelButtons = null; |
113 | |||
114 | 6365 | fjp | private class MyFieldDescription { |
115 | 6127 | fjp | boolean isOriginal;
|
116 | 6365 | fjp | |
117 | 6127 | fjp | FieldDescription fieldDesc; |
118 | 6365 | fjp | |
119 | MyFieldDescription(FieldDescription fieldDesc, boolean isOriginal) {
|
||
120 | this.fieldDesc = fieldDesc;
|
||
121 | 6127 | fjp | this.isOriginal = isOriginal;
|
122 | } |
||
123 | 6365 | fjp | |
124 | FieldDescription getFieldDescription() { |
||
125 | 6127 | fjp | return fieldDesc;
|
126 | } |
||
127 | 6365 | fjp | |
128 | boolean isOriginal() {
|
||
129 | 6127 | fjp | return isOriginal;
|
130 | } |
||
131 | 6365 | fjp | |
132 | 6127 | fjp | } |
133 | 6365 | fjp | |
134 | private class MyTableModel extends AbstractTableModel { |
||
135 | IEditableSource myIes; |
||
136 | |||
137 | public MyTableModel(IEditableSource ies) {
|
||
138 | myIes = ies; |
||
139 | 6127 | fjp | } |
140 | |||
141 | public int getColumnCount() { |
||
142 | 6468 | fjp | return 5; |
143 | 6127 | fjp | } |
144 | |||
145 | public int getRowCount() { |
||
146 | 6365 | fjp | try {
|
147 | return myIes.getRecordset().getFieldCount();
|
||
148 | } catch (DriverLoadException e) {
|
||
149 | e.printStackTrace(); |
||
150 | } catch (DriverException e) {
|
||
151 | e.printStackTrace(); |
||
152 | } |
||
153 | return 0; |
||
154 | 6127 | fjp | } |
155 | |||
156 | public Object getValueAt(int rowIndex, int columnIndex) { |
||
157 | 6365 | fjp | FieldDescription[] myFields;
|
158 | try {
|
||
159 | 6628 | fjp | myFields = myIes.getFieldsDescription(); |
160 | 6365 | fjp | FieldDescription aux = myFields[rowIndex]; |
161 | switch (columnIndex) {
|
||
162 | case 0: |
||
163 | return aux.getFieldAlias();
|
||
164 | case 1: |
||
165 | String strType = null; |
||
166 | int type = aux.getFieldType();
|
||
167 | if (type == Types.VARCHAR) |
||
168 | strType = "String";
|
||
169 | if (type == Types.DOUBLE) |
||
170 | strType = "Double";
|
||
171 | if (type == Types.INTEGER) |
||
172 | strType = "Integer";
|
||
173 | if (type == Types.BOOLEAN) |
||
174 | strType = "Boolean";
|
||
175 | if (type == Types.DATE) |
||
176 | strType = "Date";
|
||
177 | 6127 | fjp | |
178 | 6365 | fjp | return strType;
|
179 | case 2: |
||
180 | return new Integer(aux.getFieldLength()); |
||
181 | 6468 | fjp | case 3: |
182 | return new Integer(aux.getFieldDecimalCount()); |
||
183 | case 4: |
||
184 | return aux.getDefaultValue();
|
||
185 | 6828 | jaume | |
186 | 6365 | fjp | } |
187 | } catch (DriverLoadException e) {
|
||
188 | e.printStackTrace(); |
||
189 | 6127 | fjp | } |
190 | 6365 | fjp | |
191 | 6127 | fjp | return null; |
192 | } |
||
193 | |||
194 | public Class getColumnClass(int columnIndex) { |
||
195 | // TODO Auto-generated method stub
|
||
196 | return super.getColumnClass(columnIndex); |
||
197 | } |
||
198 | |||
199 | public String getColumnName(int column) { |
||
200 | 6365 | fjp | switch (column) {
|
201 | 6127 | fjp | case 0: |
202 | 6963 | jaume | return PluginServices.getText(this, "field_name"); |
203 | 6127 | fjp | case 1: |
204 | 6963 | jaume | return PluginServices.getText(this, "field_type"); |
205 | 6127 | fjp | case 2: |
206 | 6963 | jaume | return PluginServices.getText(this, "field_length"); |
207 | 6468 | fjp | case 3: |
208 | 6963 | jaume | return PluginServices.getText(this, "field_decimal_count"); |
209 | 6468 | fjp | case 4: |
210 | 6963 | jaume | return PluginServices.getText(this, "field_default_value"); |
211 | 6828 | jaume | |
212 | 6127 | fjp | } |
213 | return super.getColumnName(column); |
||
214 | } |
||
215 | |||
216 | public boolean isCellEditable(int rowIndex, int columnIndex) { |
||
217 | return false; |
||
218 | |||
219 | } |
||
220 | |||
221 | public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
||
222 | 6365 | fjp | FieldDescription[] myFields;
|
223 | try {
|
||
224 | myFields = myIes.getRecordset().getFieldsDescription(); |
||
225 | FieldDescription fDesc = myFields[rowIndex]; |
||
226 | 6127 | fjp | |
227 | 6365 | fjp | switch (columnIndex) {
|
228 | case 0: |
||
229 | fDesc.setFieldAlias((String) aValue);
|
||
230 | break;
|
||
231 | case 1: |
||
232 | String strType = (String) aValue; |
||
233 | if (strType.equals("String")) |
||
234 | fDesc.setFieldType(Types.VARCHAR);
|
||
235 | if (strType.equals("Double")) |
||
236 | fDesc.setFieldType(Types.DOUBLE);
|
||
237 | if (strType.equals("Integer")) |
||
238 | fDesc.setFieldType(Types.INTEGER);
|
||
239 | if (strType.equals("Boolean")) |
||
240 | fDesc.setFieldType(Types.BOOLEAN);
|
||
241 | if (strType.equals("Date")) |
||
242 | fDesc.setFieldType(Types.DATE);
|
||
243 | break;
|
||
244 | case 2: |
||
245 | int fieldLength = ((Integer) aValue).intValue(); |
||
246 | fDesc.setFieldLength(fieldLength); |
||
247 | 6127 | fjp | |
248 | 6365 | fjp | // TODO: HACERLO BIEN
|
249 | if (fDesc.getFieldType() == Types.VARCHAR) |
||
250 | fDesc.setFieldDecimalCount(5);
|
||
251 | |||
252 | } |
||
253 | } catch (DriverLoadException e) {
|
||
254 | e.printStackTrace(); |
||
255 | } catch (DriverException e) {
|
||
256 | e.printStackTrace(); |
||
257 | 6127 | fjp | } |
258 | 6365 | fjp | |
259 | 6127 | fjp | } |
260 | 6365 | fjp | |
261 | 6127 | fjp | } |
262 | 6365 | fjp | |
263 | 6127 | fjp | /**
|
264 | 6365 | fjp | * This method initializes
|
265 | 6828 | jaume | *
|
266 | 6127 | fjp | */
|
267 | 6356 | fjp | public DlgFieldManager(IEditableSource ies) {
|
268 | 6127 | fjp | super();
|
269 | 6356 | fjp | this.edAdapter = (EditableAdapter) ies;
|
270 | 6127 | fjp | initialize(); |
271 | // Add a new row
|
||
272 | 6356 | fjp | TableModel tm;
|
273 | try {
|
||
274 | 6365 | fjp | tm = new MyTableModel(ies);
|
275 | 6356 | fjp | getJTableFields().setModel(tm); |
276 | 6365 | fjp | // Esto lo a?ado aqu? porque si no tiene registros, no hace caso.
|
277 | // (Por eso no
|
||
278 | 6356 | fjp | // lo pongo en getJTable()
|
279 | TableColumn typeColumn = jTableFields.getColumnModel().getColumn(1); |
||
280 | JComboBox comboBox = new JComboBox(); |
||
281 | comboBox.addItem("Boolean");
|
||
282 | comboBox.addItem("Date");
|
||
283 | comboBox.addItem("Integer");
|
||
284 | comboBox.addItem("Double");
|
||
285 | comboBox.addItem("String");
|
||
286 | typeColumn.setCellEditor(new DefaultCellEditor(comboBox)); |
||
287 | 6365 | fjp | |
288 | 6923 | jaume | |
289 | 6356 | fjp | } catch (DriverLoadException e) {
|
290 | // TODO Auto-generated catch block
|
||
291 | e.printStackTrace(); |
||
292 | } |
||
293 | 6127 | fjp | |
294 | } |
||
295 | |||
296 | /**
|
||
297 | * This method initializes this
|
||
298 | 6828 | jaume | *
|
299 | 6127 | fjp | */
|
300 | private void initialize() { |
||
301 | 6923 | jaume | FlowLayout flowLayout = new FlowLayout(); |
302 | flowLayout.setVgap(5);
|
||
303 | flowLayout.setHgap(0);
|
||
304 | BorderLayout borderLayout = new BorderLayout(); |
||
305 | borderLayout.setHgap(15);
|
||
306 | borderLayout.setVgap(15);
|
||
307 | 6365 | fjp | jLabel = new JLabel(); |
308 | 6828 | jaume | jLabel.setText(PluginServices.getText(this, "add_delete_edit_fields")+": "); |
309 | 6923 | jaume | this.setLayout(borderLayout);
|
310 | this.setSize(new java.awt.Dimension(663,404)); |
||
311 | this.setPreferredSize(new java.awt.Dimension(getWidth(), getHeight())); |
||
312 | JPanel jPanelNorth = new JPanel(new FlowLayout(FlowLayout.LEFT)); |
||
313 | jPanelNorth.add(jLabel); |
||
314 | this.add(jPanelNorth, BorderLayout.NORTH); |
||
315 | JPanel jPanelCenter = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0)); |
||
316 | jPanelCenter.add(getJScrollPane()); |
||
317 | this.add(jPanelCenter, BorderLayout.CENTER); |
||
318 | 6365 | fjp | |
319 | 6923 | jaume | this.add(getJPanelButtons(), BorderLayout.EAST); |
320 | JPanel jPanelSouth = new JPanel(); |
||
321 | jPanelSouth.setLayout(flowLayout); |
||
322 | jPanelSouth.add(getJBtnOK(), null);
|
||
323 | jPanelSouth.add(getJBtnCancel(), null);
|
||
324 | this.add(jPanelSouth, BorderLayout.SOUTH); |
||
325 | |||
326 | 6127 | fjp | } |
327 | |||
328 | 6880 | cesar | public WindowInfo getWindowInfo() {
|
329 | 6923 | jaume | if (windowInfo == null) { |
330 | windowInfo = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.PALETTE
|
||
331 | 6880 | cesar | | WindowInfo.RESIZABLE); |
332 | 6923 | jaume | windowInfo.setTitle(PluginServices.getText(this, "field_manager")); |
333 | windowInfo.setHeight(this.getHeight());
|
||
334 | windowInfo.setWidth(this.getWidth());
|
||
335 | 6127 | fjp | } |
336 | 6923 | jaume | return windowInfo;
|
337 | 6127 | fjp | } |
338 | 6365 | fjp | |
339 | 6127 | fjp | /**
|
340 | 6365 | fjp | * Convierte lo que hay en la tabla en una definici?n de campos adecuada
|
341 | * para crear un LayerDefinition
|
||
342 | 6828 | jaume | *
|
343 | 6127 | fjp | * @return
|
344 | */
|
||
345 | public FieldDescription[] getFieldsDescription() { |
||
346 | DefaultTableModel tm = (DefaultTableModel) jTableFields.getModel(); |
||
347 | FieldDescription[] fieldsDesc = new FieldDescription[tm.getRowCount()]; |
||
348 | |||
349 | 6365 | fjp | for (int i = 0; i < tm.getRowCount(); i++) { |
350 | 6127 | fjp | fieldsDesc[i] = new FieldDescription();
|
351 | 6365 | fjp | fieldsDesc[i].setFieldName((String) tm.getValueAt(i, 0)); |
352 | String strType = (String) tm.getValueAt(i, 1); |
||
353 | 6127 | fjp | if (strType.equals("String")) |
354 | fieldsDesc[i].setFieldType(Types.VARCHAR);
|
||
355 | if (strType.equals("Double")) |
||
356 | fieldsDesc[i].setFieldType(Types.DOUBLE);
|
||
357 | if (strType.equals("Integer")) |
||
358 | fieldsDesc[i].setFieldType(Types.INTEGER);
|
||
359 | if (strType.equals("Boolean")) |
||
360 | fieldsDesc[i].setFieldType(Types.BOOLEAN);
|
||
361 | if (strType.equals("Date")) |
||
362 | fieldsDesc[i].setFieldType(Types.DATE);
|
||
363 | 6365 | fjp | int fieldLength = Integer.parseInt((String) tm.getValueAt(i, 2)); |
364 | 6127 | fjp | fieldsDesc[i].setFieldLength(fieldLength); |
365 | |||
366 | // TODO: HACERLO BIEN
|
||
367 | if (strType.equals("Double")) |
||
368 | fieldsDesc[i].setFieldDecimalCount(5);
|
||
369 | |||
370 | } |
||
371 | |||
372 | return fieldsDesc;
|
||
373 | } |
||
374 | |||
375 | /**
|
||
376 | 6365 | fjp | * This method initializes jScrollPane
|
377 | 6828 | jaume | *
|
378 | 6365 | fjp | * @return javax.swing.JScrollPane
|
379 | 6127 | fjp | */
|
380 | private JScrollPane getJScrollPane() { |
||
381 | if (jScrollPane == null) { |
||
382 | jScrollPane = new JScrollPane(); |
||
383 | 6923 | jaume | jScrollPane.setPreferredSize(new java.awt.Dimension(482,350)); |
384 | 6127 | fjp | jScrollPane.setViewportView(getJTableFields()); |
385 | } |
||
386 | return jScrollPane;
|
||
387 | } |
||
388 | |||
389 | /**
|
||
390 | 6365 | fjp | * This method initializes jTableFields
|
391 | 6828 | jaume | *
|
392 | 6365 | fjp | * @return javax.swing.JTable
|
393 | 6127 | fjp | */
|
394 | private JTable getJTableFields() { |
||
395 | if (jTableFields == null) { |
||
396 | jTableFields = new JTable(); |
||
397 | 6365 | fjp | jTableFields |
398 | .setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); |
||
399 | |||
400 | 6399 | fjp | jTableFields.setColumnSelectionAllowed(false);
|
401 | 6365 | fjp | // Ask to be notified of selection changes.
|
402 | 6127 | fjp | ListSelectionModel rowSM = jTableFields.getSelectionModel();
|
403 | rowSM.addListSelectionListener(new ListSelectionListener() { |
||
404 | 6365 | fjp | public void valueChanged(ListSelectionEvent e) { |
405 | // Ignore extra messages.
|
||
406 | if (e.getValueIsAdjusting())
|
||
407 | return;
|
||
408 | 6127 | fjp | |
409 | 6365 | fjp | ListSelectionModel lsm = (ListSelectionModel) e.getSource(); |
410 | if (lsm.isSelectionEmpty()) {
|
||
411 | // no rows are selected
|
||
412 | jBtnDeleteField.setEnabled(false);
|
||
413 | } else {
|
||
414 | jBtnDeleteField.setEnabled(true);
|
||
415 | } |
||
416 | 6399 | fjp | if (jTableFields.getSelectedRows().length != 1) |
417 | { |
||
418 | getJBtnRenameField().setEnabled(false);
|
||
419 | } |
||
420 | else
|
||
421 | { |
||
422 | getJBtnRenameField().setEnabled(true);
|
||
423 | } |
||
424 | 6828 | jaume | |
425 | 6365 | fjp | } |
426 | 6127 | fjp | }); |
427 | 6365 | fjp | |
428 | 6127 | fjp | } |
429 | return jTableFields;
|
||
430 | } |
||
431 | |||
432 | /**
|
||
433 | 6365 | fjp | * This method initializes jBtnNewField
|
434 | 6828 | jaume | *
|
435 | 6365 | fjp | * @return javax.swing.JButton
|
436 | 6127 | fjp | */
|
437 | private JButton getJBtnNewField() { |
||
438 | if (jBtnNewField == null) { |
||
439 | jBtnNewField = new JButton(); |
||
440 | 6923 | jaume | jBtnNewField.setText(PluginServices.getText(this, "new_field")); |
441 | 6127 | fjp | jBtnNewField.addActionListener(new java.awt.event.ActionListener() {
|
442 | 7268 | jaume | private ArrayList tempFieldNames = new ArrayList(); |
443 | |||
444 | { |
||
445 | try{
|
||
446 | String[] f = edAdapter.getRecordset().getFieldNames(); |
||
447 | for (int i = 0; i < f.length; i++) { |
||
448 | tempFieldNames.add(f[i]); |
||
449 | } |
||
450 | } catch (Exception ex) {} |
||
451 | } |
||
452 | |||
453 | 6828 | jaume | public void actionPerformed(java.awt.event.ActionEvent e) { |
454 | |||
455 | 6458 | fjp | ActionListener okAction;
|
456 | okAction = new java.awt.event.ActionListener() {
|
||
457 | 6478 | fjp | public void actionPerformed(java.awt.event.ActionEvent e){ |
458 | 6458 | fjp | try {
|
459 | 6802 | fjp | FieldDescription fld = panelNewField.getFieldDescription(); |
460 | 7250 | jaume | if (fld.getFieldType() == Types.VARCHAR && fld.getFieldLength()>MAX_FIELD_LENGTH) { |
461 | JOptionPane.showMessageDialog(DlgFieldManager.this, PluginServices.getText(this, "max_length_is") + ":" + MAX_FIELD_LENGTH); |
||
462 | fld.setFieldLength(MAX_FIELD_LENGTH); |
||
463 | } |
||
464 | 6802 | fjp | if (edAdapter.getRecordset().getFieldIndexByName(fld.getFieldAlias()) != -1) |
465 | { |
||
466 | JOptionPane.showMessageDialog(
|
||
467 | null,
|
||
468 | PluginServices.getText(this, "field_already_exists")); |
||
469 | return;
|
||
470 | } |
||
471 | 7268 | jaume | tempFieldNames.add(fld.getFieldAlias()); |
472 | |||
473 | 6458 | fjp | edAdapter.addField(fld); |
474 | jTableFields.revalidate(); |
||
475 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(panelNewField); |
476 | 6458 | fjp | } catch (EditionException e1) {
|
477 | 6468 | fjp | NotificationManager.addError(e1); |
478 | 6478 | fjp | } catch (ParseException e2) { |
479 | 6468 | fjp | NotificationManager.addError(e2); |
480 | 6802 | fjp | } catch (DriverLoadException e3) {
|
481 | NotificationManager.addError(e3); |
||
482 | } catch (DriverException e3) {
|
||
483 | NotificationManager.addError(e3); |
||
484 | 6458 | fjp | } |
485 | |||
486 | 6828 | jaume | |
487 | 6458 | fjp | } |
488 | }; |
||
489 | panelNewField.setOkAction(okAction); |
||
490 | 7268 | jaume | String[] names = (String[]) tempFieldNames.toArray(new String[0]); |
491 | panelNewField.setCurrentFieldNames(names); |
||
492 | 6880 | cesar | panelNewField = (FPanelCreateField) PluginServices.getMDIManager().addWindow(panelNewField); |
493 | 6127 | fjp | } |
494 | }); |
||
495 | } |
||
496 | return jBtnNewField;
|
||
497 | } |
||
498 | |||
499 | /**
|
||
500 | 6365 | fjp | * This method initializes jButton
|
501 | 6828 | jaume | *
|
502 | 6365 | fjp | * @return javax.swing.JButton
|
503 | 6127 | fjp | */
|
504 | 6923 | jaume | private JButton getJBtnDelete() { |
505 | 6127 | fjp | if (jBtnDeleteField == null) { |
506 | jBtnDeleteField = new JButton(); |
||
507 | 6828 | jaume | jBtnDeleteField.setText(PluginServices.getText(this, "delete_field")); |
508 | 6365 | fjp | jBtnDeleteField |
509 | .addActionListener(new java.awt.event.ActionListener() {
|
||
510 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
511 | int[] selecteds = jTableFields.getSelectedRows(); |
||
512 | TableModel tm = jTableFields.getModel();
|
||
513 | 6356 | fjp | |
514 | 6828 | jaume | |
515 | 6365 | fjp | for (int i = selecteds.length - 1; i >= 0; i--) |
516 | { |
||
517 | String fieldName = (String) tm.getValueAt(selecteds[i],0); |
||
518 | try {
|
||
519 | edAdapter.removeField(fieldName); |
||
520 | } catch (EditionException e1) {
|
||
521 | // TODO Auto-generated catch block
|
||
522 | e1.printStackTrace(); |
||
523 | } |
||
524 | } |
||
525 | jTableFields.revalidate(); |
||
526 | 6356 | fjp | |
527 | 6365 | fjp | } |
528 | }); |
||
529 | 6127 | fjp | } |
530 | return jBtnDeleteField;
|
||
531 | } |
||
532 | |||
533 | /**
|
||
534 | 6365 | fjp | * This method initializes jBtnRenameField
|
535 | 6828 | jaume | *
|
536 | 6365 | fjp | * @return javax.swing.JButton
|
537 | 6127 | fjp | */
|
538 | private JButton getJBtnRenameField() { |
||
539 | if (jBtnRenameField == null) { |
||
540 | jBtnRenameField = new JButton(); |
||
541 | 6923 | jaume | jBtnRenameField.setText(PluginServices.getText(this, "rename_field")); |
542 | 6399 | fjp | jBtnRenameField.addActionListener(new java.awt.event.ActionListener() {
|
543 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
544 | int[] selecteds = jTableFields.getSelectedRows(); |
||
545 | TableModel tm = jTableFields.getModel();
|
||
546 | |||
547 | 6828 | jaume | |
548 | 6399 | fjp | for (int i = selecteds.length - 1; i >= 0; i--) |
549 | { |
||
550 | String fieldName = (String) tm.getValueAt(selecteds[i],0); |
||
551 | try {
|
||
552 | String newName = JOptionPane.showInputDialog( |
||
553 | 6880 | cesar | (Component) PluginServices.getMDIManager().getActiveWindow(),
|
554 | 6399 | fjp | PluginServices.getText(this, "please_insert_new_field_name"), |
555 | fieldName |
||
556 | ); |
||
557 | if (newName == null) return; |
||
558 | 6802 | fjp | if (edAdapter.getRecordset().getFieldIndexByName(newName) != -1) |
559 | { |
||
560 | JOptionPane.showMessageDialog(
|
||
561 | null,
|
||
562 | PluginServices.getText(this, "field_already_exists")); |
||
563 | return;
|
||
564 | } |
||
565 | 6399 | fjp | |
566 | 6828 | jaume | |
567 | 6399 | fjp | edAdapter.renameField(fieldName, newName); |
568 | } catch (EditionException e1) {
|
||
569 | // TODO Auto-generated catch block
|
||
570 | e1.printStackTrace(); |
||
571 | 6802 | fjp | } catch (DriverLoadException e1) {
|
572 | // TODO Auto-generated catch block
|
||
573 | e1.printStackTrace(); |
||
574 | } catch (DriverException e1) {
|
||
575 | // TODO Auto-generated catch block
|
||
576 | e1.printStackTrace(); |
||
577 | 6399 | fjp | } |
578 | } |
||
579 | jTableFields.repaint(); |
||
580 | 6828 | jaume | |
581 | 6399 | fjp | } |
582 | }); |
||
583 | 6127 | fjp | } |
584 | return jBtnRenameField;
|
||
585 | } |
||
586 | |||
587 | /**
|
||
588 | 6365 | fjp | * This method initializes jBtnOK
|
589 | 6828 | jaume | *
|
590 | 6365 | fjp | * @return javax.swing.JButton
|
591 | 6127 | fjp | */
|
592 | private JButton getJBtnOK() { |
||
593 | if (jBtnOK == null) { |
||
594 | jBtnOK = new JButton(); |
||
595 | 6828 | jaume | jBtnOK.setText(PluginServices.getText(this, "aceptar")); |
596 | 6356 | fjp | jBtnOK.addActionListener(new java.awt.event.ActionListener() {
|
597 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
598 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(DlgFieldManager.this); |
599 | 6356 | fjp | } |
600 | }); |
||
601 | 6127 | fjp | } |
602 | return jBtnOK;
|
||
603 | } |
||
604 | |||
605 | /**
|
||
606 | 6365 | fjp | * This method initializes jButton
|
607 | 6828 | jaume | *
|
608 | 6365 | fjp | * @return javax.swing.JButton
|
609 | 6127 | fjp | */
|
610 | 6923 | jaume | private JButton getJBtnCancel() { |
611 | 6127 | fjp | if (jBtnCancel == null) { |
612 | jBtnCancel = new JButton(); |
||
613 | 6828 | jaume | jBtnCancel.setText(PluginServices.getText(this, "cancelar")); |
614 | 6399 | fjp | jBtnCancel.addActionListener(new java.awt.event.ActionListener() {
|
615 | public void actionPerformed(java.awt.event.ActionEvent e) { |
||
616 | 6880 | cesar | PluginServices.getMDIManager().closeWindow(DlgFieldManager.this); |
617 | 6399 | fjp | } |
618 | }); |
||
619 | 6628 | fjp | jBtnCancel.setVisible(false);
|
620 | 6127 | fjp | } |
621 | return jBtnCancel;
|
||
622 | } |
||
623 | |||
624 | 6923 | jaume | /**
|
625 | * This method initializes jPanelButtons
|
||
626 | *
|
||
627 | * @return javax.swing.JPanel
|
||
628 | */
|
||
629 | private JPanel getJPanelButtons() { |
||
630 | if (jPanelButtons == null) { |
||
631 | jPanelButtons = new JPanel(); |
||
632 | JPanel aux = new JPanel(new GridLayout(3, 1)); |
||
633 | aux.add(getJBtnNewField()); |
||
634 | aux.add(getJBtnRenameField()); |
||
635 | aux.add(getJBtnDelete()); |
||
636 | jPanelButtons.add(aux, BorderLayout.NORTH);
|
||
637 | |||
638 | } |
||
639 | return jPanelButtons;
|
||
640 | } |
||
641 | |||
642 | 6365 | fjp | } // @jve:decl-index=0:visual-constraint="12,23"
|