/[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 621 by alfonx, Thu Jan 28 10:06:05 2010 UTC revision 681 by alfonx, Tue Feb 9 22:08:26 2010 UTC
# Line 30  Line 30 
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.util.HashMap;  import java.util.HashMap;
33    import java.util.List;
34  import java.util.Vector;  import java.util.Vector;
35    
36  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 77  public class StyledFeatureCollectionTabl Line 78  public class StyledFeatureCollectionTabl
78           */           */
79          protected String[] colTooltips = null;          protected String[] colTooltips = null;
80    
81            /** A cache for the #sortedValuesVisibleOnly() **/
82            protected List<AttributeMetadata> amdMapVisibleOnly = null;
83    
84          /**          /**
85           * Creates a new table model for a styled layer.           * Creates a new table model for a styled layer.
86           *           *
# Line 91  public class StyledFeatureCollectionTabl Line 95  public class StyledFeatureCollectionTabl
95          }          }
96    
97          /**          /**
98             * This overwritten method filters the values for NODATA-values defined in
99             * the {@link AttributeMetadata}
100             */
101            @Override
102            public Object getValueAt(int row, int col) {
103                    Object rawValue = super.getValueAt(row, col);
104                    return amdMap.sortedValuesVisibleOnly().get(col).fiterNodata(rawValue);
105            }
106            
107            /**
108           * Sets a new data source for the table.           * Sets a new data source for the table.
109           *           *
110           * @param fs           * @param fs
# Line 109  public class StyledFeatureCollectionTabl Line 123  public class StyledFeatureCollectionTabl
123                  // this.featureSource = fs;                  // this.featureSource = fs;
124                  this.filter = filter;                  this.filter = filter;
125                  this.amdMap = amdm;                  this.amdMap = amdm;
126                    this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
127    
128                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
129                  if (fs != null) {                  if (fs != null) {
# Line 125  public class StyledFeatureCollectionTabl Line 140  public class StyledFeatureCollectionTabl
140                                                  .getLocalName());                                                  .getLocalName());
141    
142                                  // Add other visible attributes as ordered by weights                                  // Add other visible attributes as ordered by weights
143                                  for (AttributeMetadata a : amdm.sortedValuesVisibleOnly()) {                                  for (AttributeMetadata a : amdMapVisibleOnly) {
144                                          visibleAttrNames.add(a.getLocalName());                                          visibleAttrNames.add(a.getLocalName());
145                                  }                                  }
146    
147  //                      Tested with 2.6.x trunk from 2009-11-26 and it now works. So we only request the properties we need!                                                      // Tested with 2.6.x trunk from 2009-11-26 and it now works. So
148  //                              /**                                  // we only request the properties we need!
149  //                               * I got NPEs when properties contained only [the_geom] ?!??!!??                                  // /**
150  //                               */                                  // * I got NPEs when properties contained only [the_geom]
151  //                              if (properties.length > 1) {                                  // ?!??!!??
152                                          query = new DefaultQuery(schema.getTypeName(), filter,                                  // */
153                                                          visibleAttrNames.toArray(new String[] {}));                                  // if (properties.length > 1) {
154  //                              } else {                                  query = new DefaultQuery(schema.getTypeName(), filter,
155  //                                      query = new DefaultQuery(schema.getTypeName(), filter);                                                  visibleAttrNames.toArray(new String[] {}));
156  //                              }                                  // } else {
157                                    // query = new DefaultQuery(schema.getTypeName(), filter);
158                                    // }
159                          }                          }
160                          fc = fs.getFeatures(query);                          fc = fs.getFeatures(query);
161                  }                  }
# Line 183  public class StyledFeatureCollectionTabl Line 200  public class StyledFeatureCollectionTabl
200                  if (featureArray == null || featureArray.length == 0) {                  if (featureArray == null || featureArray.length == 0) {
201                          colNames = new String[0];                          colNames = new String[0];
202                          colTooltips = new String[0]; // Only set and used in                          colTooltips = new String[0]; // Only set and used in
203                                                                                          // StyledFeatureCollectionTableModel                          // StyledFeatureCollectionTableModel
204                          colClass = new Class[0];                          colClass = new Class[0];
205                  } else {                  } else {
206                          // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen                          // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
207                          SimpleFeatureType schema = featureArray[0].getFeatureType();                          SimpleFeatureType schema = featureArray[0].getFeatureType();
208                          // Pruefen, welche Attribute angezeigt werden                          // Pruefen, welche Attribute angezeigt werden
209                          attrTypes.clear();                          attrTypes.clear();
210                          for (AttributeMetadata amd : amdMap.sortedValuesVisibleOnly()) {                          for (AttributeMetadata amd : amdMapVisibleOnly) {
211                                  AttributeDescriptor type = schema.getDescriptor(amd.getName());                                  AttributeDescriptor type = schema.getDescriptor(amd.getName());
212                                  if (attrFilter == null || attrFilter.accept(type))                                  if (attrFilter == null || attrFilter.accept(type))
213                                          attrTypes.add(type);                                          attrTypes.add(type);
# Line 198  public class StyledFeatureCollectionTabl Line 215  public class StyledFeatureCollectionTabl
215                          // Namen und Attribut-Indizes der angezeigten Spalten ermitteln                          // Namen und Attribut-Indizes der angezeigten Spalten ermitteln
216                          colNames = new String[attrTypes.size()];                          colNames = new String[attrTypes.size()];
217                          colTooltips = new String[attrTypes.size()]; // Only set and used in                          colTooltips = new String[attrTypes.size()]; // Only set and used in
218                                                                                                                  // StyledFeatureCollectionTableModel                          // StyledFeatureCollectionTableModel
219                          colClass = new Class[attrTypes.size()];                          colClass = new Class[attrTypes.size()];
220                          attrIdxForCol = new int[attrTypes.size()];                          attrIdxForCol = new int[attrTypes.size()];
221                          for (int i = 0; i < colNames.length; i++) {                          for (int i = 0; i < colNames.length; i++) {
222                                  AttributeDescriptor descriptor = schema.getDescriptor(amdMap.sortedValuesVisibleOnly().get(i).getName());                                  AttributeDescriptor descriptor = schema
223                                                    .getDescriptor(amdMapVisibleOnly.get(i).getName());
224    
225                                  // Not so nice in 26: find the index of an attribute...                                  // Not so nice in 26: find the index of an attribute...
226                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);
# Line 212  public class StyledFeatureCollectionTabl Line 230  public class StyledFeatureCollectionTabl
230                                                  .getLocalName();                                                  .getLocalName();
231                                  colNames[i] = amdMap.get(attName).getTitle().toString();                                  colNames[i] = amdMap.get(attName).getTitle().toString();
232                                  AttributeMetadata amd = amdMap.get(attName);                                  AttributeMetadata amd = amdMap.get(attName);
233                                  colTooltips[i] = "<html>"+amd.getDesc().toString()+"<br>"+amd.getName()+"</html>";                                  colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
234                                  colClass[i] = schema.getAttributeDescriptors().get(idx).getType()                                                  + amd.getName() + "</html>";
235                                                  .getBinding();                                  colClass[i] = schema.getAttributeDescriptors().get(idx)
236                                                    .getType().getBinding();
237                          }                          }
238                  }                  }
239    
# Line 223  public class StyledFeatureCollectionTabl Line 242  public class StyledFeatureCollectionTabl
242                  for (int i = 0; i < featureArray.length; i++)                  for (int i = 0; i < featureArray.length; i++)
243                          if (featureArray[i] != null)                          if (featureArray[i] != null)
244                                  featureIdx.put(featureArray[i].getID(), i);                                  featureIdx.put(featureArray[i].getID(), i);
245  //                  //
246  //              // translate the column names                  // // translate the column names
247  //              if (amdMap != null) {                  // if (amdMap != null) {
248  //                      for (int i = 0; i < colNames.length; i++) {                  // for (int i = 0; i < colNames.length; i++) {
249  //                              colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()                  // colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
250  //                                              + "<br>" + colNames[i];                  // + "<br>" + colNames[i];
251  //                              colNames[i] = amdMap.get(colNames[i]).getTitle().toString();                  // colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
252  //                  //
253  //                      }                  // }
254  //              }                  // }
255                  if (fireTableStructureChanged)                  if (fireTableStructureChanged)
256                          fireTableStructureChanged();                          fireTableStructureChanged();
257    

Legend:
Removed from v.621  
changed lines
  Added in v.681

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26