Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.swing / org.gvsig.fmap.dal.swing.impl / src / main / java / org / gvsig / fmap / dal / swing / impl / featuretype / DefaultFeatureTypePanel.java @ 44077

History | View | Annotate | Download (4.95 KB)

1
package org.gvsig.fmap.dal.swing.impl.featuretype;
2

    
3
import java.awt.BorderLayout;
4
import java.util.Objects;
5
import javax.swing.JComponent;
6
import javax.swing.event.ListSelectionEvent;
7
import javax.swing.event.ListSelectionListener;
8
import javax.swing.table.AbstractTableModel;
9
import javax.swing.table.TableModel;
10
import org.gvsig.fmap.dal.feature.EditableFeatureType;
11
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
12
import org.gvsig.fmap.dal.feature.FeatureType;
13

    
14
/**
15
 *
16
 * @author jjdelcerro
17
 */
18
public class DefaultFeatureTypePanel 
19
        extends FeatureTypePanelView
20
        implements FeatureTypePanel
21
    {
22

    
23
    private class FeatureTypeTableModel extends AbstractTableModel {
24

    
25
        private final FeatureType featureType;
26
        private final String[] columnNames = new String[] {
27
          "Name",
28
          "Type",
29
          "Size",
30
          "Precision",
31
          "Default value",
32
          "Calcualed"
33
        };
34
        private final Class[] columnClasses = new Class[] {
35
          String.class,
36
          String.class,
37
          Integer.class,
38
          Integer.class,
39
          String.class,
40
          Boolean.class
41
        };
42
        
43
        public FeatureTypeTableModel() {
44
            this.featureType = null;
45
        }
46
        
47
        public FeatureTypeTableModel(FeatureType featureType) {
48
            this.featureType = featureType;
49
        }
50
        
51
        @Override
52
        public int getRowCount() {
53
            if( this.featureType==null ) {
54
                return 0;
55
            }
56
            return this.featureType.size();
57
        }
58

    
59
        @Override
60
        public int getColumnCount() {
61
            if( this.featureType==null ) {
62
                return 0;
63
            }
64
            return this.columnNames.length;
65
        }
66

    
67
        @Override
68
        public String getColumnName(int columnIndex) {
69
            if( this.featureType==null ) {
70
                return "";
71
            }
72
            return this.columnNames[columnIndex];
73
        }
74

    
75
        @Override
76
        public Class<?> getColumnClass(int columnIndex) {
77
            if( this.featureType==null ) {
78
                return String.class;
79
            }
80
            return this.columnClasses[columnIndex];
81
        }
82

    
83
        @Override
84
        public boolean isCellEditable(int rowIndex, int columnIndex) {
85
            return false;
86
        }
87

    
88
        @Override
89
        public Object getValueAt(int rowIndex, int columnIndex) {
90
            if( this.featureType==null ) {
91
                return "";
92
            }
93
            FeatureAttributeDescriptor descriptor = this.featureType.getAttributeDescriptor(rowIndex);
94
            switch(columnIndex) {
95
                case 0:
96
                    return descriptor.getName();
97
                case 1:
98
                    return descriptor.getDataTypeName();
99
                case 2:
100
                    return descriptor.getSize();
101
                case 3:
102
                    return descriptor.getPrecision();
103
                case 4:
104
                    return Objects.toString(descriptor.getDefaultValue(),"");
105
                case 5:
106
                    return descriptor.isComputed();
107
                default:
108
                    return "";
109
            }
110
        }
111

    
112
        @Override
113
        public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
114
        }
115
        
116
    }
117
    
118
    private DefaultFeatureTypeAttributePanel descriptorPanel;
119
    private FeatureType featureType;
120
        
121
    public DefaultFeatureTypePanel() {
122
        this.initComponents();
123
    }
124

    
125
    private void initComponents() {
126
        TableModel model = new FeatureTypeTableModel();
127
        this.tblFields.setModel(model);
128
        this.tblFields.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
129
            @Override
130
            public void valueChanged(ListSelectionEvent e) {
131
                doRowSelected();
132
            }
133
        });
134
        this.descriptorPanel = new DefaultFeatureTypeAttributePanel();
135
        this.pnlField.setLayout(new BorderLayout());
136
        this.pnlField.add(this.descriptorPanel, BorderLayout.CENTER);
137
        this.descriptorPanel.setEnabled(false);
138
    }
139
       
140
    private void doRowSelected() {
141
        int row = this.tblFields.getSelectedRow();
142
        if( row<0 ) {
143
            return;
144
        }
145
        FeatureAttributeDescriptor descriptor = this.featureType.getAttributeDescriptor(row);
146
        this.descriptorPanel.put(descriptor);
147
        this.descriptorPanel.setEnabled(true);
148
    }
149
    
150
    @Override
151
    public JComponent asJComponent() {
152
        return this;
153
    }
154

    
155
    public void setReadonly(boolean readonly) {
156
        
157
    }
158

    
159
    @Override
160
    public EditableFeatureType fetch(EditableFeatureType type) {
161
        return type;
162
    }
163

    
164
    @Override
165
    public void put(FeatureType type) {
166
        this.featureType = type;
167
        TableModel model = new FeatureTypeTableModel(type);
168
        this.tblFields.setModel(model);
169
        if( type.size()>0 ) {
170
            this.tblFields.getSelectionModel().setSelectionInterval(0, 0);
171
        }
172
    }
173

    
174
}