/[schmitzm]/trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 788 by alfonx, Tue Apr 6 12:18:52 2010 UTC revision 1265 by alfonx, Fri Nov 12 19:17:47 2010 UTC
# Line 25  Line 25 
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;
# Line 41  import org.geotools.feature.FeatureColle Line 41  import org.geotools.feature.FeatureColle
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;
# Line 61  import com.vividsolutions.jts.geom.Envel Line 62  import com.vividsolutions.jts.geom.Envel
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 AttributeMetadataImpl}-Map of the styled layer. */          /**
72             * Contains the complete {@link AttributeMetadataImpl}-Map of the styled
73             * layer.
74             */
75          protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null;          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;
# Line 79  public class StyledFeatureCollectionTabl Line 83  public class StyledFeatureCollectionTabl
83           */           */
84          protected String[] colTooltips = null;          protected String[] colTooltips = null;
85    
86          /** A cache for the #sortedValuesVisibleOnly() **/          /**
87             * 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;          protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null;
91    
92          /**          /**
# Line 102  public class StyledFeatureCollectionTabl Line 109  public class StyledFeatureCollectionTabl
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 AttributeMetadataImpl}-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<? extends AttributeMetadataInterface> 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;
# Line 134  public class StyledFeatureCollectionTabl Line 142  public class StyledFeatureCollectionTabl
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()
# Line 170  public class StyledFeatureCollectionTabl Line 178  public class StyledFeatureCollectionTabl
178           * @param fs           * @param fs
179           *            the feature source           *            the feature source
180           * @param amd           * @param amd
181           *            {@link AttributeMetadataImpl}-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 {
# Line 209  public class StyledFeatureCollectionTabl Line 217  public class StyledFeatureCollectionTabl
217                          // Pruefen, welche Attribute angezeigt werden                          // Pruefen, welche Attribute angezeigt werden
218                          attrTypes.clear();                          attrTypes.clear();
219                          for (AttributeMetadataInterface 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                          }                          }
# Line 220  public class StyledFeatureCollectionTabl Line 233  public class StyledFeatureCollectionTabl
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);

Legend:
Removed from v.788  
changed lines
  Added in v.1265

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26