Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.newlayer / org.gvsig.newlayer.lib / org.gvsig.newlayer.lib.impl / src / main / java / org / gvsig / newlayer / impl / FeatureTypePanel.java @ 44669

History | View | Annotate | Download (41.6 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.newlayer.impl;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Component;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionEvent;
32
import java.awt.event.ActionListener;
33
import java.awt.event.ItemEvent;
34
import java.awt.event.ItemListener;
35
import java.util.ArrayList;
36
import java.util.Iterator;
37
import java.util.List;
38

    
39
import javax.swing.ComboBoxModel;
40
import javax.swing.DefaultCellEditor;
41
import javax.swing.JButton;
42
import javax.swing.JCheckBox;
43
import javax.swing.JComboBox;
44
import javax.swing.JLabel;
45
import javax.swing.JOptionPane;
46
import javax.swing.JPanel;
47
import javax.swing.JScrollPane;
48
import javax.swing.JTable;
49
import javax.swing.JTextField;
50
import javax.swing.ListSelectionModel;
51
import javax.swing.UIManager;
52
import javax.swing.event.ListDataListener;
53
import javax.swing.event.ListSelectionEvent;
54
import javax.swing.event.ListSelectionListener;
55
import javax.swing.event.TableModelEvent;
56
import javax.swing.event.TableModelListener;
57
import javax.swing.table.DefaultTableCellRenderer;
58
import javax.swing.table.DefaultTableModel;
59
import javax.swing.table.TableCellRenderer;
60
import javax.swing.table.TableColumn;
61
import javax.swing.table.TableModel;
62

    
63
import org.cresques.cts.IProjection;
64
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
66

    
67
import org.gvsig.app.gui.panels.CRSSelectPanel;
68
import org.gvsig.app.gui.panels.crs.ISelectCrsPanel;
69
import org.gvsig.fmap.dal.DALLocator;
70
import org.gvsig.fmap.dal.DataManager;
71
import org.gvsig.fmap.dal.DataStoreProviderFactory;
72
import org.gvsig.fmap.dal.feature.EditableFeatureAttributeDescriptor;
73
import org.gvsig.fmap.dal.feature.EditableFeatureType;
74
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
75
import org.gvsig.fmap.dal.feature.FeatureStoreProviderFactory;
76
import org.gvsig.fmap.dal.feature.FeatureType;
77
import org.gvsig.fmap.geom.DataTypes;
78
import org.gvsig.fmap.geom.Geometry;
79
import org.gvsig.fmap.geom.GeometryLocator;
80
import org.gvsig.fmap.geom.GeometryManager;
81
import org.gvsig.fmap.geom.type.GeometryType;
82
import org.gvsig.gui.beans.wizard.panel.NotContinueWizardException;
83
import org.gvsig.gui.beans.wizard.panel.OptionPanel;
84
import org.gvsig.i18n.Messages;
85
import org.gvsig.newlayer.NewLayerService;
86
import org.gvsig.tools.dataTypes.DataType;
87
import org.gvsig.tools.swing.api.ToolsSwingLocator;
88
import org.gvsig.tools.swing.api.windowmanager.WindowManager;
89

    
90
public class FeatureTypePanel extends JPanel implements OptionPanel {
91
    private static final int COLUMN_FIELD = 0;
92
    private static final int COLUMN_TYPE = 1;
93
    private static final int COLUMN_LENGTH = 2;
94
    private static final int COLUMN_GEOMETRYTYPE = 3;
95
    private static final int COLUMN_GEOMETRYSUBTYPE = 4;
96
    private static final int COLUMN_CRS = 5;
97
    private static final int COLUMN_PRIMARYKEY = 6;
98
    private static final int COLUMN_MANDATORY = 7;
99
 
100
        private static final long serialVersionUID = 263541873998597624L;
101
        
102
    private FeatureType defaultFeatType = null;
103
    
104
    private NewLayerService newLayer_Service = null;
105
    private int inDefaultFeatTypeFieldCount = 0;
106
        private String inStoreName = null;
107
        private IProjection inProjection = null;
108
        private FeatureStoreProviderFactory spFactory = null;
109
        private boolean defaultHasGeometry = false;
110
        
111
        private static final Logger logger = LoggerFactory
112
                        .getLogger(FeatureTypePanel.class);
113

    
114
        private JLabel jLabel = null;
115
        private JScrollPane jScrollPane = null;
116
        protected JTable jTable = null;
117
        private JPanel jPanelEast = null;
118
        private JButton addFieldButton = null;
119
        private JButton deleteFieldButton = null;
120
        protected int MAX_FIELD_LENGTH = 254;
121
        
122
        // we dont need this list
123
        // we'll clear and rebuild featureType each time
124
        // the user clicks next
125
        // private List removedFields;
126

    
127
        // private DataServerExplorer explorer = null;
128

    
129
        public FeatureTypePanel(NewLayerService new_layer_service) {
130
            
131
            /*
132
            service.getFeatureType(),
133
        service.getStoreName(),
134
        service.getMapContext().getProjection();
135
        */
136
            newLayer_Service = new_layer_service;
137
        }
138
        
139
        private boolean fieldsInited = false;
140
        
141
        private void initFields() {
142
            
143
            if (newLayer_Service == null) {
144
                return;
145
            }
146
            
147
            fieldsInited = true;
148
            
149
        inStoreName = newLayer_Service.getStoreName();
150
        inProjection = newLayer_Service.getMapContext().getProjection();
151
        
152
        DataStoreProviderFactory dspf =
153
                DALLocator.getDataManager().getStoreProviderFactory(inStoreName);
154
        spFactory = (FeatureStoreProviderFactory) dspf;
155
        defaultFeatType = spFactory.createDefaultFeatureType();
156
        if (defaultFeatType != null) {
157
            inDefaultFeatTypeFieldCount =
158
                defaultFeatType.getAttributeDescriptors().length; 
159
            int def_geom_fld_index = defaultFeatType.getDefaultGeometryAttributeIndex(); 
160
            if (def_geom_fld_index >= 0 &&
161
                def_geom_fld_index < inDefaultFeatTypeFieldCount &&
162
                defaultFeatType.
163
                getAttributeDescriptor(def_geom_fld_index).
164
                getDataType().getType() == DataTypes.GEOMETRY) {
165
                
166
                defaultHasGeometry = true;
167
            }
168
        }
169
        }
170

    
171
        private void initializeComponents() {
172
                jLabel = new JLabel();
173
                jLabel.setText(Messages.getText("define_fields"));
174
                this.setLayout(new BorderLayout(5, 5));
175
                this.setSize(new java.awt.Dimension(499, 232));
176
                this.add(jLabel, java.awt.BorderLayout.NORTH);
177
                this.add(getJScrollPane(), java.awt.BorderLayout.CENTER);
178
                this.add(getJPanelSouth(), java.awt.BorderLayout.SOUTH);
179

    
180
        }
181

    
182
        /**
183
         * This method initializes jScrollPane
184
         * 
185
         * @return javax.swing.JScrollPane
186
         */
187
        private JScrollPane getJScrollPane() {
188
                if (jScrollPane == null) {
189
                        jScrollPane = new JScrollPane();
190
                        jScrollPane.setViewportView(getJTable());
191
                }
192
                return jScrollPane;
193
        }
194

    
195
        /**
196
         * This method initializes jTable
197
         * 
198
         * @return javax.swing.JTable
199
         */
200
        private JTable getJTable() {
201
                if (jTable == null) {
202
                        jTable = new JTable(){
203
                            public boolean isCellEditable(int row,int column){
204
                                
205
                                
206
                                if (row < inDefaultFeatTypeFieldCount) {
207
                                    // default fields
208
                                    Object o = getValueAt(row,COLUMN_TYPE);  
209
                                    if (o instanceof ComboItemDataType) {
210
                                        
211
                                        ComboItemDataType ot = (ComboItemDataType) o;
212
                                        return (ot.dataType.getType() == DataTypes.GEOMETRY)
213
                                            &&
214
                                            (column == COLUMN_GEOMETRYTYPE ||
215
                                        column == COLUMN_GEOMETRYSUBTYPE);
216
                                        
217
                                    } else {
218
                                        return false;
219
                                    }
220
                                    
221
                                } else {
222
                                    // fields added by user
223
                                    if (column == COLUMN_PRIMARYKEY) {
224
                                        return spFactory.allowsPrimaryKeyAttributes();
225
                                    }
226

    
227
                                    if (column == COLUMN_MANDATORY) {
228
                                        return spFactory.allowsMandatoryAttributes();
229
                                    }
230
                                    
231
                                    if (column == COLUMN_LENGTH) {
232
                                        
233
                                        Object o = getValueAt(row,COLUMN_TYPE);  
234
                                if (o instanceof ComboItemDataType) {
235
                                    
236
                                    ComboItemDataType ot = (ComboItemDataType) o;
237
                                    return dataTypeNeedsSize(ot.dataType.getType());
238
                                    
239
                                } else {
240
                                    return false;
241
                                }
242
                                        
243
                                    }
244

    
245
                                    if (defaultHasGeometry &&
246
                                        (column == COLUMN_GEOMETRYTYPE
247
                            || column == COLUMN_GEOMETRYSUBTYPE
248
                            || column == COLUMN_CRS)) {
249
                                        // geom-related columns not editable
250
                                        return false;
251
                                    } else {
252
                                return true;
253
                                    }
254
                                }
255

    
256
                                /*
257
                                if ((column == COLUMN_GEOMETRYTYPE) ||
258
                                    (column == COLUMN_GEOMETRYSUBTYPE) ||
259
                                    (column == COLUMN_CRS)) {
260
                                    DataType dataType = 
261
                                        ((ComboItemDataType) getValueAt(row, COLUMN_TYPE)).dataType;                                   
262
                                    return dataType.getType() == DataTypes.GEOMETRY;
263
                                }
264
                                */
265
                            }  
266
                        };
267

    
268
                        DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
269
                        
270
                        tm.addColumn(Messages.getText("_Name"));
271
                        tm.addColumn(Messages.getText("type"));
272
                        tm.addColumn(Messages.getText("length"));
273
                        tm.addColumn(Messages.getText("_Geometry_type"));
274
                        tm.addColumn(Messages.getText("_Dimensions"));
275
                        tm.addColumn(Messages.getText("CRS"));
276
                        tm.addColumn("PK");
277
                        tm.addColumn(Messages.getText("_Mandatory_(short_text)"));
278

    
279
                        // Ask to be notified of selection changes.
280
                        ListSelectionModel rowSM = jTable.getSelectionModel();
281
                        rowSM.addListSelectionListener(new ListSelectionListener() {
282
                                public void valueChanged(ListSelectionEvent e) {
283
                                        // Ignore extra messages.
284
                                        if (e.getValueIsAdjusting())
285
                                                return;
286

    
287
                                        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
288
                                        if (lsm.isSelectionEmpty()) {
289
                                                // no rows are selected
290
                                                deleteFieldButton.setEnabled(false);
291
                                        } else {
292
                                            int min_sele = lsm.getMinSelectionIndex(); 
293
                            if (min_sele > -1 &&
294
                                min_sele < inDefaultFeatTypeFieldCount) {
295
                                deleteFieldButton.setEnabled(false);
296
                            } else {
297
                                deleteFieldButton.setEnabled(allowEditableFeatureType());
298
                            }
299
                                        }                
300
                                        
301
                                }
302
                        });
303
                        jTable.getColumnModel().getColumn(0).setPreferredWidth(100);
304
                        // PK column
305
            jTable.getColumnModel().getColumn(6).setPreferredWidth(30);
306
            // Oblig column
307
            jTable.getColumnModel().getColumn(7).setPreferredWidth(50);
308

    
309
                        jTable.getModel().addTableModelListener(new TableModelListener() {                
310
                public void tableChanged(TableModelEvent e) {
311
                    if (e.getColumn() == COLUMN_TYPE){
312
                        jTable.repaint();
313
                    }                    
314
                }
315
            });
316
                        
317

    
318
                        if (!fieldsInited) {
319
                            initFields();
320
                        }
321

    
322
                        // Rellenado de la tabla
323
                        if (defaultFeatType != null) {
324

    
325
                                Iterator it = defaultFeatType.iterator();
326
                                boolean some_error = false;
327
                                while (it.hasNext()) {
328
                                        FeatureAttributeDescriptor descriptor = (FeatureAttributeDescriptor) it
329
                                                        .next();
330

    
331
                    if (!addRowToFieldTable(
332
                        jTable,
333
                        null,
334
                        inProjection,
335
                        descriptor)) {
336
                        
337
                        some_error = true;
338
                    }
339
                    /*
340
                                        tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
341
                                        tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
342
                                        tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
343
                                        tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
344
                                        tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
345
                                        tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
346
                                        tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
347
                                        tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
348
                                        */
349
                                }
350
                                
351
                                if (some_error) {
352
                    String tit = Messages.getText("_Default_fields");
353
                    String msg = Messages.getText("_Unable_to_add_fields");
354
                    JOptionPane.showMessageDialog(
355
                        jTable, msg, tit,
356
                        JOptionPane.ERROR_MESSAGE);
357
                                }
358
                        }
359

    
360
                }
361
                jTable.setEnabled(allowEditableFeatureType());
362
                return jTable;
363
        }
364

    
365
        /**
366
         * This method initializes jPanelWest
367
         * 
368
         * @return javax.swing.JPanel
369
         */
370
        private JPanel getJPanelSouth() {
371
                if (jPanelEast == null) {
372
                        jPanelEast = new JPanel();
373
                        jPanelEast.setLayout(new BorderLayout());
374
                        
375
                        JPanel south_east = new JPanel(new GridBagLayout());
376
                        // south_east.setPreferredSize(new java.awt.Dimension(170, 50));
377
                        GridBagConstraints c = new GridBagConstraints();
378
                        c.fill = GridBagConstraints.HORIZONTAL;
379
                        c.insets = new Insets(8,10,8,0);  //top padding
380
                        c.gridx = 0;       
381
                        c.gridwidth = 1;   
382
                        c.gridy = 0;       
383
                        south_east.add(getJButtonAddField(), c);
384
            c.gridx = 1;       
385
                        south_east.add(getJButtonDeleteField(), c);
386
                        
387
                        jPanelEast.add(south_east, BorderLayout.EAST);
388
                }
389
                return jPanelEast;
390
        }
391

    
392
        /**
393
         * This method initializes jButtonAddField
394
         * 
395
         * @return javax.swing.JButton
396
         */
397
        private JButton getJButtonAddField() {
398
                if (addFieldButton == null) {
399
                    addFieldButton = new JButton();
400
                    addFieldButton.setText(Messages.getText("add_field"));
401
                    addFieldButton.setLocation(new java.awt.Point(7, 5));
402
                    addFieldButton.setSize(new java.awt.Dimension(180, 23));
403
                    addFieldButton.setPreferredSize(new java.awt.Dimension(180, 23));
404
                    addFieldButton
405
                                        .addActionListener(new java.awt.event.ActionListener() {
406
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
407
                                                        DefaultTableModel tm = (DefaultTableModel) jTable
408
                                                                        .getModel();
409

    
410
                                                        // Figure out a suitable field name
411
                                                        ArrayList fieldNames = new ArrayList();
412
                                                        for (int i = 0; i < jTable.getRowCount(); i++) {
413
                                                                fieldNames.add(tm.getValueAt(i, COLUMN_FIELD));
414
                                                        }
415
                                                        String[] currentFieldNames = (String[]) fieldNames
416
                                                                        .toArray(new String[0]);
417
                                                        String newField = Messages.getText("field")
418
                                                                        .replaceAll(" +", "_");
419
                                                        int index = 0;
420
                                                        for (int i = 0; i < currentFieldNames.length; i++) {
421
                                                                if (currentFieldNames[i].startsWith(newField)) {
422
                                                                        try {
423
                                                                                index = Integer
424
                                                                                                .parseInt(currentFieldNames[i]
425
                                                                                                                .replaceAll(newField,
426
                                                                                                                                ""));
427
                                                                        } catch (Exception ex) { /* we don't care */
428
                                                                        }
429
                                                                }
430
                                                        }
431
                                                        String newFieldName = newField + (++index);
432

    
433
                                                        // Esto lo a?ado aqu? porque si no tiene registros,
434
                                                        // no hace caso. (Por eso no
435
                                                        // lo pongo en getJTable()
436
                                                        if (!addRowToFieldTable(
437
                                                            jTable,
438
                                                            newFieldName,
439
                                                            inProjection,
440
                                                            null)) {
441
                                                            
442
                                    String tit = Messages.getText("_Default_fields");
443
                                    String msg = Messages.getText("_Unable_to_add_fields");
444
                                    JOptionPane.showMessageDialog(
445
                                        jTable, msg, tit,
446
                                        JOptionPane.ERROR_MESSAGE);
447
                                                        }
448
                                                }
449
                                        });
450

    
451
                }
452
                addFieldButton.setEnabled(allowEditableFeatureType());
453
                return addFieldButton;
454
        }
455
        
456
        private boolean allowEditableFeatureType(){
457
            
458
            if (!fieldsInited) {
459
                initFields();
460
            }
461

    
462
                DataManager dataManager = DALLocator.getDataManager();
463
                FeatureStoreProviderFactory factory =
464
                    (FeatureStoreProviderFactory) dataManager.
465
                    getStoreProviderFactory(inStoreName);
466
                if (factory.allowEditableFeatureType()==FeatureStoreProviderFactory.NO) {
467
                        return false;
468
                }
469
                return true;
470
        }
471

    
472
        private class ComboItemDataType {
473
                private DataType dataType;
474

    
475
                public ComboItemDataType(DataType dataType) {
476
                        this.dataType = dataType;
477
                }
478

    
479
                @Override
480
                public String toString() {
481
                        return this.dataType.getName();
482
                }
483
        }
484

    
485
        private class ComboModelDataType implements ComboBoxModel {
486

    
487
                private List<ComboItemDataType> dataTypes;
488
                private ComboItemDataType selected;
489

    
490
                public ComboModelDataType(List<DataType> dataTypes, int sel_type) {
491
                    
492
                        this.dataTypes = new ArrayList<ComboItemDataType>();
493
                        ComboItemDataType item = null;
494
                        for (Iterator iterator = dataTypes.iterator(); iterator.hasNext();) {
495
                                DataType dataType = (DataType) iterator.next();
496
                                item = new ComboItemDataType(dataType);
497
                                this.dataTypes.add(item);
498
                                if (sel_type == dataType.getType()) {
499
                                    this.setSelectedItem(item);
500
                                }
501
                        }
502
                }
503

    
504
                public void addListDataListener(ListDataListener arg0) {
505
                        // DO NOTHING
506
                }
507

    
508
                public Object getElementAt(int arg0) {
509
                        return this.dataTypes.get(arg0);
510
                }
511

    
512
                public int getSize() {
513
                        return this.dataTypes.size();
514
                }
515

    
516
                public void removeListDataListener(ListDataListener arg0) {
517
                        // DO NOTHING
518
                }
519

    
520
                public Object getSelectedItem() {
521
                        return this.selected;
522
                }
523

    
524
                public void setSelectedItem(Object anItem) {
525
                        this.selected = (ComboItemDataType) anItem;
526
                }
527

    
528
        }
529

    
530
        class CrsRenderer extends JButton implements TableCellRenderer {
531
                private static final long serialVersionUID = -573793294070515376L;
532
                private JLabel label = null;
533
                
534
                public CrsRenderer() {
535
                        setOpaque(true);
536
                        label = new JLabel(Messages.getText("not_applicable"));
537
                        this.setMargin(new Insets(2, 0, 2, 0));
538
                        this.setFont(this.getFont().deriveFont(9f));
539
                }
540

    
541
                public Component getTableCellRendererComponent(JTable table,
542
                                Object value, boolean isSelected, boolean hasFocus, int row,
543
                                int column) {
544
                        
545
                    ComboItemDataType item =
546
                        (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE);
547
                    
548
                    if (item == null) {
549
                        // happens sometimes. perhaps an early rendering?
550
                        return new JLabel();
551
                    }
552
                    
553
                    DataType dataType = item.dataType;                       
554
                        
555
            if (dataType.getType() != DataTypes.GEOMETRY) {                
556
                return label;
557
            }
558
                    
559
                    if (isSelected) {
560
                                setForeground(table.getSelectionForeground());
561
                                setBackground(table.getSelectionBackground());
562
                        } else {
563
                                setForeground(table.getForeground());
564
                                setBackground(UIManager.getColor("Button.background"));
565
                        }
566
                        setText((value == null) ? "" : ((IProjection) value).getFullCode());
567
                        return this;
568
                }
569
        }        
570
           
571
    private class GeometryComboCellRenderer extends JLabel implements TableCellRenderer{
572

    
573
        public Component getTableCellRendererComponent(JTable table,
574
            Object value, boolean isSelected, boolean hasFocus, int row,
575
            int column) {                     
576

    
577
            ComboItemDataType item = (ComboItemDataType) table.getValueAt(row, COLUMN_TYPE);
578
            DataType dataType = item.dataType;                       
579
                        
580
            if (dataType.getType() == DataTypes.GEOMETRY) {
581
                ComboItemGeomType geomType = (ComboItemGeomType)value;
582
                if (geomType != null) {            
583
                    this.setText(geomType.toString());
584
                }
585
            } else {
586
               this.setText(Messages.getText("not_applicable"));
587
            }
588
            
589
            return this;
590
        }
591
        
592
    }
593

    
594
        class ButtonEditor extends DefaultCellEditor {
595
                /**
596
                 * 
597
                 */
598
                private static final long serialVersionUID = -2820892672026188802L;
599

    
600
                protected JButton button;
601

    
602
                private String label;
603

    
604
                private boolean isPushed;
605

    
606
                private Object value;
607

    
608
                public ButtonEditor(JCheckBox checkBox) {
609
                        super(checkBox);
610
                        button = new JButton();
611
                        button.setOpaque(true);
612
                        button.addActionListener(new ActionListener() {
613
                                public void actionPerformed(ActionEvent e) {
614
                                        fireEditingStopped();
615
                                }
616
                        });
617
                }
618

    
619
                public Component getTableCellEditorComponent(JTable table,
620
                                Object value, boolean isSelected, int row, int column) {
621
                        if (isSelected) {
622
                                button.setForeground(table.getSelectionForeground());
623
                                button.setBackground(table.getSelectionBackground());
624
                        } else {
625
                                button.setForeground(table.getForeground());
626
                                button.setBackground(table.getBackground());
627
                        }
628
                        label = (value == null) ? "" : ((IProjection) value).getFullCode();// .toString();
629
                        button.setText(label);
630
                        isPushed = true;
631
                        this.value = value;
632
                        return button;
633
                }
634

    
635
                public Object getCellEditorValue() {
636
                        IProjection curProj = (IProjection) this.value;
637
                        if (isPushed) {
638
                                ISelectCrsPanel csSelect = CRSSelectPanel.getUIFactory()
639
                                                .getSelectCrsPanel(curProj, true);
640
                                WindowManager wm = ToolsSwingLocator.getWindowManager();
641
                                wm.showWindow((JPanel) csSelect, "Projection",
642
                                                WindowManager.MODE.DIALOG);
643
                                curProj = csSelect.getProjection();
644
                        }
645
                        isPushed = false;
646
                        return curProj;
647
                }
648

    
649
                public boolean stopCellEditing() {
650
                        isPushed = false;
651
                        return super.stopCellEditing();
652
                }
653

    
654
                protected void fireEditingStopped() {
655
                        super.fireEditingStopped();
656
                }
657
        }
658

    
659
        private class ComboItemGeomType {
660
                private int type;
661
                private String name;
662

    
663
                public ComboItemGeomType(String name, int type) {
664
                        this.type = type;
665
                        this.name = name;
666
                }
667

    
668
                @Override
669
                public String toString() {
670
                        return this.name;
671
                }
672
                
673
                public int getGeomType() {
674
                    return type;
675
                }
676
        }
677

    
678
        private class ComboModelGeomType implements ComboBoxModel {
679

    
680
                private List<ComboItemGeomType> geomTypes;
681
                private ComboItemGeomType selected;
682

    
683
                public ComboModelGeomType(
684
                    List<ComboItemGeomType> geomTypes, int sel_geom_type) {
685
                    
686
                        this.geomTypes = geomTypes;
687
                        int len = geomTypes.size();
688
                        ComboItemGeomType item = null;
689
                        for (int i=0; i<len; i++) {
690
                            item = geomTypes.get(i);
691
                            if (item.getGeomType() == sel_geom_type) {
692
                                setSelectedItem(item);
693
                            }
694
                        }
695
                }
696

    
697
                public void addListDataListener(ListDataListener arg0) {
698
                        // DO NOTHING
699
                }
700

    
701
                public Object getElementAt(int arg0) {
702
                        return this.geomTypes.get(arg0);
703
                }
704

    
705
                public int getSize() {
706
                        return this.geomTypes.size();
707
                }
708

    
709
                public void removeListDataListener(ListDataListener arg0) {
710
                        // DO NOTHING
711
                }
712

    
713
                public Object getSelectedItem() {
714
                        return this.selected;
715
                }
716

    
717
                public void setSelectedItem(Object anItem) {
718
                        this.selected = (ComboItemGeomType) anItem;
719
                }
720

    
721
        }
722

    
723
        private List<ComboItemGeomType> getGeomTypes() {
724
                List<ComboItemGeomType> geomTypes = new ArrayList<ComboItemGeomType>();
725
                geomTypes.add(new ComboItemGeomType("GEOMETRY", Geometry.TYPES.GEOMETRY));
726
                geomTypes.add(new ComboItemGeomType("POINT", Geometry.TYPES.POINT));
727
                geomTypes.add(new ComboItemGeomType("LINE", Geometry.TYPES.LINE));
728
                geomTypes.add(new ComboItemGeomType("POLYGON", Geometry.TYPES.POLYGON));
729
                geomTypes.add(new ComboItemGeomType("SOLID", Geometry.TYPES.SOLID));
730
                geomTypes.add(new ComboItemGeomType("AGGREGATE", Geometry.TYPES.AGGREGATE));
731
                geomTypes.add(new ComboItemGeomType("MULTIPOINT", Geometry.TYPES.MULTIPOINT));
732
                geomTypes.add(new ComboItemGeomType("MULTILINE", Geometry.TYPES.MULTILINE));
733
                geomTypes.add(new ComboItemGeomType("MULTIPOLYGON", Geometry.TYPES.MULTIPOLYGON));
734
                geomTypes.add(new ComboItemGeomType("MULTISOLID", Geometry.TYPES.MULTISOLID));
735

    
736
                return geomTypes;
737
        }
738

    
739
        private List<ComboItemGeomType> getGeomSubtypes() {
740
                List<ComboItemGeomType> geomSubtypes = new ArrayList<ComboItemGeomType>();
741
                geomSubtypes.add(new ComboItemGeomType("GEOM2D",
742
                                Geometry.SUBTYPES.GEOM2D));
743
                geomSubtypes.add(new ComboItemGeomType("GEOM2DM",
744
                                Geometry.SUBTYPES.GEOM2DM));
745
                geomSubtypes.add(new ComboItemGeomType("GEOM3D",
746
                                Geometry.SUBTYPES.GEOM3D));
747
                geomSubtypes.add(new ComboItemGeomType("GEOM3DM",
748
                                Geometry.SUBTYPES.GEOM3DM));
749
                geomSubtypes.add(new ComboItemGeomType("UNKNOWN",
750
                                Geometry.SUBTYPES.UNKNOWN));
751
                return geomSubtypes;
752
        }
753

    
754
        class CheckBoxRenderer extends JCheckBox implements TableCellRenderer {
755

    
756
                /**
757
                 * 
758
                 */
759
                private static final long serialVersionUID = 5093448776058027505L;
760

    
761
                public CheckBoxRenderer() {
762
                        setHorizontalAlignment(JLabel.CENTER);
763
                }
764

    
765
                public Component getTableCellRendererComponent(JTable table,
766
                                Object value, boolean isSelected, boolean hasFocus, int row,
767
                                int column) {
768
                        if (isSelected) {
769
                                setForeground(table.getSelectionForeground());
770
                                setBackground(table.getSelectionBackground());
771
                        } else {
772
                                setForeground(table.getForeground());
773
                                setBackground(table.getBackground());
774
                        }
775
                        setSelected((value != null && ((Boolean) value).booleanValue()));
776
                        return this;
777
                }
778
        }
779

    
780
        /**
781
         * This method initializes jButton
782
         * 
783
         * @return javax.swing.JButton
784
         */
785
        private JButton getJButtonDeleteField() {
786
                if (deleteFieldButton == null) {
787
                    deleteFieldButton = new JButton();
788
                    deleteFieldButton.setText(Messages.getText("delete_field"));
789
                    deleteFieldButton.setLocation(new java.awt.Point(7, 33));
790
                    deleteFieldButton.setSize(new java.awt.Dimension(180, 23));
791
                    deleteFieldButton.setPreferredSize(new java.awt.Dimension(180, 23));
792
                    deleteFieldButton.setEnabled(false);
793
                    deleteFieldButton
794
                                        .addActionListener(new java.awt.event.ActionListener() {
795
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
796
                                                        int[] selecteds = jTable.getSelectedRows();
797
                                                        DefaultTableModel tm = (DefaultTableModel) jTable
798
                                                                        .getModel();
799

    
800
                                                        for (int i = selecteds.length - 1; i >= 0; i--) {
801
                                                            /*
802
                                                             * 
803
                                                                removedFields.add((String) tm.getValueAt(i, 0));
804
                                 */
805
                                                                tm.removeRow(selecteds[i]);
806
                                                        }
807
                                                }
808
                                        });
809
                }
810
                deleteFieldButton.setEnabled(false);
811
                return deleteFieldButton;
812
        }
