[Schmitzm-commits] r52 - in trunk/src: schmitzm/geotools/gui skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Apr 17 15:57:14 CEST 2009


Author: mojays
Date: 2009-04-17 15:57:14 +0200 (Fri, 17 Apr 2009)
New Revision: 52

Modified:
   trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
   trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
   trunk/src/skrueger/geotools/StyledMapUtil.java
Log:


Modified: trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-04-17 13:18:16 UTC (rev 51)
+++ trunk/src/schmitzm/geotools/gui/FeatureTablePane.java	2009-04-17 13:57:14 UTC (rev 52)
@@ -8,17 +8,7 @@
     Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
     Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
  **/
-/** SCHMITZM - This file is part of the java library of Martin O.J. Schmitz (SCHMITZM)
 
-    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
-    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
-    You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
-
-    Diese Bibliothek ist freie Software; Sie dürfen sie unter den Bedingungen der GNU Lesser General Public License, wie von der Free Software Foundation veröffentlicht, weiterverteilen und/oder modifizieren; entweder gemäß Version 2.1 der Lizenz oder (nach Ihrer Option) jeder späteren Version.
-    Diese Bibliothek wird in der Hoffnung weiterverbreitet, daß sie nützlich sein wird, jedoch OHNE IRGENDEINE GARANTIE, auch ohne die implizierte Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN BESTIMMTEN ZWECK. Mehr Details finden Sie in der GNU Lesser General Public License.
-    Sie sollten eine Kopie der GNU Lesser General Public License zusammen mit dieser Bibliothek erhalten haben; falls nicht, schreiben Sie an die Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA.
- **/
-
 package schmitzm.geotools.gui;
 
 import java.awt.BorderLayout;

Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-04-17 13:18:16 UTC (rev 51)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java	2009-04-17 13:57:14 UTC (rev 52)
@@ -10,27 +10,97 @@
  **/
 package skrueger.geotools;
 
+import java.util.Iterator;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.Vector;
+
+import org.geotools.data.DefaultQuery;
+import org.geotools.data.FeatureSource;
+import org.geotools.data.Query;
+import org.geotools.data.memory.MemoryDataStore;
+import org.geotools.feature.FeatureCollection;
+import org.opengis.filter.Filter;
+
 import schmitzm.geotools.gui.FeatureCollectionTableModel;
+import skrueger.AttributeMetaData;
 
+
+/**
+ * This class extends the 
+ * @author <a href="mailto:martin.schmitz at koeln.de">Martin Schmitz</a> (University of Bonn/Germany)
+ *
+ */
 public class StyledFeatureCollectionTableModel extends FeatureCollectionTableModel {
   
+  protected Map<Integer,AttributeMetaData> visibleAMD = null;
+  
   public StyledFeatureCollectionTableModel(StyledFeatureCollectionInterface map) {
-    super(null);
+    super();
+    setFeatureCollection(map);
   }
   
   public StyledFeatureCollectionTableModel(StyledFeatureSourceInterface map) {
-    super(null);
+    super();
+    setFeatureCollection(map);
   }
-
-  public String[] createColumnNames() {
-    return new String[0];
+  
+  protected void setFeatureSource(FeatureSource fs, Map<Integer,AttributeMetaData> amd) throws Exception {
+    FeatureCollection fc = null;
+    this.visibleAMD      = new TreeMap<Integer, AttributeMetaData>();
+    if ( fs != null ) {
+      Query query = new DefaultQuery();
+      if ( amd != null ) {
+        // determine the names of the visible Attributes
+        this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
+        Vector<String> visibleAttrNames = new Vector<String>();
+        for ( int attrIdx : visibleAMD.keySet() )
+          visibleAttrNames.add( fs.getSchema().getAttributeType(attrIdx).getLocalName() );
+        // create a query for the visible attributes  
+        query = new DefaultQuery(
+                       fs.getSchema().getTypeName(),
+                       Filter.INCLUDE,
+                       visibleAttrNames.toArray(new String[0])
+        );
+      }
+      fc = fs.getFeatures(query);
+    }
+    setFeatureCollection( fc );
   }
   
-  public int getRowCount() {
-    return 0;
+  public void setFeatureCollection(StyledFeatureCollectionInterface map) {
+    try {
+      if ( map == null )
+        setFeatureSource(null,null);
+      else {
+        FeatureCollection fc     = map.getGeoObject();
+        String            fcName = fc.getFeatureType().getTypeName();
+        FeatureSource     fs     = new MemoryDataStore(fc).getFeatureSource(fcName);
+        setFeatureSource(fs, map.getAttributeMetaDataMap());
+      }
+    } catch (Exception err) {
+      throw new RuntimeException(err);
+    }
   }
   
-  public Object getValueAt(int row, int col) {
-    return "";
+  public void setFeatureCollection(StyledFeatureSourceInterface map) {
+    try {
+      if ( map == null )
+        setFeatureSource(null,null);
+      else
+        setFeatureSource(map.getGeoObject(), map.getAttributeMetaDataMap());
+    } catch (Exception err) {
+      throw new RuntimeException(err);
+    }
   }
+  
+  @Override
+  public void reorganize() {
+    super.reorganize();
+    // translate the column names
+    Iterator<Integer> keys = visibleAMD.keySet().iterator();
+    for (int i=0; keys.hasNext(); i++)
+      colNames[i] = visibleAMD.get( keys.next() ).getTitle().toString();
+  }
+
 }

Modified: trunk/src/skrueger/geotools/StyledMapUtil.java
===================================================================
--- trunk/src/skrueger/geotools/StyledMapUtil.java	2009-04-17 13:18:16 UTC (rev 51)
+++ trunk/src/skrueger/geotools/StyledMapUtil.java	2009-04-17 13:57:14 UTC (rev 52)
@@ -4,6 +4,8 @@
 import java.util.Map;
 import java.util.HashMap;
 import java.util.List;
+import java.util.SortedMap;
+import java.util.TreeMap;
 import java.net.URL;
 
 import org.geotools.feature.FeatureCollection;
@@ -160,6 +162,22 @@
   }
 
   /**
+   * Return only the visible or invisible entries of an AttributeMetaData-Map.
+   * @param amdMap AttributeMetaData-Map
+   * @param visible indicated whether the visible or invisible entries are
+   *                returned 
+   */
+  public static Map<Integer,AttributeMetaData> getVisibleAttributeMetaData(Map<Integer,AttributeMetaData> amdMap, boolean visible) {
+    SortedMap<Integer,AttributeMetaData> filteredMap = new TreeMap<Integer,AttributeMetaData>();
+    for (AttributeMetaData amd : amdMap.values())
+      if ( amd.isVisible() )
+        filteredMap.put(amd.getColIdx(), amd);
+    
+    return filteredMap;
+  }
+  
+  
+  /**
    * Parses a {@link AttributeMetaData} object from an JDOM-{@link Element}.
    * This method works like {@link AMLImport#parseDataAttribute(org.w3c.dom.Node},
    * but for JDOM.



More information about the Schmitzm-commits mailing list