[Schmitzm-commits] r704 - in trunk: dist src/schmitzm/geotools/feature src/schmitzm/geotools/feature/resource/locales src/schmitzm/geotools/gui/resource/locales src/schmitzm/swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Feb 14 16:18:39 CET 2010


Author: mojays
Date: 2010-02-14 16:18:36 +0100 (Sun, 14 Feb 2010)
New Revision: 704

Modified:
   trunk/dist/schmitzm-2.0.x-src.zip
   trunk/dist/schmitzm-2.0.x.jar
   trunk/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
   trunk/src/schmitzm/geotools/feature/FeatureUtil.java
   trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle.properties
   trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_de.properties
   trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties
   trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
   trunk/src/schmitzm/swing/InputOption.java
Log:
FeatureUtil: new methods to check/apply attribute name restrictions
FeatureTypeBuilderTableModel: check attribute name restrictions
InputOption: new method checkInputAndError()

Modified: trunk/dist/schmitzm-2.0.x-src.zip
===================================================================
(Binary files differ)

Modified: trunk/dist/schmitzm-2.0.x.jar
===================================================================
(Binary files differ)

Modified: trunk/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/feature/FeatureTypeBuilderTableModel.java	2010-02-14 15:18:36 UTC (rev 704)
@@ -52,8 +52,11 @@
 
 import schmitzm.geotools.gui.GeotoolsGUIUtil;
 import schmitzm.swing.BooleanInputOption;
+import schmitzm.swing.ExceptionDialog;
+import schmitzm.swing.InputOption;
 import schmitzm.swing.ManualInputOption;
 import schmitzm.swing.SelectionInputOption;
+import schmitzm.swing.event.InputOptionAdapter;
 import schmitzm.swing.table.AbstractMutableTableModel;
 import schmitzm.swing.table.ComponentRenderer;
 import schmitzm.temp.BaseTypeUtil;
