[Schmitzm-commits] r168 - trunk/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Jun 28 19:57:39 CEST 2009


Author: alfonx
Date: 2009-06-28 19:57:38 +0200 (Sun, 28 Jun 2009)
New Revision: 168

Modified:
   trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
Log:
* Comitting new GT jars, because i had to resign them.
gt2-xml and gt2-wfs are now part of the game.

Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-06-28 14:27:37 UTC (rev 167)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-06-28 17:57:38 UTC (rev 168)
@@ -10,7 +10,6 @@
  **/
 package skrueger.geotools;
 
-
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Vector;
@@ -20,6 +19,7 @@
 import org.geotools.data.FeatureSource;
 import org.geotools.data.Query;
 import org.geotools.data.memory.MemoryDataStore;
+import org.geotools.feature.AttributeType;
 import org.geotools.feature.FeatureCollection;
 import org.opengis.filter.Filter;
 
@@ -35,102 +35,144 @@
  * functionalities of the {@link AttributeMetaData} of
  * {@linkplain StyledMapInterface styled objects}.
  * <ul>
- *   <li>column names are translated according to {@link AttributeMetaData#getTitle()}</li>
- *   <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
+ * <li>column names are translated according to
+ * {@link AttributeMetaData#getTitle()}</li>
+ * <li>columns are hidden according to {@link AttributeMetaData#isVisible()()}</li>
  * </ul>
- * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ * 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a>
+ *         (University of Bonn/Germany)
  */
-public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
-  final static private Logger LOGGER = Logger.getLogger(StyledFeatureCollectionTableModel.class);
-  /** Holds the data source as styled map. */ 
-  protected StyledMapInterface<?> map = null;
-  /** Contains only the visible elements of the {@link AttributeMetaData}-Map */
-  protected Map<Integer, AttributeMetaData> visibleAMD = 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;
-  /** Holds the current filter on the table */
-  protected Filter filter = null;
-  /** Holds the Bounds for all features. Only set once during the constructor **/
-  protected Envelope bounds;
+public class StyledFeatureCollectionTableModel extends
+		FeatureCollectionTableModel {
+	final static private Logger LOGGER = Logger
+			.getLogger(StyledFeatureCollectionTableModel.class);
+	/** Holds the data source as styled map. */
+	protected StyledMapInterface<?> map = null;
+	/** Contains only the visible elements of the {@link AttributeMetaData}-Map */
+	protected Map<Integer, AttributeMetaData> visibleAMD = 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;
+	/** Holds the current filter on the table */
+	protected Filter filter = null;
+	/** Holds the Bounds for all features. Only set once during the constructor **/
+	protected Envelope bounds;
 
-  /**
-   * Creates a new table model for a styled map.
-   * @param map the styled map
-   */
-  public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
-    this(map,Filter.INCLUDE);
-  }
+	/**
+	 * Creates a new table model for a styled map.
+	 * 
+	 * @param map
+	 *            the styled map
+	 */
+	public StyledFeatureCollectionTableModel(
+			StyledFeatureCollectionInterface map) {
+		this(map, Filter.INCLUDE);
+	}
 
-  /**
-   * Creates a new table model for a styled map.
-   * @param map the styled map
-   * @param filter filter applied to the table
-   */
-  public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map, Filter filter) {
-    super();
-    setFeatureCollection(map, filter);
-  }
+	/**
+	 * Creates a new table model for a styled map.
+	 * 
+	 * @param map
+	 *            the styled map
+	 * @param filter
+	 *            filter applied to the table
+	 */
+	public StyledFeatureCollectionTableModel(
+			StyledFeatureCollectionInterface map, Filter filter) {
+		super();
+		setFeatureCollection(map, filter);
+	}
 
-  /**
-   * Creates a new table model for a styled map.
-   * @param map the styled map
-   */
-  public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
-    this(map,Filter.INCLUDE);
-  }
+	/**
+	 * Creates a new table model for a styled map.
+	 * 
+	 * @param map
+	 *            the styled map
+	 */
+	public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
+		this(map, Filter.INCLUDE);
+	}
 
-  /**
-   * Creates a new table model for a styled map.
-   * @param map the styled map
-   * @param filter filter applied to the table
-   */
-  public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map, Filter filter) {
-    super();
-    setFeatureCollection(map, filter);
-  }
+	/**
+	 * Creates a new table model for a styled map.
+	 * 
+	 * @param map
+	 *            the styled map
+	 * @param filter
+	 *            filter applied to the table
+	 */
+	public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map,
+			Filter filter) {
+		super();
+		setFeatureCollection(map, filter);
+	}
 
