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