22 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
23 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
24 |
|
|
25 |
|
import com.vividsolutions.jts.geom.Envelope; |
26 |
|
|
27 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
28 |
import skrueger.AttributeMetaData; |
import skrueger.AttributeMetaData; |
29 |
import skrueger.i8n.I8NUtil; |
import skrueger.i8n.I8NUtil; |
50 |
protected Map<Integer, AttributeMetaData> origAMD = null; |
protected Map<Integer, AttributeMetaData> origAMD = null; |
51 |
/** Holds the current filter on the table */ |
/** Holds the current filter on the table */ |
52 |
protected Filter filter = null; |
protected Filter filter = null; |
53 |
|
/** Holds the Bounds for all features. Only set once during the constructor **/ |
54 |
|
protected Envelope bounds; |
55 |
|
|
56 |
/** |
/** |
57 |
* Creates a new table model for a styled map. |
* Creates a new table model for a styled map. |
98 |
protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception { |
protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception { |
99 |
if ( filter == null ) |
if ( filter == null ) |
100 |
filter = Filter.INCLUDE; |
filter = Filter.INCLUDE; |
101 |
|
|
102 |
this.featureSource = fs; |
this.featureSource = fs; |
103 |
this.filter = filter; |
this.filter = filter; |
104 |
this.origAMD = amd; |
this.origAMD = amd; |
106 |
|
|
107 |
FeatureCollection fc = null; |
FeatureCollection fc = null; |
108 |
if (fs != null) { |
if (fs != null) { |
109 |
Query query = new DefaultQuery(); |
|
110 |
|
bounds = fs.getBounds(); |
111 |
|
|
112 |
|
Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter); |
113 |
if (amd != null) { |
if (amd != null) { |
114 |
// determine the names of the visible Attributes |
// determine the names of the visible Attributes |
115 |
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true); |
121 |
|
|
122 |
// create a query for the visible attributes |
// create a query for the visible attributes |
123 |
String[] properties = visibleAttrNames.toArray(new String[0]); |
String[] properties = visibleAttrNames.toArray(new String[0]); |
124 |
|
|
125 |
query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties); |
query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties); |
126 |
} |
} |
127 |
fc = fs.getFeatures(query); |
fc = fs.getFeatures(query); |
128 |
|
|
129 |
|
// FAILS:!!!, even with query = new DefaultQuery(fs.getSchema().getTypeName(), filter); |
130 |
|
// java.lang.UnsupportedOperationException: Unknown feature |
131 |
|
// attribute: PQM_MOD |
132 |
|
// at |
133 |
|
// schmitzm.geotools.feature.FeatureOperationTree.evaluate(FeatureOperationTree.java:93) |
134 |
|
// bounds = fc.getBounds(); |
135 |
|
// SK, 17.4.2009 |
136 |
|
// |
137 |
|
// System.out.println("Filter = "+filter); |
138 |
|
// System.out.println("Size of FC = "+fc.size()); |
139 |
|
// System.out.println("anz att= "+fc.getNumberOfAttributes()); |
140 |
} |
} |
141 |
setFeatureCollection(fc); |
setFeatureCollection(fc); |
142 |
} |
} |
193 |
throw new RuntimeException(err); |
throw new RuntimeException(err); |
194 |
} |
} |
195 |
} |
} |
196 |
|
|
197 |
|
/** |
198 |
|
* @return <code>Filter.INCLUDE</code> or the {@link Filter} applied to the Features |
199 |
|
*/ |
200 |
|
public Filter getFilter() { |
201 |
|
return this.filter; |
202 |
|
} |
203 |
|
|
204 |
/** |
/** |
205 |
* After calling {@code super.reorganize(.)} this method replaced the |
* After calling {@code super.reorganize(.)} this method replaced the |
216 |
for (int i = 0; i < colNames.length && keys.hasNext(); i++) { |
for (int i = 0; i < colNames.length && keys.hasNext(); i++) { |
217 |
Translation title = visibleAMD.get(keys.next()).getTitle(); |
Translation title = visibleAMD.get(keys.next()).getTitle(); |
218 |
if (!I8NUtil.isEmpty(title)) { |
if (!I8NUtil.isEmpty(title)) { |
219 |
System.out.println("set colname " + i + " to " + title.toString()); |
// System.out.println("set colname " + i + " to " + title.toString()); |
220 |
colNames[i] = title.toString(); |
colNames[i] = title.toString(); |
221 |
} |
} |
222 |
} |
} |
224 |
if ( fireTableStructureChanged ) |
if ( fireTableStructureChanged ) |
225 |
fireTableStructureChanged(); |
fireTableStructureChanged(); |
226 |
} |
} |
227 |
|
|
228 |
|
/** |
229 |
|
* @returns Cached bounds for the whole dataset (without applying the |
230 |
|
* filter) or <code>null</code> |
231 |
|
*/ |
232 |
|
public Envelope getBounds() { |
233 |
|
return bounds; |
234 |
|
} |
235 |
} |
} |