/[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

branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollectionTableModel.java revision 534 by alfonx, Fri Nov 20 10:28:01 2009 UTC trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java revision 862 by alfonx, Sat May 22 01:24:46 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.List;
34  import java.util.Vector;  import java.util.Vector;
35    
36  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
# Line 44  import org.opengis.filter.Filter; Line 45  import org.opengis.filter.Filter;
45    
46  import schmitzm.geotools.feature.FeatureUtil;  import schmitzm.geotools.feature.FeatureUtil;
47  import schmitzm.geotools.gui.FeatureCollectionTableModel;  import schmitzm.geotools.gui.FeatureCollectionTableModel;
48  import skrueger.AttributeMetadata;  import skrueger.AttributeMetadataImpl;
49    import skrueger.AttributeMetadataInterface;
50    
51  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
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}.   * functionalities of the {@link AttributeMetadataImpl}.
56   * <ul>   * <ul>
57   * <li>column names are translated according to   * <li>column names are translated according to
58   * {@link AttributeMetadata#getTitle()}</li>   * {@link AttributeMetadataImpl#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   * <li>Any filter defined in the {@link StyledFeaturesInterface} will be
61   * applied.</li>   * applied.</li>
62   * </ul>   * </ul>
63   *   *
64   * @author Stefan A. Krüger   * @author Stefan A. Tzeggai
65   */   */
66  public class StyledFeatureCollectionTableModel extends  public class StyledFeatureCollectionTableModel extends
67                  FeatureCollectionTableModel {                  FeatureCollectionTableModel {
68          final static private Logger LOGGER = Logger          final static private Logger LOGGER = Logger
69                          .getLogger(StyledFeatureCollectionTableModel.class);                          .getLogger(StyledFeatureCollectionTableModel.class);
70          /** Contains the complete {@link AttributeMetadata}-Map of the styled layer. */          /** Contains the complete {@link AttributeMetadataImpl}-Map of the styled layer. */
71          protected AttributeMetadataMap amdMap = null;          protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null;
72          /** Holds the current filter on the table */          /** Holds the current filter on the table */
73          protected Filter filter = null;          protected Filter filter = null;
74          /** 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 77  public class StyledFeatureCollectionTabl Line 79  public class StyledFeatureCollectionTabl
79           */           */
80          protected String[] colTooltips = null;          protected String[] colTooltips = null;
81    
82            /** A cache for the #sortedValuesVisibleOnly() **/
83            protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null;
84    
85          /**          /**
86           * Creates a new table model for a styled layer.           * Creates a new table model for a styled layer.
87           *           *
# Line 91  public class StyledFeatureCollectionTabl Line 96  public class StyledFeatureCollectionTabl
96          }          }
97    
98          /**          /**
99             * This overwritten method filters the values for NODATA-values defined in
100             * the {@link AttributeMetadataImpl}
101             */
102            @Override
103            public Object getValueAt(int row, int col) {
104                    Object rawValue = super.getValueAt(row, col);
105                    return amdMap.sortedValuesVisibleOnly().get(col).fiterNodata(rawValue);
106            }
107            
108            /**
109           * Sets a new data source for the table.           * Sets a new data source for the table.
110           *           *
111           * @param fs           * @param fs
112           *            the feature source           *            the feature source
113           * @param amdm           * @param amdm
114           *            {@link AttributeMetadata}-Map to define the visible attributes           *            {@link AttributeMetadataImpl}-Map to define the visible attributes
115           *            and translation           *            and translation
116           */           */
117          protected void setFeatureSource(          protected void setFeatureSource(
118                          FeatureSource<SimpleFeatureType, SimpleFeature> fs,                          FeatureSource<SimpleFeatureType, SimpleFeature> fs,
119                          AttributeMetadataMap amdm, Filter filter) throws Exception {                          AttributeMetadataMap<? extends AttributeMetadataInterface> amdm, Filter filter) throws Exception {
120    
121                  if (filter == null)                  if (filter == null)
122                          filter = Filter.INCLUDE;                          filter = Filter.INCLUDE;
# Line 109  public class StyledFeatureCollectionTabl Line 124  public class StyledFeatureCollectionTabl
124                  // this.featureSource = fs;                  // this.featureSource = fs;
125                  this.filter = filter;                  this.filter = filter;
126                  this.amdMap = amdm;                  this.amdMap = amdm;
127                    this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
128    
129                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
130                  if (fs != null) {                  if (fs != null) {
# Line 120  public class StyledFeatureCollectionTabl Line 136  public class StyledFeatureCollectionTabl
136                          if (amdm != null) {                          if (amdm != null) {
137                                  Vector<String> visibleAttrNames = new Vector<String>();                                  Vector<String> visibleAttrNames = new Vector<String>();
138    
139                                  // Add the column with the geometry (usually "the_geom")                                  // Add the column with the geometry (usually "the_geom") always
140                                  visibleAttrNames.add(schema.getGeometryDescriptor()                                  visibleAttrNames.add(schema.getGeometryDescriptor()
141                                                  .getLocalName());                                                  .getLocalName());
142    
143                                  // Add other visible attributes as ordered by weights                                  // Add other visible attributes as ordered by weights
144                                  for (AttributeMetadata a : amdm.sortedValuesVisibleOnly()) {                                  for (AttributeMetadataInterface a : amdMapVisibleOnly) {
145                                          visibleAttrNames.add(a.getLocalName());                                          visibleAttrNames.add(a.getLocalName());
146                                  }                                  }
147    
148                                  // for (AttributeDescriptor aDesc :                                  // Tested with 2.6.x trunk from 2009-11-26 and it now works. So
149                                  // schema.getAttributeDescriptors()) {                                  // we only request the properties we need!
150                                  //                                                                        // /**
151                                  // // Always add the geometry                                  // * I got NPEs when properties contained only [the_geom]
152                                  // if (schema.getGeometryDescriptor()                                  // ?!??!!??
153                                  // .getName().equals(aDesc.getName())) {                                  // */
154                                  // visibleAttrNames.add(schema.getGeometryDescriptor()                                  // if (properties.length > 1) {
155                                  // .getLocalName());                                  query = new DefaultQuery(schema.getTypeName(), filter,
156                                  // continue;                                                  visibleAttrNames.toArray(new String[] {}));
157                                  // }                                  // } else {
158                                  //                                                                        // query = new DefaultQuery(schema.getTypeName(), filter);
                                 // if (amd.get(aDesc.getName()).isVisible())  
                                 // visibleAttrNames.add(aDesc.getName().getLocalPart());  
159                                  // }                                  // }
                                 //  
                                 // // create a query for the visible attributes  
                                 String[] properties = visibleAttrNames.toArray(new String[] {});  
                                 //  
                                 // LOGGER.debug("Query contains the following attributes: "  
                                 // + visibleAttrNames);  
   
                                 /**  
                                  * I got NPEs when properties contained only [the_geom] ?!??!!??  
                                  * TODO Try again one day... Not today... 20.11.2009, SK  
                                  */  
                                 if (properties.length > 1) {  
                                         query = new DefaultQuery(schema.getTypeName(), filter,  
                                                         properties);  
                                 } else {  
                                         query = new DefaultQuery(schema.getTypeName(), filter);  
                                 }  
160                          }                          }
161                          fc = fs.getFeatures(query);                          fc = fs.getFeatures(query);
162                  }                  }
# Line 173  public class StyledFeatureCollectionTabl Line 170  public class StyledFeatureCollectionTabl
170           * @param fs           * @param fs
171           *            the feature source           *            the feature source
172           * @param amd           * @param amd
173           *            {@link AttributeMetadata}-Map to define the visible attributes           *            {@link AttributeMetadataImpl}-Map to define the visible attributes
174           *            and translation           *            and translation
175           */           */
176          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
# Line 204  public class StyledFeatureCollectionTabl Line 201  public class StyledFeatureCollectionTabl
201                  if (featureArray == null || featureArray.length == 0) {                  if (featureArray == null || featureArray.length == 0) {
202                          colNames = new String[0];                          colNames = new String[0];
203                          colTooltips = new String[0]; // Only set and used in                          colTooltips = new String[0]; // Only set and used in
204                                                                                          // StyledFeatureCollectionTableModel                          // StyledFeatureCollectionTableModel
205                          colClass = new Class[0];                          colClass = new Class[0];
206                  } else {                  } else {
207                          // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen                          // Struktur der Tabelle vom AttributeMetaDtaaMap übernehmen
208                          SimpleFeatureType schema = featureArray[0].getFeatureType();                          SimpleFeatureType schema = featureArray[0].getFeatureType();
209                          // Pruefen, welche Attribute angezeigt werden                          // Pruefen, welche Attribute angezeigt werden
210                          attrTypes.clear();                          attrTypes.clear();
211                          for (AttributeMetadata amd : amdMap.sortedValuesVisibleOnly()) {                          for (AttributeMetadataInterface amd : amdMapVisibleOnly) {
212                                  AttributeDescriptor type = schema.getDescriptor(amd.getName());                                  AttributeDescriptor type = schema.getDescriptor(amd.getName());
213                                  if (attrFilter == null || attrFilter.accept(type))                                  if (attrFilter == null || attrFilter.accept(type))
214                                          attrTypes.add(type);                                          attrTypes.add(type);
# Line 219  public class StyledFeatureCollectionTabl Line 216  public class StyledFeatureCollectionTabl
216                          // Namen und Attribut-Indizes der angezeigten Spalten ermitteln                          // Namen und Attribut-Indizes der angezeigten Spalten ermitteln
217                          colNames = new String[attrTypes.size()];                          colNames = new String[attrTypes.size()];
218                          colTooltips = new String[attrTypes.size()]; // Only set and used in                          colTooltips = new String[attrTypes.size()]; // Only set and used in
219                                                                                                                  // StyledFeatureCollectionTableModel                          // StyledFeatureCollectionTableModel
220                          colClass = new Class[attrTypes.size()];                          colClass = new Class[attrTypes.size()];
221                          attrIdxForCol = new int[attrTypes.size()];                          attrIdxForCol = new int[attrTypes.size()];
222                          for (int i = 0; i < colNames.length; i++) {                          for (int i = 0; i < colNames.length; i++) {
223                                  AttributeDescriptor descriptor = schema.getDescriptor(amdMap.sortedValuesVisibleOnly().get(i).getName());                                  AttributeDescriptor descriptor = schema
224                                                    .getDescriptor(amdMapVisibleOnly.get(i).getName());
225    
226                                  // Not so nice in 26: find the index of an attribute...                                  // Not so nice in 26: find the index of an attribute...
227                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);
# Line 232  public class StyledFeatureCollectionTabl Line 230  public class StyledFeatureCollectionTabl
230                                  String attName = schema.getAttributeDescriptors().get(idx)                                  String attName = schema.getAttributeDescriptors().get(idx)
231                                                  .getLocalName();                                                  .getLocalName();
232                                  colNames[i] = amdMap.get(attName).getTitle().toString();                                  colNames[i] = amdMap.get(attName).getTitle().toString();
233                                  AttributeMetadata amd = amdMap.get(attName);                                  AttributeMetadataInterface amd = amdMap.get(attName);
234                                  colTooltips[i] = "<html>"+amd.getDesc().toString()+"<br>"+amd.getName()+"</html>";                                  colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
235                                  colClass[i] = schema.getAttributeDescriptors().get(idx).getType()                                                  + amd.getName() + "</html>";
236                                                  .getBinding();                                  colClass[i] = schema.getAttributeDescriptors().get(idx)
237                                                    .getType().getBinding();
238                          }                          }
239                  }                  }
240    
# Line 244  public class StyledFeatureCollectionTabl Line 243  public class StyledFeatureCollectionTabl
243                  for (int i = 0; i < featureArray.length; i++)                  for (int i = 0; i < featureArray.length; i++)
244                          if (featureArray[i] != null)                          if (featureArray[i] != null)
245                                  featureIdx.put(featureArray[i].getID(), i);                                  featureIdx.put(featureArray[i].getID(), i);
246  //                  //
247  //              // translate the column names                  // // translate the column names
248  //              if (amdMap != null) {                  // if (amdMap != null) {
249  //                      for (int i = 0; i < colNames.length; i++) {                  // for (int i = 0; i < colNames.length; i++) {
250  //                              colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()                  // colTooltips[i] = amdMap.get(colNames[i]).getDesc().toString()
251  //                                              + "<br>" + colNames[i];                  // + "<br>" + colNames[i];
252  //                              colNames[i] = amdMap.get(colNames[i]).getTitle().toString();                  // colNames[i] = amdMap.get(colNames[i]).getTitle().toString();
253  //                  //
254  //                      }                  // }
255  //              }                  // }
256                  if (fireTableStructureChanged)                  if (fireTableStructureChanged)
257                          fireTableStructureChanged();                          fireTableStructureChanged();
258    

Legend:
Removed from v.534  
changed lines
  Added in v.862

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26