813

    
814
        public String getPanelTitle() {
815
                return Messages.getText("_Field_definitions");
816
        }
817

    
818
        public void nextPanel() throws NotContinueWizardException {
819
                if (allowEditableFeatureType()){
820
                        fillFeatureType();
821
                }
822
        }
823

    
824
        private void fillFeatureType() throws NotContinueWizardException {
825
            
826
            if (!fieldsInited) {
827
                initFields();
828
            }
829

    
830
                /*
831
                 * Coge los datos del formulario y los guarda en
832
                 * this.service.getFeatureType()
833
                 */
834

    
835
            EditableFeatureType edft = newLayer_Service.getFeatureType();
836

    
837
                // Clean and rebuild featureType everytime we click next
838
                removeAllFields(edft);
839
                edft.setDefaultGeometryAttributeName(null);
840

    
841
                GeometryManager gm = GeometryLocator.getGeometryManager();
842
                DefaultTableModel tm = (DefaultTableModel) jTable.getModel();
843
                
844
                for (int i = 0; i < tm.getRowCount(); i++) {
845
                        DataType dataType = ((ComboItemDataType) tm.getValueAt(i, COLUMN_TYPE)).dataType;
846

    
847
                        int fieldLength = 20;
848
                        if (dataTypeNeedsSize(dataType.getType())) {
849
                    fieldLength = 
850
                        Integer.parseInt((String) tm.getValueAt(i, COLUMN_LENGTH));
851
                        }
852

    
853
                        EditableFeatureAttributeDescriptor efad1 =
854
                            edft.add(
855
                                        (String) tm.getValueAt(i, COLUMN_FIELD), dataType.getType(),
856
                                        fieldLength);
857

    
858
                        if (dataType.getType() == DataTypes.DOUBLE ||
859
                            dataType.getType() == DataTypes.FLOAT) {
860
                            // TODO Improve this?
861
                            // Half of the size dedicated
862
                            // to precision (at least 1) 
863
              efad1.setPrecision(fieldLength);
864
                    efad1.setScale(Math.max(1, fieldLength/2));
865
                        }
866

    
867
                        if (dataType.getType() == DataTypes.GEOMETRY) {
868
                            
869
                int g_type = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYTYPE)).type;
870
                int g_subtype = ((ComboItemGeomType) tm.getValueAt(i, COLUMN_GEOMETRYSUBTYPE)).type;
871
                            
872
                            GeometryType gty = null;
873
                            
874
                            try {
875
                    gty = gm.getGeometryType(g_type, g_subtype);
876
                    efad1.setGeometryType(gty);
877
                    // efad1.setGeometryType(g_type);
878
                            } catch (Exception ex) {
879
                    String _msg = Messages.getText("_Invalid_geometry_type")
880
                        + " (" + g_type + ", " + g_subtype + ")";
881
                                throw new NotContinueWizardException(_msg, ex, this);
882
                            }
883
                                
884
                                efad1.setSRS((IProjection) tm.getValueAt(i, COLUMN_CRS));
885
                                
886
                                //If there is not a previous default geometry field, add it
887
                                // this will set the first geometry field
888
                                // as the default geometry field
889
                                if (edft.getDefaultGeometryAttribute() == null){
890
                                    edft.setDefaultGeometryAttributeName(efad1.getName());
891
                                }        
892
                        }
