10 |
**/ |
**/ |
11 |
package skrueger.geotools; |
package skrueger.geotools; |
12 |
|
|
13 |
|
import java.util.Iterator; |
14 |
|
import java.util.Map; |
15 |
|
import java.util.TreeMap; |
16 |
|
import java.util.Vector; |
17 |
|
|
18 |
|
import org.geotools.data.DefaultQuery; |
19 |
|
import org.geotools.data.FeatureSource; |
20 |
|
import org.geotools.data.Query; |
21 |
|
import org.geotools.data.memory.MemoryDataStore; |
22 |
|
import org.geotools.feature.FeatureCollection; |
23 |
|
import org.opengis.filter.Filter; |
24 |
|
|
25 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
26 |
|
import skrueger.AttributeMetaData; |
27 |
|
|
28 |
|
|
29 |
|
/** |
30 |
|
* This class extends the |
31 |
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
32 |
|
* |
33 |
|
*/ |
34 |
public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel { |
public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel { |
35 |
|
|
36 |
|
protected Map<Integer,AttributeMetaData> visibleAMD = null; |
37 |
|
|
38 |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
39 |
super(null); |
super(); |
40 |
|
setFeatureCollection(map); |
41 |
} |
} |
42 |
|
|
43 |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
44 |
super(null); |
super(); |
45 |
|
setFeatureCollection(map); |
46 |
} |
} |
47 |
|
|
48 |
public String[] createColumnNames() { |
protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception { |
49 |
return new String[0]; |
FeatureCollection fc = null; |
50 |
|
this.visibleAMD = new TreeMap<Integer, AttributeMetaData>(); |
51 |
|
if ( fs != null ) { |
52 |
|
Query query = new DefaultQuery(); |
53 |
|
if ( amd != null ) { |
54 |
|
// determine the names of the visible Attributes |
55 |
|
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
56 |
|
Vector<String> visibleAttrNames = new Vector<String>(); |
57 |
|
for ( int attrIdx : visibleAMD.keySet() ) |
58 |
|
visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() ); |
59 |
|
// create a query for the visible attributes |
60 |
|
query = new DefaultQuery( |
61 |
|
fs.getSchema().getTypeName(), |
62 |
|
Filter.INCLUDE, |
63 |
|
visibleAttrNames.toArray(new String[0]) |
64 |
|
); |
65 |
|
} |
66 |
|
fc = fs.getFeatures(query); |
67 |
|
} |
68 |
|
setFeatureCollection( fc ); |
69 |
|
} |
70 |
|
|
71 |
|
public void setFeatureCollection(StyledFeatureCollectionInterface map) { |
72 |
|
try { |
73 |
|
if ( map == null ) |
74 |
|
setFeatureSource(null,null); |
75 |
|
else { |
76 |
|
FeatureCollection fc = map.getGeoObject(); |
77 |
|
String fcName = fc.getFeatureType().getTypeName(); |
78 |
|
FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName); |
79 |
|
setFeatureSource(fs, map.getAttributeMetaDataMap()); |
80 |
|
} |
81 |
|
} catch (Exception err) { |
82 |
|
throw new RuntimeException(err); |
83 |
|
} |
84 |
} |
} |
85 |
|
|
86 |
public int getRowCount() { |
public void setFeatureCollection(StyledFeatureSourceInterface map) { |
87 |
return 0; |
try { |
88 |
|
if ( map == null ) |
89 |
|
setFeatureSource(null,null); |
90 |
|
else |
91 |
|
setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap()); |
92 |
|
} catch (Exception err) { |
93 |
|
throw new RuntimeException(err); |
94 |
|
} |
95 |
} |
} |
96 |
|
|
97 |
public Object getValueAt(int row, int col) { |
@Override |
98 |
return ""; |
public void reorganize() { |
99 |
|
super.reorganize(); |
100 |
|
// translate the column names |
101 |
|
Iterator<Integer> keys = visibleAMD.keySet().iterator(); |
102 |
|
for (int i=0; keys.hasNext(); i++) |
103 |
|
colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString(); |
104 |
} |
} |
105 |
|
|
106 |
} |
} |