/[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 463 by alfonx, Sun Oct 4 14:28:07 2009 UTC revision 464 by alfonx, Tue Oct 13 13:22:31 2009 UTC
# Line 29  Line 29 
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.geotools;  package skrueger.geotools;
31    
 import java.util.Iterator;  
 import java.util.Map;  
32  import java.util.Vector;  import java.util.Vector;
33    
34  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 44  import org.opengis.feature.type.Attribut Line 42  import org.opengis.feature.type.Attribut
42  import org.opengis.filter.Filter;  import org.opengis.filter.Filter;
43    
44  import schmitzm.geotools.gui.FeatureCollectionTableModel;  import schmitzm.geotools.gui.FeatureCollectionTableModel;
45  import skrueger.AttributeMetaData;  import skrueger.AttributeMetadata;
 import skrueger.i8n.I8NUtil;  
 import skrueger.i8n.Translation;  
46    
47  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
48    
49  /**  /**
50   * This class extends the the {@link FeatureCollectionTableModel} with the   * This class extends the the {@link FeatureCollectionTableModel} with the
51   * functionalities of the {@link AttributeMetaData}.   * functionalities of the {@link AttributeMetadata}.
52   * <ul>   * <ul>
53   * <li>column names are translated according to   * <li>column names are translated according to
54   * {@link AttributeMetaData#getTitle()}</li>   * {@link AttributeMetadata#getTitle()}</li>
55   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
56   * <li>Any filter defined in the {@link StyledFeaturesInterface} will be applied.</li>   * <li>Any filter defined in the {@link StyledFeaturesInterface} will be applied.</li>
57   * </ul>   * </ul>
# Line 66  public class StyledFeatureCollectionTabl Line 62  public class StyledFeatureCollectionTabl
62                  FeatureCollectionTableModel {                  FeatureCollectionTableModel {
63          final static private Logger LOGGER = Logger          final static private Logger LOGGER = Logger
64                          .getLogger(StyledFeatureCollectionTableModel.class);                          .getLogger(StyledFeatureCollectionTableModel.class);
65          /** Contains only the visible elements of the {@link AttributeMetaData}-Map */          /** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */
66          protected Map<Integer, AttributeMetaData> visibleAMD = null;          protected AttributeMetadataMap origAMD = null;
 //      /** Holds the data source for the table as {@code FeatureSource}. */  
 //      protected FeatureSource featureSource = null;  
         /** Contains the complete {@link AttributeMetaData}-Map of the styled layer. */  
         protected Map<Integer, AttributeMetaData> origAMD = null;  
67          /** Holds the current filter on the table */          /** Holds the current filter on the table */
68          protected Filter filter = null;          protected Filter filter = null;
69          /** Holds the Bounds for all features. Only set once during the constructor **/          /** Holds the Bounds for all features. Only set once during the constructor **/
# Line 96  public class StyledFeatureCollectionTabl Line 88  public class StyledFeatureCollectionTabl
88           * @param fs           * @param fs
89           *            the feature source           *            the feature source
90           * @param amd           * @param amd
91           *            {@link AttributeMetaData}-Map to define the visible attributes           *            {@link AttributeMetadata}-Map to define the visible attributes
92           *            and translation           *            and translation
93           */           */
94          protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs,          protected void setFeatureSource(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
95                          Map<Integer, AttributeMetaData> amd, Filter filter)                          AttributeMetadataMap amd, Filter filter)
96                          throws Exception {                          throws Exception {
97                                    
98                  if (filter == null)                  if (filter == null)
# Line 109  public class StyledFeatureCollectionTabl Line 101  public class StyledFeatureCollectionTabl
101  //              this.featureSource = fs;  //              this.featureSource = fs;
102                  this.filter = filter;                  this.filter = filter;
103                  this.origAMD = amd;                  this.origAMD = amd;
                 this.visibleAMD = null;  
104    
105                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
106                  if (fs != null) {                  if (fs != null) {
107    
108                          bounds = fs.getBounds();                          bounds = fs.getBounds();
109    
110                          Query query = new DefaultQuery(fs.getSchema().getName().getLocalPart(), filter);                          final SimpleFeatureType schema = fs.getSchema();
111                            Query query = new DefaultQuery(schema.getTypeName(), filter);
112                          if (amd != null) {                          if (amd != null) {
                                 // determine the names of the visible Attributes  
                                 this.visibleAMD = StyledLayerUtil.getVisibleAttributeMetaData(  
                                                 amd, true);  
113                                  Vector<String> visibleAttrNames = new Vector<String>();                                  Vector<String> visibleAttrNames = new Vector<String>();
114                                  // Add the column with the geometry (usually "the_geom")                                  // Add the column with the geometry (usually "the_geom")
115                                  visibleAttrNames.add(fs.getSchema().getGeometryDescriptor()                                  
116                                                  .getLocalName());                                  for (AttributeDescriptor aDesc : schema.getAttributeDescriptors()) {
117                                  for (int attrIdx : visibleAMD.keySet()) {                                          
118                                            // Always add the geometry
119                                          /**                                          if (schema.getGeometryDescriptor()
120                                           * If the user removed columns from the schema of the DBF                                                  .getName().equals(aDesc.getName())) {
121                                           * file, there might exist AttributeMetaData for columns                                                  visibleAttrNames.add(schema.getGeometryDescriptor()
122                                           * that don't exists. We check here to avoid an                                                                  .getLocalName());
123                                           * ArrayOutOfIndex.                                                  continue;
                                          */  
                                         if (attrIdx < fs.getSchema().getAttributeCount()) {  
                                                 final AttributeDescriptor attributeTypeAtIdx = fs.getSchema()  
                                                                 .getAttributeDescriptors().get(attrIdx);  
                                                 visibleAttrNames.add(attributeTypeAtIdx.getLocalName());  
                                         } else {  
                                                 LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored.");  
124                                          }                                          }
125                                            
126                                            if (amd.get(aDesc.getName()).isVisible())
127                                                    visibleAttrNames.add(aDesc.getName().getLocalPart());
128                                  }                                  }
129    
130                                  // create a query for the visible attributes                                  // create a query for the visible attributes
131                                  String[] properties = visibleAttrNames.toArray(new String[0]);                                  String[] properties = visibleAttrNames.toArray(new String[] {});
132    
133                                  LOGGER.debug("Query contains the following attributes: "                                  LOGGER.debug("Query contains the following attributes: "
134                                                  + visibleAttrNames);                                                  + visibleAttrNames);
135    
136                                  query = new DefaultQuery(fs.getSchema().getTypeName(), filter,                                  query = new DefaultQuery(schema.getTypeName(), filter,
137                                                  properties);                                                  properties);
138                          }                          }
139                          fc = fs.getFeatures(query);                          fc = fs.getFeatures(query);
# Line 163  public class StyledFeatureCollectionTabl Line 148  public class StyledFeatureCollectionTabl
148           * @param fs           * @param fs
149           *            the feature source           *            the feature source
150           * @param amd           * @param amd
151           *            {@link AttributeMetaData}-Map to define the visible attributes           *            {@link AttributeMetadata}-Map to define the visible attributes
152           *            and translation           *            and translation
153           */           */
154          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
# Line 187  public class StyledFeatureCollectionTabl Line 172  public class StyledFeatureCollectionTabl
172           */           */
173          @Override          @Override
174          protected void reorganize(boolean fireTableStructureChanged) {          protected void reorganize(boolean fireTableStructureChanged) {
175                    
176                  super.reorganize(false);                  super.reorganize(false);
177                    
178                  // translate the column names                  // translate the column names
179                  if (visibleAMD != null) {                  if (origAMD != null) {
180                          Iterator<Integer> keys = visibleAMD.keySet().iterator();                          for (int i = 0; i < colNames.length; i++) {
181                          for (int i = 0; i < colNames.length && keys.hasNext(); i++) {                                  colNames[i] = origAMD.get(colNames[i]).getTitle().toString();
                                 Translation title = visibleAMD.get(keys.next()).getTitle();  
                                 if (!I8NUtil.isEmpty(title)) {  
                                         // System.out.println("set colname " + i + " to " +  
                                         // title.toString());  
                                         colNames[i] = title.toString();  
                                 }  
182                          }                          }
183                            
184                  }                  }
185                  if (fireTableStructureChanged)                  if (fireTableStructureChanged)
186                          fireTableStructureChanged();                          fireTableStructureChanged();

Legend:
Removed from v.463  
changed lines
  Added in v.464

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26