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 the {@link FeatureCollectionTableModel} with the |
31 |
|
* functionalities of the {@link AttributeMetaData} (AMD) of {@linkplain StyledMapInterface styled objects}. |
32 |
|
* <ul> |
33 |
|
* <li>column names are translated according to (AMD)</li> |
34 |
|
* <li>columns are hidden according to |
35 |
|
* </ul> |
36 |
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
37 |
|
* |
38 |
|
*/ |
39 |
public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel { |
public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel { |
40 |
|
|
41 |
|
protected Map<Integer,AttributeMetaData> visibleAMD = null; |
42 |
|
|
43 |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
44 |
super(null); |
super(); |
45 |
|
setFeatureCollection(map); |
46 |
} |
} |
47 |
|
|
48 |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
49 |
super(null); |
super(); |
50 |
|
setFeatureCollection(map); |
51 |
} |
} |
52 |
|
|
53 |
public String[] createColumnNames() { |
protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception { |
54 |
return new String[0]; |
FeatureCollection fc = null; |
55 |
|
this.visibleAMD = null; |
56 |
|
if ( fs != null ) { |
57 |
|
Query query = new DefaultQuery(); |
58 |
|
if ( amd != null ) { |
59 |
|
// determine the names of the visible Attributes |
60 |
|
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
61 |
|
Vector<String> visibleAttrNames = new Vector<String>(); |
62 |
|
for ( int attrIdx : visibleAMD.keySet() ) |
63 |
|
visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() ); |
64 |
|
// create a query for the visible attributes |
65 |
|
query = new DefaultQuery( |
66 |
|
fs.getSchema().getTypeName(), |
67 |
|
Filter.INCLUDE, |
68 |
|
visibleAttrNames.toArray(new String[0]) |
69 |
|
); |
70 |
|
} |
71 |
|
fc = fs.getFeatures(query); |
72 |
|
} |
73 |
|
setFeatureCollection( fc ); |
74 |
|
} |
75 |
|
|
76 |
|
public void setFeatureCollection(StyledFeatureCollectionInterface map) { |
77 |
|
try { |
78 |
|
if ( map == null ) |
79 |
|
setFeatureSource(null,null); |
80 |
|
else { |
81 |
|
FeatureCollection fc = map.getGeoObject(); |
82 |
|
String fcName = fc.getFeatureType().getTypeName(); |
83 |
|
FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName); |
84 |
|
setFeatureSource(fs, map.getAttributeMetaDataMap()); |
85 |
|
} |
86 |
|
} catch (Exception err) { |
87 |
|
throw new RuntimeException(err); |
88 |
|
} |
89 |
} |
} |
90 |
|
|
91 |
public int getRowCount() { |
public void setFeatureCollection(StyledFeatureSourceInterface map) { |
92 |
return 0; |
try { |
93 |
|
if ( map == null ) |
94 |
|
setFeatureSource(null,null); |
95 |
|
else |
96 |
|
setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap()); |
97 |
|
} catch (Exception err) { |
98 |
|
throw new RuntimeException(err); |
99 |
|
} |
100 |
} |
} |
101 |
|
|
102 |
public Object getValueAt(int row, int col) { |
@Override |
103 |
return ""; |
public void reorganize() { |
104 |
|
super.reorganize(); |
105 |
|
// translate the column names |
106 |
|
if ( visibleAMD != null ) { |
107 |
|
Iterator<Integer> keys = visibleAMD.keySet().iterator(); |
108 |
|
for (int i=0; keys.hasNext(); i++) |
109 |
|
colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString(); |
110 |
|
} |
111 |
} |
} |
112 |
} |
} |