893
                        
894
                        // pk and mandatory
895
            efad1.setIsPrimaryKey(((Boolean) tm.getValueAt(i, COLUMN_PRIMARYKEY))
896
                .booleanValue());
897
            efad1.setAllowNull(!((Boolean) tm.getValueAt(i, COLUMN_MANDATORY))
898
                .booleanValue());
899

    
900
                }
901
        }
902

    
903
        /**
904
     * @param featureType
905
     */
906
    private void removeAllFields(EditableFeatureType ft) {
907
        
908
        FeatureAttributeDescriptor[] atts =  ft.getAttributeDescriptors();
909
        int len = atts.length;
910
        FeatureAttributeDescriptor item = null;
911
        for (int i=0; i<len; i++) {
912
            item = atts[i];
913
            ft.remove(item.getName());
914
        }
915
    }
916

    
917
    public void lastPanel() {
918
                // TODO Auto-generated method stub
919
                logger.info("FeatureTypePanel: lastPanel");
920
        }
921

    
922
        public void updatePanel() {
923
                initializeComponents();
924

    
925
        }
926

    
927
        public JPanel getJPanel() {
928
                return this;
929
        }
930
        
931
        /**
932
         * If fad is null, it's an addition after user has clicked on 'Add field'.
933
         * If fad is not null, it's the description of a default field and the
934
         * field name will also be taken from there.
935
         * 
936
         * @param the_table
937
         * @param new_fld_name
938
         * @param the_projection
939
         * @param fad
940
         * 
941
         * @return true if field was actually added, false otherwise
942
         */
