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

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

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26