-  /**
-   * Sets a new data source for the table.
-   * @param fs     the feature source
-   * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
-   *               and translation
-   */
-  protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {
-    if ( filter == null )
-      filter = Filter.INCLUDE;
-    
-    this.featureSource = fs;
-    this.filter        = filter;
-    this.origAMD       = amd;
-    this.visibleAMD    = null;
-    
-    FeatureCollection fc = null;
-    if (fs != null) {
-    	
-       bounds = fs.getBounds();	
-    	
-      Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
-      if (amd != null) {
-        // determine the names of the visible Attributes
-        this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
-        Vector<String> visibleAttrNames = new Vector<String>();
-        // Add the column with the geometry (usually "the_geom")
-        visibleAttrNames.add(fs.getSchema().getDefaultGeometry().getLocalName());
-        for (int attrIdx : visibleAMD.keySet())
-          visibleAttrNames.add(fs.getSchema().getAttributeType(attrIdx).getLocalName());
+	/**
+	 * Sets a new data source for the table.
+	 * 
+	 * @param fs
+	 *            the feature source
+	 * @param amd
+	 *            {@link AttributeMetaData}-Map to define the visible attributes
+	 *            and translation
+	 */
+	protected void setFeatureSource(FeatureSource fs,
+			Map<Integer, AttributeMetaData> amd, Filter filter)
+			throws Exception {
+		if (filter == null)
+			filter = Filter.INCLUDE;
 
-        // create a query for the visible attributes
-        String[] properties = visibleAttrNames.toArray(new String[0]);
-        
-        LOGGER.debug("Query contains the following attributes: " + visibleAttrNames);
-        
-        query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties);
-      }
-      fc = fs.getFeatures(query);
+		this.featureSource = fs;
+		this.filter = filter;
+		this.origAMD = amd;
+		this.visibleAMD = null;
 
-// FAILS:!!!, even with  query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
+		FeatureCollection fc = null;
+		if (fs != null) {
+
+			bounds = fs.getBounds();
+
+			Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
+			if (amd != null) {
+				// determine the names of the visible Attributes
+				this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(
+						amd, true);
+				Vector<String> visibleAttrNames = new Vector<String>();
+				// Add the column with the geometry (usually "the_geom")
+				visibleAttrNames.add(fs.getSchema().getDefaultGeometry()
+						.getLocalName());
+				for (int attrIdx : visibleAMD.keySet()) {
+
+					/**
+					 * If the user removed columns from the schema of the DBF
+					 * file, there might exist AttributeMetaData for columns
+					 * that don't exists. We check here to avoid an
+					 * ArrayOutOfIndex.
+					 */
+					if (attrIdx < fs.getSchema().getAttributeCount()) {
+						final AttributeType attributeTypeAtIdx = fs.getSchema()
+								.getAttributeType(attrIdx);
+						visibleAttrNames.add(attributeTypeAtIdx.getLocalName());
+					} else {
+						LOGGER.warn("AttributeMetaData has been found for columnIdx="+attrIdx+", but fs.getSchema().getAttributeCount() = "+fs.getSchema().getAttributeCount()+". Ignored.");
+					}
+				}
+
+				// create a query for the visible attributes
+				String[] properties = visibleAttrNames.toArray(new String[0]);
+
+				LOGGER.debug("Query contains the following attributes: "
+						+ visibleAttrNames);
+
+				query = new DefaultQuery(fs.getSchema().getTypeName(), filter,
+						properties);
+			}
+			fc = fs.getFeatures(query);
+
+			// FAILS:!!!, even with query = new
+			// DefaultQuery(fs.getSchema().getTypeName(), filter);
 			// java.lang.UnsupportedOperationException: Unknown feature
 			// attribute: PQM_MOD
 			// at
@@ -141,99 +183,115 @@
 			// System.out.println("Filter = "+filter);
 			// System.out.println("Size of FC = "+fc.size());
 			// System.out.println("anz att= "+fc.getNumberOfAttributes());
-    }
-    setFeatureCollection(fc);
-  }
+		}
+		setFeatureCollection(fc);
+	}
 
-  /**
-   * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
-   * and sets this as the new data source for the table.
-   * @param fs     the feature source
-   * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
-   *               and translation
-   */
-  public void setFeatureCollection(StyledFeatureCollectionInterface map, Filter filter) {
-    this.map = map;
-    try {
-      if (map == null)
-        setFeatureSource(null, null, null);
-      else {
-        FeatureCollection fc = map.getGeoObject();
-        String fcName = fc.getSchema().getTypeName();
-        FeatureSource fs = new MemoryDataStore(fc).getFeatureSource(fcName);
-        setFeatureSource(fs, map.getAttributeMetaDataMap(), filter);
-      }
-    } catch (Exception err) {
-      throw new RuntimeException(err);
-    }
-  }
+	/**
+	 * Converts the {@code StyledFeatureCollection} to a {@code FeatureSource}
+	 * and sets this as the new data source for the table.
+	 * 
+	 * @param fs
+	 *            the feature source
+	 * @param amd
+	 *            {@link AttributeMetaData}-Map to define the visible attributes
+	 *            and translation
+	 */
+	public void setFeatureCollection(StyledFeatureCollectionInterface map,
+			Filter filter) {
+		this.map = map;
+		try {
+			if (map == null)
+				setFeatureSource(null, null, null);
+			else {
+				FeatureCollection fc = map.getGeoObject();
+				String fcName = fc.getSchema().getTypeName();
+				FeatureSource fs = new MemoryDataStore(fc)
+						.getFeatureSource(fcName);
+				setFeatureSource(fs, map.getAttributeMetaDataMap(), filter);
+			}
+		} catch (Exception err) {
+			throw new RuntimeException(err);
+		}
+	}
 