943
    private boolean addRowToFieldTable(
944
        JTable the_table,
945
        String new_fld_name,
946
        IProjection the_projection,
947
        FeatureAttributeDescriptor fad) {
948
        
949
        if (fad == null && new_fld_name == null) {
950
            logger.info("Error: unable to add field to table (no description and no name)");
951
            return false;
952
        }
953
        
954
        DefaultTableModel the_tm = (DefaultTableModel) the_table.getModel();
955
        Object[] newRow = new Object[the_tm.getColumnCount()];
956
        
957
        /*
958
        tm.setValueAt(descriptor.getName(), row, COLUMN_FIELD);
959
        tm.setValueAt(descriptor.getType(), row, COLUMN_TYPE);
960
        tm.setValueAt(descriptor.getSize(), row, COLUMN_LENGTH);
961
        tm.setValueAt(descriptor.getGeometryType(), row, COLUMN_GEOMETRYTYPE);
962
        tm.setValueAt(descriptor.getGeometrySubType(), row, COLUMN_GEOMETRYSUBTYPE);
963
        tm.setValueAt(descriptor.getSRS(), row, COLUMN_CRS);
964
        tm.setValueAt(descriptor.isPrimaryKey(), row, COLUMN_PRIMARYKEY);
965
        tm.setValueAt(descriptor.isMandatory(), row, COLUMN_MANDATORY);
966
        */
967
        
968
        // =============================== name
969
        if (fad == null) {
970
            newRow[COLUMN_FIELD] = new_fld_name;
971
        } else {
972
            newRow[COLUMN_FIELD] = fad.getName();
973
        }
974
        // ===================================== field type
975
        TableColumn typeColumn = the_table.getColumnModel().getColumn(COLUMN_TYPE);
976
        List supp_types = spFactory.getSupportedDataTypes();
977
        
978
        DataManager daman = DALLocator.getDataManager();
979
        List all_types = daman.getDataTypes();
980
        
981
        
982
        ComboModelDataType model = null;
983
        if (fad == null) {
984

    
985
            // this is a user defined column, remove geometry if in default feattype 
986
            if (defaultHasGeometry) {
987
                supp_types = removeGeometryType(supp_types);
988
                all_types = removeGeometryType(all_types);
989
            }
990
            
991
            if (supp_types != null && supp_types.size() > 0) {
992
                model = new ComboModelDataType(
993
                    supp_types,
994
                    ((DataType) supp_types.get(0)).getType());
995
            } else {
996
                model = new ComboModelDataType(
997
                    all_types,
998
                    ((DataType) all_types.get(0)).getType());
999
            }
1000
        } else {
1001
            model = new ComboModelDataType(supp_types, fad.getType());
1002
        }
1003
        
1004
        JComboBox comboBox = new JComboBox(model);
1005
        typeColumn.setCellEditor(new DefaultCellEditor(comboBox));
1006
        newRow[COLUMN_TYPE] = model.getSelectedItem();
1007
        
1008
        // ============================= width
1009
        TableColumn widthColumn =
1010
            the_table.getColumnModel().getColumn(COLUMN_LENGTH);
1011
        if (fad == null) {
1012
            newRow[COLUMN_LENGTH] = "20";
1013
        } else {
1014
            newRow[COLUMN_LENGTH] = "" + fad.getSize();
1015
        }
1016
        
1017
        SimpleTextCellRenderer stcr = new SimpleTextCellRenderer();
1018
        widthColumn.setCellEditor(new DefaultCellEditor(new JTextField()));
1019
        widthColumn.setCellRenderer(stcr);
1020
        
1021
        
1022
        // ============================= geom type
1023
        TableColumn geomTypeColumn =
1024
            the_table.getColumnModel().getColumn(COLUMN_GEOMETRYTYPE);
1025
        ComboModelGeomType geomTypeModel = null;
1026
        
1027
        List<ComboItemGeomType> supptd =
1028
            leaveSupportedGeomTypes(getGeomTypes(),
1029
                spFactory.getSupportedGeometryTypesSubtypes(), 0);
1030
        
1031
        if (fad == null) {
1032
            geomTypeModel = new ComboModelGeomType(
1033
                supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1);
1034
        } else {
1035
            geomTypeModel = new ComboModelGeomType(
1036
                supptd, fad.getGeomType().getType());
1037
        }
1038
        
1039
        JComboBox geomTypeComboBox = new JComboBox(geomTypeModel);
1040
        geomTypeColumn.setCellEditor(new DefaultCellEditor(geomTypeComboBox));
1041
        
1042
        GeometryComboCellRenderer gccr = new GeometryComboCellRenderer();
1043
        geomTypeColumn.setCellRenderer(gccr);
1044
        newRow[COLUMN_GEOMETRYTYPE] = geomTypeModel.getSelectedItem();
1045
        
1046
        // ============================= geom sub type
1047

    
1048
        TableColumn geomSubTypeColumn =
1049
            the_table.getColumnModel().getColumn(COLUMN_GEOMETRYSUBTYPE);
1050
        ComboModelGeomType geomSubTypeModel = null;
1051

    
1052
        supptd =
1053
            leaveSupportedGeomTypes(getGeomSubtypes(),
1054
                spFactory.getSupportedGeometryTypesSubtypes(), 1);
1055
        
1056
        if (fad == null) {
1057
            geomSubTypeModel = new ComboModelGeomType(
1058
                supptd, supptd.size() > 0 ? supptd.get(0).getGeomType() : -1);
1059
        } else {
1060
            geomSubTypeModel = new ComboModelGeomType(
1061
                supptd, fad.getGeomType().getSubType());
1062
        }
1063
        
1064
        JComboBox geomSubTypeComboBox = new JComboBox(geomSubTypeModel);
1065
        geomSubTypeColumn.setCellEditor(new DefaultCellEditor(
1066
            geomSubTypeComboBox));
1067
        geomSubTypeColumn.setCellRenderer(new GeometryComboCellRenderer());
1068
        newRow[COLUMN_GEOMETRYSUBTYPE] = geomSubTypeModel.getSelectedItem();
1069

    
1070
        // ============================= CRS
1071

    
1072
        TableColumn crsColumn = the_table.getColumnModel().getColumn(COLUMN_CRS);
1073
        crsColumn.setCellEditor(new ButtonEditor(new JCheckBox()));
1074
        CrsRenderer crsButtonRenderer = new CrsRenderer();
1075
        crsColumn.setCellRenderer(crsButtonRenderer);
1076
        newRow[COLUMN_CRS] = the_projection;
1077

    
1078
        // ============================= PK
1079

    
1080
        TableColumn primaryKeyColumn =
1081
            the_table.getColumnModel().getColumn(COLUMN_PRIMARYKEY);
1082
        JCheckBox primaryKeyCheckBox = new JCheckBox();
1083
        
1084
        if (fad == null) {
1085
            primaryKeyCheckBox.setSelected(false);
1086
        } else {
1087
            primaryKeyCheckBox.setSelected(fad.isPrimaryKey());
1088
        }
1089

    
1090
        primaryKeyColumn.setCellEditor(
1091
            new DefaultCellEditor(primaryKeyCheckBox));
1092
        CheckBoxRenderer primaryKeyCheckBoxRenderer = new CheckBoxRenderer();
1093
        primaryKeyColumn.setCellRenderer(primaryKeyCheckBoxRenderer);
1094
        newRow[COLUMN_PRIMARYKEY] = primaryKeyCheckBox.isSelected();
1095
            
1096
        // ================================== mandatory
1097
        
1098
        TableColumn mandatoryColumn =
1099
            the_table.getColumnModel().getColumn(COLUMN_MANDATORY);
1100
        JCheckBox mandatoryCheckBox = new JCheckBox();
1101
        
1102
        if (fad == null) {
1103
            mandatoryCheckBox.setSelected(false);
1104
        } else {
1105
            mandatoryCheckBox.setSelected(fad.isMandatory());
1106
        }
1107
        
1108
        mandatoryColumn.setCellEditor(new DefaultCellEditor(mandatoryCheckBox));
1109
        CheckBoxRenderer mandatoryCheckBoxRenderer = new CheckBoxRenderer();
1110
        mandatoryColumn.setCellRenderer(mandatoryCheckBoxRenderer);
1111
        newRow[COLUMN_MANDATORY] = mandatoryCheckBox.isSelected();
1112

    
1113
        // ==================================
1114
        
1115
        // Add a new row
1116
        the_tm.addRow(newRow);
1117
        return true;
1118
    }