@@ -264,7 +267,21 @@
   public void setValueAt(Object value, int rowIndex, int columnIndex) {
     AttributeDefinition aDef = attrDefinitions.elementAt(rowIndex);
     switch ( columnIndex ) {
-      case 0: aDef.name.setValue(value); break;
+      case 0: // Attribut-Namen automatisch konvertieren
+              try {
+                FeatureUtil.checkAttributeNameRestrictionsAndError((String)value);
+                value = FeatureUtil.applyAttributeNameRestrictions((String)value);
+                aDef.name.setValue(value);
+              } catch (Exception err) {
+                ExceptionDialog.show(
+                    null,
+                    err,
+                    FeatureUtil.RESOURCE.getString("org.geotools.err.attr.name"),
+                    "<html><center><b>"+value+"</b></center>"+err.getMessage()+"</html>",
+                    false
+                );
+              }
+              break;
       case 1: aDef.type.setSelectedDisplayItem(value); break;
       case 2: aDef.nillable.setValue(value); break;
       case 3: aDef.autoValue.setValue(value); break;
@@ -277,7 +294,8 @@
    */
   public void performAddRow() {
     AttributeDefinition newAttrDef = new AttributeDefinition();
-    newAttrDef.name.setValue( GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr",getRowCount() ) );
+    String presetName = GeotoolsGUIUtil.RESOURCE.getString("schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr",getRowCount() );
+    newAttrDef.name.setValue( presetName );
     attrDefinitions.add( newAttrDef );
     fireTableDataChanged();
   }
@@ -323,7 +341,7 @@
      * Creates an empty attribute definition.
      */
     public AttributeDefinition() {
-      name         = new ManualInputOption.Text(null, true); // Attribute name is mandatory
+      name         = new ManualInputOption.Text(null, true); 
       type         = new SelectionInputOption.Combo<Class>(null,true,ATTR_TYPES,0,ATTR_TYPES_DESC);
       defaultValue = new ManualInputOption.Text(null,false); // Default value is not mandatory
       nillable     = new BooleanInputOption(null,true);
@@ -352,6 +370,12 @@
      * @return {@link DefaultAttributeType} or {@link GeometricAttributeType}
      */
     public AttributeDescriptor createAttributeType() {
+      try {
+        FeatureUtil.checkAttributeNameRestrictionsAndError( name.getValue() );
+      } catch (Exception err) {
+        throw new UnsupportedOperationException("<html><b><center>"+name.getValue()+"</b></center>"+err.getMessage()+"</html>",err);
+      }
+    
       Class   type         = (Class)this.type.getValue();
       boolean nillable     = (Boolean)this.nillable.getValue();
       Object  defaultValue = this.defaultValue.getValue();

Modified: trunk/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/feature/FeatureUtil.java	2010-02-14 15:18:36 UTC (rev 704)
@@ -614,8 +614,71 @@
 				aType.getType().getBinding(), nillable, restrictions,
 				defaultValue, metaData);
 	}
+	
+    /**
+     * Applies the following restrictions to an attribute name.
+     * <ul>
+     *   <li>Truncates white spaces at start and end.</li>
+     *   <li>Truncates name to 10 characters</li>
+     *   <li>Transforms name to upper case letters</li>
+     * </ul>
+     * @param attrName an attribute name
+     * @see #checkAttributeNameRestrictionsAndError(String)
+     */
+    public static String applyAttributeNameRestrictions(String attrName) {
+      // NULL not allowed
+      if ( attrName != null ) {
+        attrName = attrName.trim();
+        attrName = attrName.toUpperCase();
+        if ( attrName.length() > 10 )
+          attrName = attrName.substring(0,10);
+      }
+      return attrName;
+    }
+    
+    /**
+     * Throws an exception if an attribute name does not satisfy all of
+     * the following restrictions.
+     * <ul>
+     *   <li>{@code null} and empty string not allowed</li>
+     *   <li>Maximum of 10 characters</li>
+     *   <li>Starting with a letter (a-z,A-Z)</li>
+     *   <li>Only combination of letters (a-z,A-Z), digits (0-9) and '_'</li>
+     * </ul>
+     * @param attrName an attribute name
+     * @see #checkAttributeNameRestrictionsAndError(String)
+     */
+	public static void checkAttributeNameRestrictionsAndError(String attrName) throws Exception {
+	  // NULL not allowed
+	  if ( attrName == null || attrName.trim().equals("") )
+	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.null") );
+	  // Maximum 10 characters
+	  if ( attrName.length() > 10 )
+	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.length") );
+	  // Digit not allowed as first character
+	  if ( !attrName.matches("[a-zA-Z].*") )
+	    throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.start") );
+      // Only "normal" characters, digits and '_' allowed
+      if ( !attrName.matches("\\w+") )
+        throw new Exception( RESOURCE.getString("org.geotools.err.attr.name.chars") );
+	}
 
 	/**
+	 * Checks whether an attribute name satisfies all restrictions.
+	 * @param attrName an attribute name
+	 * @see #checkAttributeNameRestrictionsAndError(String)
+	 */
+	public static boolean checkAttributeNameRestrictions(String attrName) {
+	  try {
+	    checkAttributeNameRestrictionsAndError(attrName);
+	  } catch (Exception err) {
+	    return false;
+	  }
+	  return true;
+	}
+
+	
+	/**
 	 * Erweitert das Schema einer {@link FeatureCollection} um eine Reihe von
 	 * Attributen.
 	 * 

Modified: trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle.properties
===================================================================
--- trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle.properties	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle.properties	2010-02-14 15:18:36 UTC (rev 704)
@@ -58,6 +58,14 @@
 # ------ in Package schmitzm.geotools.feature          ------
 # -----------------------------------------------------------
 
+# --- Restrictions for attribute names ---
+org.geotools.err.attr.name=Attribute name not allowed 
+org.geotools.err.attr.name.null=Attribute name must not be NULL! 
+org.geotools.err.attr.name.length=At most 10 characters allowed for attribute name! 
+org.geotools.err.attr.name.start=Attribute name must start with a character (A-Z,a-z)!
+org.geotools.err.attr.name.chars=Only digits (0-9), characters (A-Z,a-z) and '_' allowed for attribute name!
+
+
 # --- Translations for FeatureOperationTree / FeatureOperationTreeParser
 FeatureOperationTree.err.NullAttr=FeatureOperationTree can not evaluate null-Attributes: ${0}
 FeatureOperationTree.err.UnknownAttr=Unknown feature attribute: ${0}

Modified: trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_de.properties
===================================================================
--- trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_de.properties	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/feature/resource/locales/FeatureResourceBundle_de.properties	2010-02-14 15:18:36 UTC (rev 704)
@@ -58,6 +58,13 @@
 # ------ in Package schmitzm.geotools.feature ------
 # --------------------------------------------------
 
+# --- Restrictions for attribute names ---
+org.geotools.err.attr.name=Attribute-Name nicht zulässig
+org.geotools.err.attr.name.null=Attribute-Name darf nicht NULL sein! 
+org.geotools.err.attr.name.length=Attribut-Name darf maximal 10 Zeichen lang sein! 
+org.geotools.err.attr.name.start=Attribut-Name muss mit einem Zeichen (A-Z,a-z) beginnen!
+org.geotools.err.attr.name.chars=Attribut-Name darf nur Ziffern (0-9), Zeichen (A-Z,a-z) und '_' beinhalten!
+
 # --- Translations for FeatureOperationTree / FeatureOperationTreeParser
 FeatureOperationTree.err.NullAttr=FeatureOperationTree keine null-Attribute auswerten: ${0}
 FeatureOperationTree.err.UnknownAttr=Unbekanntes Feature-Attribut: ${0}

Modified: trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties
===================================================================
--- trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle.properties	2010-02-14 15:18:36 UTC (rev 704)
@@ -33,6 +33,7 @@
 # ------ in Package schmitz.geotools.gui                   ------
 # ---------------------------------------------------------------
 
+Attribute=Attribute
 Attributes=Attributes
 
 org.geotools.styling.StyleBuilder.MARK_ARROW=Arrow
@@ -140,7 +141,7 @@
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.Nillable=Nillable
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.AutoValue=Auto
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.DefValue=Default
-schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr=Attribute_${0}
+schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr=ATTR_${0}
 
 schmitzm.geotools.gui.SelectableFeatureTablePane.button.clearSelection.tt=Clear selection
 schmitzm.geotools.gui.SelectableFeatureTablePane.button.selectionToTop.tt=Move selected to the top of the table

Modified: trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties
===================================================================
--- trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/geotools/gui/resource/locales/GTResourceBundle_de.properties	2010-02-14 15:18:36 UTC (rev 704)
@@ -32,6 +32,7 @@
 # ------ in Package schmitz.geotools.gui        ------
 # ----------------------------------------------------
 
+Attribute=Attribut
 Attributes=Attribute
 
 org.geotools.styling.StyleBuilder.MARK_ARROW=Pfeil
@@ -134,7 +135,7 @@
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.Nillable=Nullable
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.AutoValue=Auto-Wert
 schmitzm.geotools.gui.FeatureTypeBuilderTableModel.DefValue=Default
-schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr=Attribut_${0}
+schmitzm.geotools.gui.FeatureTypeBuilderTableModel.NewAttr=ATTR_${0}
 
 schmitzm.geotools.gui.SelectableFeatureTablePane.button.clearSelection.tt=Auswahl aufheben
 schmitzm.geotools.gui.SelectableFeatureTablePane.button.selectionToTop.tt=Ausgew\u00e4hlte Zeilen in der Tabelle nach oben verschieben 

Modified: trunk/src/schmitzm/swing/InputOption.java
===================================================================
--- trunk/src/schmitzm/swing/InputOption.java	2010-02-13 17:18:59 UTC (rev 703)
+++ trunk/src/schmitzm/swing/InputOption.java	2010-02-14 15:18:36 UTC (rev 704)
@@ -215,6 +215,15 @@
   }
 
   /**
+   * Prueft, ob die Eingabe in dem Feld zulaessig ist und wird ggf. eine
+   * Exception. Die Implementierung
+   */
+  public void checkInputAndError() throws Exception {
+    if ( !isInputValid() )
+      throw new Exception( getInvalidInputMessage() );
+  }
+
+  /**
    * Liefert die letzte von {@link #isInputValid()} erzeugte
    * Fehlermeldung.
    */



More information about the Schmitzm-commits mailing list