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 / featuretable / SimpleFeaturesTableModel.java @ 44340
History | View | Annotate | Download (5.36 KB)
1 |
package org.gvsig.fmap.dal.swing.impl.featuretable; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
import java.util.Iterator; |
5 |
import java.util.List; |
6 |
import javax.swing.table.AbstractTableModel; |
7 |
import org.gvsig.fmap.dal.complements.Search; |
8 |
import org.gvsig.fmap.dal.exception.DataException; |
9 |
import org.gvsig.fmap.dal.feature.Feature; |
10 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
11 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
12 |
import org.gvsig.fmap.dal.feature.FeatureType; |
13 |
import org.gvsig.tools.ToolsLocator; |
14 |
import org.gvsig.tools.util.UnmodifiableBasicList; |
15 |
|
16 |
/**
|
17 |
*
|
18 |
* @author jjdelcerro
|
19 |
*/
|
20 |
public class SimpleFeaturesTableModel |
21 |
extends AbstractTableModel |
22 |
implements UnmodifiableBasicList<Feature> {
|
23 |
|
24 |
private final List<Feature> features; |
25 |
private final List<String> columnNames; |
26 |
private final FeatureType featureType; |
27 |
|
28 |
public SimpleFeaturesTableModel(FeatureStore store) throws DataException { |
29 |
this(store.getDefaultFeatureType(), null, store.getFeatures()); |
30 |
} |
31 |
|
32 |
public SimpleFeaturesTableModel(FeatureType featureType) {
|
33 |
this(featureType, null, null); |
34 |
} |
35 |
|
36 |
public SimpleFeaturesTableModel(FeatureType featureType, List<String> columnNames, List<Feature> features) { |
37 |
this.features = features;
|
38 |
this.featureType = featureType;
|
39 |
if (columnNames == null || columnNames.isEmpty()) { |
40 |
this.columnNames = new ArrayList<>(); |
41 |
Search search = (Search) ToolsLocator.getComplementsManager().get( |
42 |
Search.COMPLEMENT_MANE, featureType |
43 |
); |
44 |
List<Search.OrderedAttribute> attributos = search.getOrderedAttributes(
|
45 |
Search.BASIC_TYPES_FILTER, |
46 |
Search.STR_INT_LONG_LABEL_ORDER, |
47 |
12
|
48 |
); |
49 |
for (Search.OrderedAttribute attrdesc : attributos) {
|
50 |
this.columnNames.add(attrdesc.getDescriptor().getName());
|
51 |
} |
52 |
} else {
|
53 |
this.columnNames = columnNames;
|
54 |
} |
55 |
} |
56 |
|
57 |
public List<Feature> getFeatures() { |
58 |
return this.features; |
59 |
} |
60 |
|
61 |
@Override
|
62 |
public int getRowCount() { |
63 |
if (this.features == null) { |
64 |
return 0; |
65 |
} |
66 |
return this.features.size(); |
67 |
} |
68 |
|
69 |
@Override
|
70 |
public int getColumnCount() { |
71 |
return this.columnNames.size(); |
72 |
} |
73 |
|
74 |
@Override
|
75 |
public String getColumnName(int columnIndex) { |
76 |
String attrName = this.columnNames.get(columnIndex); |
77 |
if (this.featureType == null) { |
78 |
return attrName;
|
79 |
} |
80 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
81 |
if (attrdesc == null) { |
82 |
return "C" + columnIndex; |
83 |
} |
84 |
return attrdesc.getLocalizedShortLabel();
|
85 |
} |
86 |
|
87 |
@Override
|
88 |
public Class<?> getColumnClass(int columnIndex) { |
89 |
if (this.featureType == null) { |
90 |
return String.class; |
91 |
} |
92 |
String attrName = this.columnNames.get(columnIndex); |
93 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
94 |
if (attrdesc == null) { |
95 |
return String.class; |
96 |
} |
97 |
if( attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList() ) {
|
98 |
return String.class; |
99 |
} |
100 |
Class theClass = attrdesc.getDataType().getDefaultClass();
|
101 |
if( theClass==null ) { |
102 |
return String.class; |
103 |
} |
104 |
return theClass;
|
105 |
} |
106 |
|
107 |
@Override
|
108 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
109 |
return false; |
110 |
} |
111 |
|
112 |
@Override
|
113 |
public Feature get(int position) { |
114 |
if (this.features == null) { |
115 |
return null; |
116 |
} |
117 |
Feature feature = this.features.get(position);
|
118 |
return feature;
|
119 |
} |
120 |
|
121 |
@Override
|
122 |
public Object getValueAt(int rowIndex, int columnIndex) { |
123 |
if (this.features == null) { |
124 |
return null; |
125 |
} |
126 |
try {
|
127 |
Feature feature = this.features.get(rowIndex);
|
128 |
String attrName = this.columnNames.get(columnIndex); |
129 |
Object value = feature.get(attrName);
|
130 |
FeatureAttributeDescriptor attrdesc = this.featureType.getAttributeDescriptor(attrName);
|
131 |
if (attrdesc != null) { |
132 |
if( attrdesc.isForeingKey() && attrdesc.getForeingKey().isClosedList() ) {
|
133 |
value = attrdesc.getForeingKey().getLabelForValue(value); |
134 |
} |
135 |
} |
136 |
return value;
|
137 |
} catch (Throwable th) { |
138 |
return null; |
139 |
} |
140 |
} |
141 |
|
142 |
@Override
|
143 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
144 |
|
145 |
} |
146 |
|
147 |
@Override
|
148 |
public List<Feature> toList() { |
149 |
return this.features; |
150 |
} |
151 |
|
152 |
@Override
|
153 |
public boolean isEmpty() { |
154 |
return this.features.isEmpty(); |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public int size() { |
159 |
return this.features.size(); |
160 |
} |
161 |
|
162 |
@Override
|
163 |
public Iterator<Feature> iterator() { |
164 |
return this.features.iterator(); |
165 |
} |
166 |
|
167 |
} |