1119

    
1120
    /**
1121
     * @param supp_types
1122
     * @return
1123
     */
1124
    private List removeGeometryType(List dta_types) {
1125
        List resp = new ArrayList();
1126
        
1127
        int len = dta_types.size();
1128
        Object item_o = null;
1129
        DataType item_dt = null;
1130
        
1131
        for (int i=0; i<len; i++) {
1132
            item_o = dta_types.get(i);
1133
            if (item_o instanceof DataType) {
1134
                item_dt = (DataType) item_o;
1135
                if (item_dt.getType() != DataTypes.GEOMETRY) {
1136
                    resp.add(item_dt);
1137
                }
1138
            }
1139
        }
1140
        return resp;
1141
    }
1142

    
1143
    private List<ComboItemGeomType> leaveSupportedGeomTypes(
1144
        List<ComboItemGeomType> all_types,
1145
        List<int[]> supported,
1146
        int index /* 0 for geom types, 1 for geom subtypes */) {
1147
        
1148
        if (supported == null) {
1149
            // all supported
1150
            return all_types;
1151
        }
1152
        
1153
        List<ComboItemGeomType> resp = new ArrayList<ComboItemGeomType>();
1154
        int len = all_types.size();
1155
        ComboItemGeomType item = null;
1156
        for (int i=0; i<len; i++) {
1157
            item = all_types.get(i);
1158
            if (isInNthElement(item.getGeomType(), supported, index)) {
1159
                resp.add(item);
1160
            }
1161
        }
1162
        return resp;
1163
    }
