24 |
|
|
25 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
26 |
import skrueger.AttributeMetaData; |
import skrueger.AttributeMetaData; |
27 |
|
import skrueger.i8n.I8NUtil; |
28 |
|
import skrueger.i8n.Translation; |
29 |
|
|
30 |
/** |
/** |
31 |
* This class extends the the {@link FeatureCollectionTableModel} with the |
* This class extends the the {@link FeatureCollectionTableModel} with the |
32 |
* functionalities of the {@link AttributeMetaData} (AMD) of {@linkplain StyledMapInterface styled objects}. |
* functionalities of the {@link AttributeMetaData} of |
33 |
|
* {@linkplain StyledMapInterface styled objects}. |
34 |
* <ul> |
* <ul> |
35 |
* <li>column names are translated according to (AMD)</li> |
* <li>column names are translated according to |
36 |
* <li>columns are hidden according to |
* {@link AttributeMetaData#getTitle()}</li> |
37 |
* </ul> |
* <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li> |
38 |
* @author <a href="mailto:[email protected]">Martin Schmitz</a> (University of Bonn/Germany) |
* </ul> |
39 |
* |
* |
40 |
|
* @author <a href="mailto:[email protected]">Martin Schmitz</a> |
41 |
|
* (University of Bonn/Germany) |
42 |
|
* |
43 |
*/ |
*/ |
44 |
public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel { |
public class StyledFeatureCollectionTableModel extends |
45 |
|
FeatureCollectionTableModel { |
46 |
protected Map<Integer,AttributeMetaData> visibleAMD = null; |
|
47 |
|
protected Map<Integer, AttributeMetaData> visibleAMD = null; |
48 |
|
|
49 |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) { |
50 |
|
this(map,Filter.INCLUDE); |
51 |
|
} |
52 |
|
|
53 |
|
public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) { |
54 |
super(); |
super(); |
55 |
setFeatureCollection(map); |
setFeatureCollection(map, filter); |
56 |
} |
} |
57 |
|
|
58 |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) { |
59 |
|
this(map,Filter.INCLUDE); |
60 |
|
} |
61 |
|
|
62 |
|
public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) { |
63 |
super(); |
super(); |
64 |
setFeatureCollection(map); |
setFeatureCollection(map, filter); |
65 |
} |
} |
66 |
|
|
67 |
protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception { |
protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception { |
68 |
|
this.visibleAMD = null; |
69 |
|
if ( filter == null ) |
70 |
|
filter = Filter.INCLUDE; |
71 |
|
|
72 |
FeatureCollection fc = null; |
FeatureCollection fc = null; |
73 |
this.visibleAMD = null; |
if (fs != null) { |
|
if ( fs != null ) { |
|
74 |
Query query = new DefaultQuery(); |
Query query = new DefaultQuery(); |
75 |
if ( amd != null ) { |
if (amd != null) { |
76 |
// determine the names of the visible Attributes |
// determine the names of the visible Attributes |
77 |
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
78 |
Vector<String> visibleAttrNames = new Vector<String>(); |
Vector<String> visibleAttrNames = new Vector<String>(); |
79 |
for ( int attrIdx : visibleAMD.keySet() ) |
// Add the column with the geometry (usually "the_geom") |
80 |
visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() ); |
visibleAttrNames.add(fs.getSchema().getDefaultGeometry().getLocalName()); |
81 |
// create a query for the visible attributes |
for (int attrIdx : visibleAMD.keySet()) |
82 |
query = new DefaultQuery( |
visibleAttrNames.add(fs.getSchema().getAttributeType(attrIdx).getLocalName()); |
83 |
fs.getSchema().getTypeName(), |
|
84 |
Filter.INCLUDE, |
// create a query for the visible attributes |
85 |
visibleAttrNames.toArray(new String[0]) |
String[] properties = visibleAttrNames.toArray(new String[0]); |
86 |
); |
query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties); |
87 |
} |
} |
88 |
fc = fs.getFeatures(query); |
fc = fs.getFeatures(query); |
89 |
} |
} |
90 |
setFeatureCollection( fc ); |
setFeatureCollection(fc); |
91 |
} |
} |
92 |
|
|
93 |
public void setFeatureCollection(StyledFeatureCollectionInterface map) { |
public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) { |
94 |
try { |
try { |
95 |
if ( map == null ) |
if (map == null) |
96 |
setFeatureSource(null,null); |
setFeatureSource(null, null, null); |
97 |
else { |
else { |
98 |
FeatureCollection fc = map.getGeoObject(); |
FeatureCollection fc = map.getGeoObject(); |
99 |
String fcName = fc.getFeatureType().getTypeName(); |
String fcName = fc.getFeatureType().getTypeName(); |
100 |
FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName); |
FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName); |
101 |
setFeatureSource(fs, map.getAttributeMetaDataMap()); |
setFeatureSource(fs, map.getAttributeMetaDataMap(), filter); |
102 |
} |
} |
103 |
} catch (Exception err) { |
} catch (Exception err) { |
104 |
throw new RuntimeException(err); |
throw new RuntimeException(err); |
105 |
} |
} |
106 |
} |
} |
107 |
|
|
108 |
public void setFeatureCollection(StyledFeatureSourceInterface map) { |
public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) { |
109 |
try { |
try { |
110 |
if ( map == null ) |
if (map == null) |
111 |
setFeatureSource(null,null); |
setFeatureSource(null, null, null); |
112 |
else |
else |
113 |
setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap()); |
setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap(), filter); |
114 |
} catch (Exception err) { |
} catch (Exception err) { |
115 |
throw new RuntimeException(err); |
throw new RuntimeException(err); |
116 |
} |
} |
117 |
} |
} |
118 |
|
|
119 |
@Override |
@Override |
120 |
public void reorganize() { |
public void reorganize() { |
121 |
super.reorganize(); |
super.reorganize(); |
122 |
// translate the column names |
// translate the column names |
123 |
if ( visibleAMD != null ) { |
if (visibleAMD != null) { |
124 |
Iterator<Integer> keys = visibleAMD.keySet().iterator(); |
Iterator<Integer> keys = visibleAMD.keySet().iterator(); |
125 |
for (int i=0; keys.hasNext(); i++) |
for (int i = 0; i < colNames.length && keys.hasNext(); i++) { |
126 |
colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString(); |
Translation title = visibleAMD.get(keys.next()).getTitle(); |
127 |
|
if (!I8NUtil.isEmpty(title)) { |
128 |
|
System.out.println("set colname " + i + " to " + title.toString()); |
129 |
|
colNames[i] = title.toString(); |
130 |
|
} |
131 |
|
} |
132 |
} |
} |
133 |
|
fireTableStructureChanged(); |
134 |
} |
} |
135 |
} |
} |