/[schmitzm]/branches/2.2.x/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
ViewVC logotype

Diff of /branches/2.2.x/src/skrueger/geotools/StyledFeatureCollectionTableModel.java

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

trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java revision 685 by alfonx, Wed Feb 10 15:04:02 2010 UTC branches/2.2.x/src/skrueger/geotools/StyledFeatureCollectionTableModel.java revision 1055 by alfonx, Thu Sep 23 17:38:23 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;
48  import schmitzm.geotools.gui.FeatureCollectionTableModel;  import schmitzm.geotools.gui.FeatureCollectionTableModel;
49  import skrueger.AttributeMetadata;  import skrueger.AttributeMetadataImpl;
50    import skrueger.AttributeMetadataInterface;
51    
52  import com.vividsolutions.jts.geom.Envelope;  import com.vividsolutions.jts.geom.Envelope;
53    
54  /**  /**
55   * This class extends the the {@link FeatureCollectionTableModel} with the   * This class extends the the {@link FeatureCollectionTableModel} with the
56   * functionalities of the {@link AttributeMetadata}.   * functionalities of the {@link AttributeMetadataImpl}.
57   * <ul>   * <ul>
58   * <li>column names are translated according to   * <li>column names are translated according to
59   * {@link AttributeMetadata#getTitle()}</li>   * {@link AttributeMetadataImpl#getTitle()}</li>
60   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>   * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
61   * <li>Any filter defined in the {@link StyledFeaturesInterface} will be   * <li>Any filter defined in the {@link StyledFeaturesInterface} will be
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 AttributeMetadata}-Map of the styled layer. */          /** Contains the complete {@link AttributeMetadataImpl}-Map of the styled layer. */
72          protected AttributeMetadataMap amdMap = null;          protected AttributeMetadataMap<? extends AttributeMetadataInterface> amdMap = null;
73          /** Holds the current filter on the table */          /** Holds the current filter on the table */
74          protected Filter filter = null;          protected Filter filter = null;
75          /** 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 79  public class StyledFeatureCollectionTabl Line 81  public class StyledFeatureCollectionTabl
81          protected String[] colTooltips = null;          protected String[] colTooltips = null;
82    
83          /** A cache for the #sortedValuesVisibleOnly() **/          /** A cache for the #sortedValuesVisibleOnly() **/
84          protected List<AttributeMetadata> amdMapVisibleOnly = null;          protected List<? extends AttributeMetadataInterface> amdMapVisibleOnly = null;
85    
86          /**          /**
87           * Creates a new table model for a styled layer.           * Creates a new table model for a styled layer.
# Line 96  public class StyledFeatureCollectionTabl Line 98  public class StyledFeatureCollectionTabl
98    
99          /**          /**
100           * This overwritten method filters the values for NODATA-values defined in           * This overwritten method filters the values for NODATA-values defined in
101           * the {@link AttributeMetadata}           * the {@link AttributeMetadataImpl}
102           */           */
103          @Override          @Override
104          public Object getValueAt(int row, int col) {          public Object getValueAt(int row, int col) {
# Line 110  public class StyledFeatureCollectionTabl Line 112  public class StyledFeatureCollectionTabl
112           * @param fs           * @param fs
113           *            the feature source           *            the feature source
114           * @param amdm           * @param amdm
115           *            {@link AttributeMetadata}-Map to define the visible attributes           *            {@link AttributeMetadataImpl}-Map to define the visible attributes
116           *            and translation           *            and translation
117           */           */
118          protected void setFeatureSource(          protected void setFeatureSource(
119                          FeatureSource<SimpleFeatureType, SimpleFeature> fs,                          FeatureSource<SimpleFeatureType, SimpleFeature> fs,
120                          AttributeMetadataMap amdm, Filter filter) throws Exception {                          AttributeMetadataMap<? extends AttributeMetadataInterface> amdm, Filter filter) throws Exception {
121    
122                  if (filter == null)                  if (filter == null)
123                          filter = Filter.INCLUDE;                          filter = Filter.INCLUDE;
# Line 124  public class StyledFeatureCollectionTabl Line 126  public class StyledFeatureCollectionTabl
126                  this.filter = filter;                  this.filter = filter;
127                  this.amdMap = amdm;                  this.amdMap = amdm;
128                  this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();                  this.amdMapVisibleOnly = amdMap.sortedValuesVisibleOnly();
129                    
130                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;                  FeatureCollection<SimpleFeatureType, SimpleFeature> fc = null;
131                  if (fs != null) {                  if (fs != null) {
132    
# Line 133  public class StyledFeatureCollectionTabl Line 135  public class StyledFeatureCollectionTabl
135                          final SimpleFeatureType schema = fs.getSchema();                          final SimpleFeatureType schema = fs.getSchema();
136                          Query query = new DefaultQuery(schema.getTypeName(), filter);                          Query query = new DefaultQuery(schema.getTypeName(), filter);
137                          if (amdm != null) {                          if (amdm != null) {
138                                  Vector<String> visibleAttrNames = new Vector<String>();                LinkedHashSet<String> visibleAttrNames = new LinkedHashSet<String>();
139    
140                                  // Add the column with the geometry (usually "the_geom") always                                  // Add the column with the geometry (usually "the_geom") always
141                                  visibleAttrNames.add(schema.getGeometryDescriptor()                                  String geomColumnLocalName = schema.getGeometryDescriptor()
142                                                  .getLocalName());                                                  .getLocalName();
143                                    visibleAttrNames.add(geomColumnLocalName);
144    
145                                  // Add other visible attributes as ordered by weights                                  // Add other visible attributes as ordered by weights
146                                  for (AttributeMetadata a : amdMapVisibleOnly) {                                  for (AttributeMetadataInterface a : amdMapVisibleOnly) {
147                                          visibleAttrNames.add(a.getLocalName());                                          visibleAttrNames.add(a.getLocalName());
148                                  }                                  }
149    
# Line 156  public class StyledFeatureCollectionTabl Line 159  public class StyledFeatureCollectionTabl
159                                  // } else {                                  // } else {
160                                  // query = new DefaultQuery(schema.getTypeName(), filter);                                  // query = new DefaultQuery(schema.getTypeName(), filter);
161                                  // }                                  // }
162                                    
163                                    System.out.println(query.getPropertyNames());
164                          }                          }
165                          fc = fs.getFeatures(query);                          fc = fs.getFeatures(query);
166                  }                  }
# Line 169  public class StyledFeatureCollectionTabl Line 174  public class StyledFeatureCollectionTabl
174           * @param fs           * @param fs
175           *            the feature source           *            the feature source
176           * @param amd           * @param amd
177           *            {@link AttributeMetadata}-Map to define the visible attributes           *            {@link AttributeMetadataImpl}-Map to define the visible attributes
178           *            and translation           *            and translation
179           */           */
180          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {          public void setStyledFeatures(StyledFeaturesInterface<?> styledFeatures) {
# Line 207  public class StyledFeatureCollectionTabl Line 212  public class StyledFeatureCollectionTabl
212                          SimpleFeatureType schema = featureArray[0].getFeatureType();                          SimpleFeatureType schema = featureArray[0].getFeatureType();
213                          // Pruefen, welche Attribute angezeigt werden                          // Pruefen, welche Attribute angezeigt werden
214                          attrTypes.clear();                          attrTypes.clear();
215                          for (AttributeMetadata amd : amdMapVisibleOnly) {                          for (AttributeMetadataInterface amd : amdMapVisibleOnly) {
216                                  AttributeDescriptor type = schema.getDescriptor(amd.getName());                                  Name name = amd.getName();
217                    AttributeDescriptor type = schema.getDescriptor(name);
218                    // if type can not be determined by complete name,
219                    // try only the local name
220                    if ( type == null )
221                      type = schema.getDescriptor(name.getLocalPart());
222                                  if (attrFilter == null || attrFilter.accept(type))                                  if (attrFilter == null || attrFilter.accept(type))
223                                          attrTypes.add(type);                                          attrTypes.add(type);
224                          }                          }
# Line 219  public class StyledFeatureCollectionTabl Line 229  public class StyledFeatureCollectionTabl
229                          colClass = new Class[attrTypes.size()];                          colClass = new Class[attrTypes.size()];
230                          attrIdxForCol = new int[attrTypes.size()];                          attrIdxForCol = new int[attrTypes.size()];
231                          for (int i = 0; i < colNames.length; i++) {                          for (int i = 0; i < colNames.length; i++) {
232                                  AttributeDescriptor descriptor = schema                                  Name name = amdMapVisibleOnly.get(i).getName();
233                                                  .getDescriptor(amdMapVisibleOnly.get(i).getName());                  AttributeDescriptor descriptor = schema.getDescriptor(name);
234                    // if type can not be determined by complete name,
235                    // try only the local name
236                    if ( descriptor == null )
237                      descriptor = schema.getDescriptor(name.getLocalPart());
238    
239                                  // Not so nice in 26: find the index of an attribute...                                  // Not so nice in 26: find the index of an attribute...
240                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);                                  int idx = schema.getAttributeDescriptors().indexOf(descriptor);
# Line 229  public class StyledFeatureCollectionTabl Line 243  public class StyledFeatureCollectionTabl
243                                  String attName = schema.getAttributeDescriptors().get(idx)                                  String attName = schema.getAttributeDescriptors().get(idx)
244                                                  .getLocalName();                                                  .getLocalName();
245                                  colNames[i] = amdMap.get(attName).getTitle().toString();                                  colNames[i] = amdMap.get(attName).getTitle().toString();
246                                  AttributeMetadata amd = amdMap.get(attName);                                  AttributeMetadataInterface amd = amdMap.get(attName);
247                                  colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"                                  colTooltips[i] = "<html>" + amd.getDesc().toString() + "<br>"
248                                                  + amd.getName() + "</html>";                                                  + amd.getName() + "</html>";
249                                  colClass[i] = schema.getAttributeDescriptors().get(idx)                                  colClass[i] = schema.getAttributeDescriptors().get(idx)

Legend:
Removed from v.685  
changed lines
  Added in v.1055

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26