1164

    
1165

    
1166
    private boolean isInNthElement(int val, List<int[]> arr_list, int index) {
1167
        GeometryManager geomManager = GeometryLocator.getGeometryManager();
1168
        int len = arr_list.size();
1169
        int[] item = null;
1170
        for (int i=0; i<len; i++) {
1171
            item = arr_list.get(i);
1172
            if (item != null && item.length > index ) {
1173
                if( geomManager.isSubtype(item[index], val) ) {
1174
                    return true;
1175
                }
1176
            }
1177
        }
1178
        return false;
1179
    }
1180
    
1181
    private boolean dataTypeNeedsSize(int data_type) {
1182
        
1183
        if (data_type == DataTypes.FLOAT
1184
            || data_type == DataTypes.INT
1185
            || data_type == DataTypes.STRING) {
1186
            return true;
1187
        } else {
1188
            return false;
1189
        }
1190
    }
1191
    
1192
    private class SimpleTextCellRenderer extends DefaultTableCellRenderer {
1193

    
1194
        public SimpleTextCellRenderer() {
1195
            super();
1196
        }
1197
        /* (non-Javadoc)
1198
         * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
1199
         */
1200
        public Component getTableCellRendererComponent(
1201
            JTable table,
1202
            Object value, boolean isSelected, boolean hasFocus, int row,
1203
            int column) {
1204
            
1205
            TableModel tm = table.getModel();
1206
            Object new_val = "";            
1207
            Object type_obj = tm.getValueAt(row, COLUMN_TYPE);
1208
            if (type_obj instanceof ComboItemDataType) {
1209
                ComboItemDataType type_item = (ComboItemDataType) type_obj;
1210
                if (dataTypeNeedsSize(type_item.dataType.getType())) {
1211
                    new_val = getCurrentOr(value, "");
1212
                } else {
1213
                    new_val = Messages.getText("not_applicable");
1214
                }
1215
                return super.getTableCellRendererComponent(
1216
                    table, new_val, isSelected, hasFocus, row, column);
1217
            } else {
1218
                return super.getTableCellRendererComponent(
1219
                    table, value, isSelected, hasFocus, row, column);
1220
            }
1221
        }
1222
        
1223
        private Object getCurrentOr(Object v, String d) {
1224
            
1225
            if (v instanceof String) {
1226
                String parse_str = (String) v;
1227
                try {
1228
                    Integer.parseInt(parse_str);
1229
                    return v;
1230
                } catch (Exception ex) {
1231
                    // not a valid integer
1232
                    return d;
1233
                }
1234
            } else {
1235
                return v;
1236
            }
1237
        }
1238

    
1239
    }
