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