[Schmitzm-commits] r352 - branches/1.0-gt2-2.6/src/schmitzm/geotools/feature

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Aug 31 14:51:49 CEST 2009


Author: mojays
Date: 2009-08-31 14:51:47 +0200 (Mon, 31 Aug 2009)
New Revision: 352

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
Log:
gt2-2.6.x conversion bugs eliminated

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2009-08-31 12:51:43 UTC (rev 351)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2009-08-31 12:51:47 UTC (rev 352)
@@ -43,8 +43,9 @@
 
 import org.geotools.feature.AttributeTypeFactory;
 import org.geotools.feature.DefaultAttributeType;
-import org.geotools.feature.FeatureTypeBuilder;
+import org.geotools.feature.GeometryAttributeType;
 import org.geotools.feature.SchemaException;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.feature.type.GeometricAttributeType;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
@@ -103,14 +104,14 @@
   /** Die in der Tabelle dargestellten Attribute. */
   protected Vector<AttributeDefinition> attrDefinitions = new Vector<AttributeDefinition>();
 
-  /** {@link FeatureTypeBuilder} der in der Tabelle dargestellt wird. */
-  protected FeatureTypeBuilder featureTypeBuilder = null;
+  /** {@link SimpleFeatureTypeBuilder} der in der Tabelle dargestellt wird. */
+  protected SimpleFeatureTypeBuilder featureTypeBuilder = null;
 
   /**
    * Erstellt ein leeres Tabellen-Modell.
    */
   public FeatureTypeBuilderTableModel() {
-    this((FeatureTypeBuilder)null);
+    this(null);
   }
 
   /**
@@ -123,15 +124,6 @@
   }
 
   /**
-   * Erstellt ein neues Tabellen-Modell.
-   * @param type ein SimpleFeatureType, der editiert wird
-   */
-  public FeatureTypeBuilderTableModel(FeatureTypeBuilder builder) {
-    super();
-    setFeatureTypeBuilder(builder);
-  }
-
-  /**
    * Liefert die Spaltennamen der Tabelle.
    */
   public String[] createColumnNames() {
@@ -186,18 +178,15 @@
 
   /**
    * Setzt den {@link FeatureTypeBuilder}, der in der Tabelle dargestellt wird.
-   * @param builder {@link FeatureTypeBuilder}
+   * Dieser wird mit den Attributen des angegebenen {@link SimpleFeatureType}
+   * initialisiert
+   * @param ftype {@link SimpleFeatureType}
    */
-  public void setFeatureTypeBuilder(FeatureTypeBuilder builder) {
-    if ( builder == null )
-      builder = FeatureTypeBuilder.newInstance("New Type");
-
-    this.featureTypeBuilder = builder;
+  public void setFeatureType(SimpleFeatureType ftype) {
     // Attribut-Typen in Array speichern
     attrDefinitions.clear();
     if ( featureTypeBuilder != null )
-      for (int i=0; i<featureTypeBuilder.getAttributeCount(); i++) {
-        AttributeDescriptor aDesc = featureTypeBuilder.get(i);
+      for (AttributeDescriptor aDesc : ftype.getAttributeDescriptors()) {
         attrDefinitions.add( new AttributeDefinition(
             aDesc.getLocalName(),
             aDesc.getType().getBinding(),
@@ -206,45 +195,27 @@
             aDesc.getDefaultValue()
         ) );
       }
+    
+    this.featureTypeBuilder = new SimpleFeatureTypeBuilder();
+    this.featureTypeBuilder.init(ftype);
+
     this.fireTableDataChanged();
   }
 
   /**
-   * Setzt den {@link FeatureTypeBuilder}, der in der Tabelle dargestellt wird.
-   * Dieser wird mit den Attributen des angegebenen {@link SimpleFeatureType}
-   * initialisiert
-   * @param ftype {@link SimpleFeatureType}
-   */
-  public void setFeatureType(SimpleFeatureType ftype) {
-    if ( ftype != null ) {
-      FeatureTypeBuilder builder = FeatureTypeBuilder.newInstance(ftype.getTypeName());
-      builder.addTypes(ftype.getAttributeDescriptors());
-      setFeatureTypeBuilder(builder);
-    } else
-      setFeatureTypeBuilder(null);
-  }
-
-  /**
    * Erzeugt einen neuen {@link SimpleFeatureType}, aus den in der Tabelle dargestellen
    * Attributen.
    */
   public SimpleFeatureType createFeatureType() {
-    try {
-//      this.featureTypeBuilder.removeAll(); // does not work because of BUG in gt2-2.4.4
-      for (;featureTypeBuilder.getAttributeCount() >0;)
-        this.featureTypeBuilder.removeType(0);
-
-      for (AttributeDefinition aDef : attrDefinitions) {
-        AttributeDescriptor aDesc = aDef.createAttributeType();
-        featureTypeBuilder.addType( aDesc );
-        if ( featureTypeBuilder.getDefaultGeometry() == null &&
-             aDesc instanceof GeometricAttributeType )
-          featureTypeBuilder.setDefaultGeometry( (GeometricAttributeType)aDesc );
-      }
-      return this.featureTypeBuilder.getFeatureType();
-    } catch (SchemaException err) {
-      throw new RuntimeException(err);
+    featureTypeBuilder.init(null);
+    for (AttributeDefinition aDef : attrDefinitions) {
+      AttributeDescriptor aDesc = aDef.createAttributeType();
+      featureTypeBuilder.add( aDesc );
+      if ( featureTypeBuilder.getDefaultGeometry() == null &&
+           aDesc instanceof GeometryAttributeType )
+        featureTypeBuilder.setDefaultGeometry( aDesc.getLocalName() );
     }
+    return this.featureTypeBuilder.buildFeatureType();
   }
 
   /**



More information about the Schmitzm-commits mailing list