1240

    
1241
    private class EnableLengthItemListener implements ItemListener {
1242
        
1243
        private TableModel theTableModel = null;
1244
        private JTable theTable = null;
1245
        
1246
        public EnableLengthItemListener(JTable t, boolean b) {
1247
            theTable = t;
1248
            theTableModel = t.getModel();
1249
        }
1250
        
1251
        public void itemStateChanged(final ItemEvent e) {
1252
            doUpdate(e);
1253
        }
1254

    
1255
        public void doUpdate(ItemEvent e) {
1256
            
1257
            Object src_obj = e.getSource();
1258
            if (src_obj instanceof JComboBox) {
1259
                
1260
                // one of the field type combos has changed
1261
                int len = theTableModel.getRowCount();
1262
                Object type_obj = null;
1263
                ComboItemDataType type_item = null;
1264
                for (int i=0; i<len; i++) {
1265
                    type_obj = theTableModel.getValueAt(i, COLUMN_TYPE);
1266
                    if (type_obj instanceof ComboItemDataType) {
1267
                        type_item = (ComboItemDataType) type_obj;
1268
                        if (dataTypeNeedsSize(type_item.dataType.getType())) {
1269
                            theTableModel.setValueAt(
1270
                                "20",
1271
                                i, COLUMN_LENGTH);
1272
                        } else {
1273
                            theTableModel.setValueAt(
1274
                                Messages.getText("not_applicable"),
1275
                                i, COLUMN_LENGTH);
1276
                        }
1277
                    }
1278
                }
1279
                theTable.validate(); // .revalidate(); // .repaint();
1280
            }
1281
        }
1282

    
1283
    }
1284
    
1285
    
1286
    
1287
    
1288
    
1289
}