25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.geotools; |
package skrueger.geotools; |
31 |
|
|
32 |
import java.util.HashMap; |
import java.util.HashMap; |
33 |
|
import java.util.LinkedHashSet; |
34 |
import java.util.List; |
import java.util.List; |
|
import java.util.Vector; |
|
35 |
|
|
36 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
37 |
import org.geotools.data.DefaultQuery; |
import org.geotools.data.DefaultQuery; |
41 |
import org.opengis.feature.simple.SimpleFeature; |
import org.opengis.feature.simple.SimpleFeature; |
42 |
import org.opengis.feature.simple.SimpleFeatureType; |
import org.opengis.feature.simple.SimpleFeatureType; |
43 |
import org.opengis.feature.type.AttributeDescriptor; |
import org.opengis.feature.type.AttributeDescriptor; |
44 |
|
import org.opengis.feature.type.Name; |
45 |
import org.opengis.filter.Filter; |
import org.opengis.filter.Filter; |
46 |
|
|
47 |
import schmitzm.geotools.feature.FeatureUtil; |
import schmitzm.geotools.feature.FeatureUtil; |
48 |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
import schmitzm.geotools.gui.FeatureCollectionTableModel; |
49 |
import skrueger.AttributeMetadata; |
import skrueger.AttributeMetadataImpl; |
50 |
|
import skrueger.AttributeMetadataInterface; |
51 |
|
|
52 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
53 |
|
|
54 |
/** |
/** |
55 |
* This class extends the the {@link FeatureCollectionTableModel} with the |
* This class extends the the {@link FeatureCollectionTableModel} with the |
56 |
* functionalities of the {@link AttributeMetadata}. |
* functionalities of the {@link AttributeMetadataImpl}. |
57 |
* <ul> |
* <ul> |
58 |
* <li>column names are translated according to |
* <li>column names are translated according to |
59 |
* {@link AttributeMetadata#getTitle()}</li> |
* {@link AttributeMetadataImpl#getTitle()}</li> |
60 |
* <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li> |
* <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li> |
61 |
* <li>Any filter defined in the {@link StyledFeaturesInterface} will be |
* <li>Any filter defined in the {@link StyledFeaturesInterface} will be |
62 |
* applied.</li> |
* applied.</li> |
63 |
* </ul> |
* </ul> |
64 |
* |
* |
65 |
* @author Stefan A. Krüger |
* @author Stefan A. Tzeggai |
66 |
*/ |
*/ |
67 |
public class StyledFeatureCollectionTableModel extends |
public class StyledFeatureCollectionTableModel extends |
68 |
FeatureCollectionTableModel { |
FeatureCollectionTableModel { |
69 |
final static private Logger LOGGER = Logger |
final static private Logger LOGGER = Logger |
70 |
.getLogger(StyledFeatureCollectionTableModel.class); |
.getLogger(StyledFeatureCollectionTableModel.class); |
71 |
/** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */ |
/** |
72 |
protected AttributeMetadataMap amdMap = null; |
* Contains the complete {@link AttributeMetadataImpl}-Map of the styled |
73 |
|
* layer. |
74 |
|
*/ |
75 |
|
protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null; |
76 |
/** Holds the current filter on the table */ |
/** Holds the current filter on the table */ |
77 |
protected Filter filter = null; |
protected Filter filter = null; |
78 |
/** Holds the Bounds for all features. Only set once during the constructor **/ |
/** Holds the Bounds for all features. Only set once during the constructor **/ |
83 |
*/ |
*/ |
84 |
protected String[] colTooltips = null; |
protected String[] colTooltips = null; |
85 |
|
|
86 |
/** A cache for the #sortedValuesVisibleOnly() **/ |
/** |
87 |
protected List<AttributeMetadata> amdMapVisibleOnly = null; |
* A cache for the #sortedValuesVisibleOnly(). WHen the amd is changed |
88 |
|
* externally, this object will stay the same |
89 |
|
**/ |
90 |
|
protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null; |
91 |
|
|
92 |
/** |
/** |
93 |
* Creates a new table model for a styled layer. |
* Creates a new table model for a styled layer. |
104 |
|
|
105 |
/** |
/** |
106 |
* This overwritten method filters the values for NODATA-values defined in |
* This overwritten method filters the values for NODATA-values defined in |
107 |
* the {@link AttributeMetadata} |
* the {@link AttributeMetadataImpl} |
108 |
*/ |
*/ |
109 |
@Override |
@Override |
110 |
public Object getValueAt(int row, int col) { |
public Object getValueAt(int row, int col) { |
111 |
Object rawValue = super.getValueAt(row, col); |
Object rawValue = super.getValueAt(row, col); |
112 |
return amdMap.sortedValuesVisibleOnly().get(col).fiterNodata(rawValue); |
return amdMapVisibleOnly.get(col).fiterNodata(rawValue); |
113 |
} |
} |
114 |
|
|
115 |
/** |
/** |
116 |
* Sets a new data source for the table. |
* Sets a new data source for the table. |
117 |
* |
* |
118 |
* @param fs |
* @param fs |
119 |
* the feature source |
* the feature source |
120 |
* @param amdm |
* @param amdm |
121 |
* {@link AttributeMetadata}-Map to define the visible attributes |
* {@link AttributeMetadataImpl}-Map to define the visible |
122 |
* and translation |
* attributes and translation |
123 |
*/ |
*/ |
124 |
protected void setFeatureSource( |
protected void setFeatureSource( |
125 |
FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
FeatureSource<SimpleFeatureType, SimpleFeature> fs, |
126 |
AttributeMetadataMap amdm, Filter filter) throws Exception { |
AttributeMetadataMap<? extends AttributeMetadataInterface> amdm, |
127 |
|
Filter filter) throws Exception { |
128 |
|
|
129 |
if (filter == null) |
if (filter == null) |
130 |
filter = Filter.INCLUDE; |
filter = Filter.INCLUDE; |
142 |
final SimpleFeatureType schema = fs.getSchema(); |
final SimpleFeatureType schema = fs.getSchema(); |
143 |
Query query = new DefaultQuery(schema.getTypeName(), filter); |
Query query = new DefaultQuery(schema.getTypeName(), filter); |
144 |
if (amdm != null) { |
if (amdm != null) { |
145 |
Vector<String> visibleAttrNames = new Vector<String>(); |
LinkedHashSet<String> visibleAttrNames = new LinkedHashSet<String>(); |
146 |
|
|
147 |
// Add the column with the geometry (usually "the_geom") always |
// Add the column with the geometry (usually "the_geom") always |
148 |
visibleAttrNames.add(schema.getGeometryDescriptor() |
visibleAttrNames.add(schema.getGeometryDescriptor() |
149 |
.getLocalName()); |
.getLocalName()); |
150 |
|
|
151 |
// Add other visible attributes as ordered by weights |
// Add other visible attributes as ordered by weights |
152 |
for (AttributeMetadata a : amdMapVisibleOnly) { |
for (AttributeMetadataInterface a : amdMapVisibleOnly) { |
153 |
visibleAttrNames.add(a.getLocalName()); |
visibleAttrNames.add(a.getLocalName()); |
154 |
} |
} |
155 |
|
|
178 |
* @param fs |
* @param fs |
179 |
* the feature source |
* the feature source |
180 |
* @param amd |
* @param amd |
181 |
* {@link AttributeMetadata}-Map to define the visible attributes |
* {@link AttributeMetadataImpl}-Map to define the visible |
182 |
* and translation |
* attributes and translation |
183 |
*/ |
*/ |
184 |
public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) { |
public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) { |
185 |
try { |
try { |
216 |
SimpleFeatureType schema = featureArray[0].getFeatureType(); |
SimpleFeatureType schema = featureArray[0].getFeatureType(); |
217 |
// Pruefen, welche Attribute angezeigt werden |
// Pruefen, welche Attribute angezeigt werden |
218 |
attrTypes.clear(); |
attrTypes.clear(); |
219 |
for (AttributeMetadata amd : amdMapVisibleOnly) { |
for (AttributeMetadataInterface amd : amdMapVisibleOnly) { |
220 |
AttributeDescriptor type = schema.getDescriptor(amd.getName()); |
Name name = amd.getName(); |
221 |
|
AttributeDescriptor type = schema.getDescriptor(name); |
222 |
|
// if type can not be determined by complete name, |
223 |
|
// try only the local name |
224 |
|
if (type == null) |
225 |
|
type = schema.getDescriptor(name.getLocalPart()); |
226 |
if (attrFilter == null || attrFilter.accept(type)) |
if (attrFilter == null || attrFilter.accept(type)) |
227 |
attrTypes.add(type); |
attrTypes.add(type); |
228 |
} |
} |
233 |
colClass = new Class[attrTypes.size()]; |
colClass = new Class[attrTypes.size()]; |
234 |
attrIdxForCol = new int[attrTypes.size()]; |
attrIdxForCol = new int[attrTypes.size()]; |
235 |
for (int i = 0; i < colNames.length; i++) { |
for (int i = 0; i < colNames.length; i++) { |
236 |
AttributeDescriptor descriptor = schema |
Name name = amdMapVisibleOnly.get(i).getName(); |
237 |
.getDescriptor(amdMapVisibleOnly.get(i).getName()); |
AttributeDescriptor descriptor = schema.getDescriptor(name); |
238 |
|
// if type can not be determined by complete name, |
239 |
|
// try only the local name |
240 |
|
if (descriptor == null) |
241 |
|
descriptor = schema.getDescriptor(name.getLocalPart()); |
242 |
|
|
243 |
// Not so nice in 26: find the index of an attribute... |
// Not so nice in 26: find the index of an attribute... |
244 |
int idx = schema.getAttributeDescriptors().indexOf(descriptor); |
int idx = schema.getAttributeDescriptors().indexOf(descriptor); |
247 |
String attName = schema.getAttributeDescriptors().get(idx) |
String attName = schema.getAttributeDescriptors().get(idx) |
248 |
.getLocalName(); |
.getLocalName(); |
249 |
colNames[i] = amdMap.get(attName).getTitle().toString(); |
colNames[i] = amdMap.get(attName).getTitle().toString(); |
250 |
AttributeMetadata amd = amdMap.get(attName); |
AttributeMetadataInterface amd = amdMap.get(attName); |
251 |
colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>" |
colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>" |
252 |
+ amd.getName() + "</html>"; |
+ amd.getName() + "</html>"; |
253 |
colClass[i] = schema.getAttributeDescriptors().get(idx) |
colClass[i] = schema.getAttributeDescriptors().get(idx) |