-  /**
-   * Sets the {@code StyledFeatureCollection} as new data source for the table.
-   * @param fs     the feature source
-   * @param amd    {@link AttributeMetaData}-Map to define the visible attributes
-   *               and translation
-   */
-  public void setFeatureCollection(StyledFeatureSourceInterface map, Filter filter) {
-    this.map = map;
-    try {
-      if (map == null)
-        setFeatureSource(null, null, null);
-      else
-        setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap(), filter);
-    } catch (Exception err) {
-      throw new RuntimeException(err);
-    }
-  }
-  
-  /**
-   * Resets the filter for the table. 
-   * @param filter a filter
-   */
-  public void setFilter(Filter filter) {
-    try{
-      setFeatureSource(this.featureSource, this.origAMD, filter);
-    } catch (Exception err) {
-    	LOGGER.error("Setting the filter of the table model", err);
-      throw new RuntimeException(err);
-    }
-  }
-  
-  /**
-   * @return <code>Filter.INCLUDE</code> or the {@link Filter} applied to the Features
-   */
-  public Filter getFilter() {
-	  return this.filter;
-  }
+	/**
+	 * Sets the {@code StyledFeatureCollection} as new data source for the
+	 * table.
+	 * 
+	 * @param fs
+	 *            the feature source
+	 * @param amd
+	 *            {@link AttributeMetaData}-Map to define the visible attributes
+	 *            and translation
+	 */
+	public void setFeatureCollection(StyledFeatureSourceInterface map,
+			Filter filter) {
+		this.map = map;
+		try {
+			if (map == null)
+				setFeatureSource(null, null, null);
+			else
+				setFeatureSource(map.getGeoObject(), map
+						.getAttributeMetaDataMap(), filter);
+		} catch (Exception err) {
+			throw new RuntimeException(err);
+		}
+	}
 
-  /**
-   * After calling {@code super.reorganize(.)} this method replaced the
-   * column descriptions with the titles of the {@code AttributeMetaData}.
-   * @param fireTableStructureChanged indicates whether a table event is
-   *        initiated after reorganize
-   */
-  @Override
-  protected void reorganize(boolean fireTableStructureChanged) {
-    super.reorganize(false);
-    // translate the column names
-    if (visibleAMD != null) {
-      Iterator<Integer> keys = visibleAMD.keySet().iterator();
-      for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
-        Translation title = visibleAMD.get(keys.next()).getTitle();
-        if (!I8NUtil.isEmpty(title)) {
-//          System.out.println("set colname " + i + " to " + title.toString());
-          colNames[i] = title.toString();
-        }
-      }
-    }
-    if ( fireTableStructureChanged )
-      fireTableStructureChanged();
-  }
+	/**
+	 * Resets the filter for the table.
+	 * 
+	 * @param filter
+	 *            a filter
+	 */
+	public void setFilter(Filter filter) {
+		try {
+			setFeatureSource(this.featureSource, this.origAMD, filter);
+		} catch (Exception err) {
+			LOGGER.error("Setting the filter of the table model", err);
+			throw new RuntimeException(err);
+		}
+	}
 
-  /**
-	 * @return Cached bounds for the whole dataset (without applying the
-	 *          filter) or <code>null</code>
+	/**
+	 * @return <code>Filter.INCLUDE</code> or the {@link Filter} applied to the
+	 *         Features
 	 */
+	public Filter getFilter() {
+		return this.filter;
+	}
+
+	/**
+	 * After calling {@code super.reorganize(.)} this method replaced the column
+	 * descriptions with the titles of the {@code AttributeMetaData}.
+	 * 
+	 * @param fireTableStructureChanged
+	 *            indicates whether a table event is initiated after reorganize
+	 */
+	@Override
+	protected void reorganize(boolean fireTableStructureChanged) {
+		super.reorganize(false);
+		// translate the column names
+		if (visibleAMD != null) {
+			Iterator<Integer> keys = visibleAMD.keySet().iterator();
+			for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
+				Translation title = visibleAMD.get(keys.next()).getTitle();
+				if (!I8NUtil.isEmpty(title)) {
+					// System.out.println("set colname " + i + " to " +
+					// title.toString());
+					colNames[i] = title.toString();
+				}
+			}
+		}
+		if (fireTableStructureChanged)
+			fireTableStructureChanged();
+	}
+
+	/**
+	 * @return Cached bounds for the whole dataset (without applying the filter)
+	 *         or <code>null</code>
+	 */
 	public Envelope getBounds() {
 		return bounds;
 	}



More information about the Schmitzm-commits mailing list