/[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 332 by alfonx, Wed Aug 26 17:15:49 2009 UTC revision 428 by alfonx, Sun Oct 4 14:28:07 2009 UTC
# Line 37  import org.apache.log4j.Logger; Line 37  import org.apache.log4j.Logger;
37  import org.geotools.data.DefaultQuery;  import org.geotools.data.DefaultQuery;
38  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
39  import org.geotools.data.Query;  import org.geotools.data.Query;
 import org.geotools.data.memory.MemoryDataStore;  
40  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
41    import org.opengis.feature.simple.SimpleFeature;
42    import org.opengis.feature.simple.SimpleFeatureType;
43  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
44  import org.opengis.filter.Filter;  import org.opengis.filter.Filter;
45    
# Line 51  import com.vividsolutions.jts.geom.Envel Line 52  import com.vividsolutions.jts.geom.Envel
52    
53  /**  /**
54   * This class extends the the {@link FeatureCollectionTableModel} with the   * This class extends the the {@link FeatureCollectionTableModel} with the
55   * functionalities of the {@link AttributeMetaData} of   * functionalities of the {@link AttributeMetaData}.
  * {@linkplain StyledLayerInterface styled objects}.  
56   * <ul>   * <ul>
57   * <li>column names are translated according to   * <li>column names are translated according to
58   * {@link AttributeMetaData#getTitle()}</li>   * {@link AttributeMetaData#getTitle()}</li>
59   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
60     * <li>Any filter defined in the {@link StyledFeaturesInterface} will be applied.</li>
61   * </ul>   * </ul>
62   *   *
63   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   * @author Stefan A. Krüger
  *         (University of Bonn/Germany)  
64   */   */
65  public class StyledFeatureCollectionTableModel extends  public class StyledFeatureCollectionTableModel extends
66                  FeatureCollectionTableModel {                  FeatureCollectionTableModel {
67          final static private Logger LOGGER = Logger          final static private Logger LOGGER = Logger
68                          .getLogger(StyledFeatureCollectionTableModel.class);                          .getLogger(StyledFeatureCollectionTableModel.class);
         /** Holds the data source as styled layer. */  
         protected StyledLayerInterface<?> layer = null;  
69          /** Contains only the visible elements of the {@link AttributeMetaData}-Map */          /** Contains only the visible elements of the {@link AttributeMetaData}-Map */
70          protected Map<Integer, AttributeMetaData> visibleAMD = null;          protected Map<Integer, AttributeMetaData> visibleAMD = null;
71          /** Holds the data source for the table as {@code FeatureSource}. */  //      /** Holds the data source for the table as {@code FeatureSource}. */
72          protected FeatureSource featureSource = null;  //      protected FeatureSource featureSource = null;
73          /** Contains the complete {@link AttributeMetaData}-Map of the styled layer. */          /** Contains the complete {@link AttributeMetaData}-Map of the styled layer. */
74          protected Map<Integer, AttributeMetaData> origAMD = null;          protected Map<Integer, AttributeMetaData> origAMD = null;
75          /** Holds the current filter on the table */          /** Holds the current filter on the table */
# Line 80  public class StyledFeatureCollectionTabl Line 78  public class StyledFeatureCollectionTabl
78          protected Envelope bounds;          protected Envelope bounds;
79    
80                    
   
         /**  
          * Creates a new table model for a styled layer.  
          *  
          * @param layer  
          *            the styled layer  
          */  
         public StyledFeatureCollectionTableModel(  
                         StyledFeatureCollectionInterface layer) {  
                 this(layer, Filter.INCLUDE);  
         }  
   
         /**  
          * Creates a new table model for a styled layer.  
          *  
          * @param layer  
          *            the styled layer  
          * @param filter  
          *            filter applied to the table  
          */  
         public StyledFeatureCollectionTableModel(  
                         StyledFeatureCollectionInterface layer, Filter filter) {  
                 super();  
                 setFeatureCollection(layer, filter);  
         }  
   
   
         /**  
          * Creates a new table model for a styled layer.  
          *  
          * @param layer  
          *            the styled layer  
          */  
         public StyledFeatureCollectionTableModel(StyledFeaturesInterface layer) {  
                 this(layer, Filter.INCLUDE);  
         }  
   
81          /**          /**
82           * Creates a new table model for a styled layer.           * Creates a new table model for a styled layer.
83           *           *
84           * @param layer           * @param styledFeatures
85           *            the styled layer           *            the styled layer
86           * @param filter           * @param filter
87           *            filter applied to the table           *            filter applied to the table
88           */           */
89          public StyledFeatureCollectionTableModel(StyledFeaturesInterface layer,          public StyledFeatureCollectionTableModel(StyledFeaturesInterface<?> styledFeatures) {
90                          Filter filter) {                  setStyledFeatures(styledFeatures);
                 super();  
                 setFeatureCollection(layer, filter);  
91          }          }
92    
93          /**          /**
# Line 140  public class StyledFeatureCollectionTabl Line 99  public class StyledFeatureCollectionTabl
99           *            {@link AttributeMetaData}-Map to define the visible attributes           *            {@link AttributeMetaData}-Map to define the visible attributes
100           *            and translation           *            and translation
101           */           */
102          protected void setFeatureSource(FeatureSource fs,          protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
103                          Map<Integer, AttributeMetaData> amd, Filter filter)                          Map<Integer, AttributeMetaData> amd, Filter filter)
104                          throws Exception {                          throws Exception {
105                    
106                  if (filter == null)                  if (filter == null)
107                          filter = Filter.INCLUDE;                          filter = Filter.INCLUDE;
108    
109                  this.featureSource = fs;  //              this.featureSource = fs;
110                  this.filter = filter;                  this.filter = filter;
111                  this.origAMD = amd;                  this.origAMD = amd;
112                  this.visibleAMD = null;                  this.visibleAMD = null;
113    
114                  FeatureCollection fc = null;                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
115                  if (fs != null) {                  if (fs != null) {
116    
117                          bounds = fs.getBounds();                          bounds = fs.getBounds();
118    
119                          Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter);                          Query query = new DefaultQuery(fs.getSchema().getName().getLocalPart(), filter);
120                          if (amd != null) {                          if (amd != null) {
121                                  // determine the names of the visible Attributes                                  // determine the names of the visible Attributes
122                                  this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData(                                  this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData(
123                                                  amd, true);                                                  amd, true);
124                                  Vector<String> visibleAttrNames = new Vector<String>();                                  Vector<String> visibleAttrNames = new Vector<String>();
125                                  // Add the column with the geometry (usually "the_geom")                                  // Add the column with the geometry (usually "the_geom")
126                                  visibleAttrNames.add(fs.getSchema().getDefaultGeometry()                                  visibleAttrNames.add(fs.getSchema().getGeometryDescriptor()
127                                                  .getLocalName());                                                  .getLocalName());
128                                  for (int attrIdx : visibleAMD.keySet()) {                                  for (int attrIdx : visibleAMD.keySet()) {
129    
# Line 175  public class StyledFeatureCollectionTabl Line 135  public class StyledFeatureCollectionTabl
135                                           */                                           */
136                                          if (attrIdx < fs.getSchema().getAttributeCount()) {                                          if (attrIdx < fs.getSchema().getAttributeCount()) {
137                                                  final AttributeDescriptor attributeTypeAtIdx = fs.getSchema()                                                  final AttributeDescriptor attributeTypeAtIdx = fs.getSchema()
138                                                                  .getAttributeType(attrIdx);                                                                  .getAttributeDescriptors().get(attrIdx);
139                                                  visibleAttrNames.add(attributeTypeAtIdx.getLocalName());                                                  visibleAttrNames.add(attributeTypeAtIdx.getLocalName());
140                                          } else {                                          } else {
141                                                  LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored.");                                                  LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored.");
# Line 192  public class StyledFeatureCollectionTabl Line 152  public class StyledFeatureCollectionTabl
152                                                  properties);                                                  properties);
153                          }                          }
154                          fc = fs.getFeatures(query);                          fc = fs.getFeatures(query);
   
                         // FAILS:!!!, even with query = new  
                         // DefaultQuery(fs.getSchema().getTypeName(), filter);  
                         // java.lang.UnsupportedOperationException: Unknown feature  
                         // attribute: PQM_MOD  
                         // at  
                         // schmitzm.geotools.feature.FeatureOperationTree.evaluate(FeatureOperationTree.java:93)  
                         // bounds = fc.getBounds();  
                         // SK, 17.4.2009  
                         //        
                         // System.out.println("Filter = "+filter);  
                         // System.out.println("Size of FC = "+fc.size());  
                         // System.out.println("anz att= "+fc.getNumberOfAttributes());  
155                  }                  }
156                  setFeatureCollection(fc);                  setFeatureCollection(fc);
157          }          }
# Line 219  public class StyledFeatureCollectionTabl Line 166  public class StyledFeatureCollectionTabl
166           *            {@link AttributeMetaData}-Map to define the visible attributes           *            {@link AttributeMetaData}-Map to define the visible attributes
167           *            and translation           *            and translation
168           */           */
169          public void setFeatureCollection(StyledFeaturesInterface layer,          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
                         Filter filter) {  
                 this.layer = layer;  
170                  try {                  try {
171                          if (layer == null)                          if (styledFeatures == null)
172                                  setFeatureSource(null, null, null);                                  setFeatureSource(null, null, null);
173                          else {                          else {
174                                  FeatureCollection fc = layer.getFeatureCollection();                                  setFeatureSource(styledFeatures.getFeatureSource(), styledFeatures.getAttributeMetaDataMap(), styledFeatures.getFilter());
                                 String fcName = fc.getSchema().getTypeName();  
                                 FeatureSource fs = new MemoryDataStore(fc)  
                                                 .getFeatureSource(fcName);  
                                 setFeatureSource(fs, layer.getAttributeMetaDataMap(), filter);  
175                          }                          }
176                  } catch (Exception err) {                  } catch (Exception err) {
177                          throw new RuntimeException(err);                          throw new RuntimeException(err);
# Line 238  public class StyledFeatureCollectionTabl Line 179  public class StyledFeatureCollectionTabl
179          }          }
180    
181          /**          /**
          * Sets the {@code StyledFeatureCollection} as new data source for the  
          * table.  
          *  
          * @param fs  
          *            the feature source  
          * @param amd  
          *            {@link AttributeMetaData}-Map to define the visible attributes  
          *            and translation  
          */  
         public void setFeatureCollection(StyledFeatureSourceInterface layer,  
                         Filter filter) {  
                 this.layer = layer;  
                 try {  
                         if (layer == null)  
                                 setFeatureSource(null, null, null);  
                         else  
                                 setFeatureSource(layer.getGeoObject(), layer  
                                                 .getAttributeMetaDataMap(), filter);  
                 } catch (Exception err) {  
                         throw new RuntimeException(err);  
                 }  
         }  
   
         /**  
          * Resets the filter for the table.  
          *  
          * @param filter  
          *            a filter  
          */  
         public void setFilter(Filter filter) {  
                 try {  
                         setFeatureSource(this.featureSource, this.origAMD, filter);  
                 } catch (Exception err) {  
                         LOGGER.error("Setting the filter of the table model", err);  
                         throw new RuntimeException(err);  
                 }  
         }  
   
         /**  
          * @return <code>Filter.INCLUDE</code> or the {@link Filter} applied to the  
          *         Features  
          */  
         public Filter getFilter() {  
                 return this.filter;  
         }  
   
         /**  
182           * After calling {@code super.reorganize(.)} this method replaced the column           * After calling {@code super.reorganize(.)} this method replaced the column
183           * descriptions with the titles of the {@code AttributeMetaData}.           * descriptions with the titles of the {@code AttributeMetaData}.
184           *           *

Legend:
Removed from v.332  
changed lines
  Added in v.428

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26