Revision: 3659
Author: [email protected]
Date: Wed Jun 30 10:01:27 2010
Log: NEW - bug 2458: Create Critic Manager
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2458

Changed the quick fix on the physical name critic. It no longer prompts the user, instead it allows implementations to specify how to update the physical name if it does not match. The current implementation replaces spaces with underscores and removes other non-alpha-numeric characters.
http://code.google.com/p/power-architect/source/detail?r=3659

Modified:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/AlphaNumericNameCritic.java /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/OraclePhysicalNameCritic.java /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/PhysicalNameCritic.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/AlphaNumericNameCritic.java Fri Jun 25 12:04:13 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/AlphaNumericNameCritic.java Wed Jun 30 10:01:27 2010
@@ -33,5 +33,18 @@
                 Integer.MAX_VALUE);
         setName(Messages.getString("AlphaNumericNameCritic.name"));
     }
+
+    @Override
+    public String correctPhysicalName(String existingName) {
+        StringBuffer buffer = new StringBuffer(existingName.length());
+        for (int i = 0; i < existingName.length(); i++) {
+            if (existingName.charAt(i) == ' ') {
+                buffer.append('_');
+ } else if (getLegalNamePattern().matcher(Character.toString(existingName.charAt(i))).matches()) {
+                buffer.append(existingName.charAt(i));
+            }
+        }
+        return buffer.toString();
+    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/OraclePhysicalNameCritic.java Tue Jun 8 14:56:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/OraclePhysicalNameCritic.java Wed Jun 30 10:01:27 2010
@@ -33,5 +33,18 @@
Pattern.compile("^[a-z_][a-z0-9_]*$", Pattern.CASE_INSENSITIVE),
                 30);
     }
+
+    @Override
+    public String correctPhysicalName(String existingName) {
+        StringBuffer buffer = new StringBuffer(existingName.length());
+        for (int i = 0; i < existingName.length(); i++) {
+            if (existingName.charAt(i) == ' ') {
+                buffer.append('_');
+ } else if (getLegalNamePattern().matcher(Character.toString(existingName.charAt(i))).matches()) {
+                buffer.append(existingName.charAt(i));
+            }
+        }
+        return buffer.toString();
+    }

 }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/PhysicalNameCritic.java Tue Jun 29 13:26:19 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/PhysicalNameCritic.java Wed Jun 30 10:01:27 2010
@@ -24,7 +24,6 @@
 import java.util.List;
 import java.util.regex.Pattern;

-import ca.sqlpower.architect.ArchitectProject;
 import ca.sqlpower.architect.ddl.critic.Critic;
 import ca.sqlpower.architect.ddl.critic.CriticAndSettings;
 import ca.sqlpower.architect.ddl.critic.Criticism;
@@ -35,17 +34,13 @@
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLIndex.Column;
 import ca.sqlpower.sqlobject.SQLRelationship.ColumnMapping;
-import ca.sqlpower.util.UserPrompter;
-import ca.sqlpower.util.UserPrompter.UserPromptOptions;
-import ca.sqlpower.util.UserPrompter.UserPromptResponse;
-import ca.sqlpower.util.UserPrompterFactory.UserPromptType;

 /**
* Criticizes the physical name of all SQLObjects based on the parameters given
  * to the constructor.
  */
-public class PhysicalNameCritic extends CriticAndSettings {
-
+public abstract class PhysicalNameCritic extends CriticAndSettings {
+
     private final Pattern legalNamePattern;
     private final int maxNameLength;
     private final String platformName;
@@ -116,20 +111,15 @@
         }

         if (!getLegalNamePattern().matcher(physName).matches()) {
+            final String newLogicalName = correctPhysicalName(physName);
             criticisms.add(new Criticism(
                     so,
                     "Physical name not legal for " + so.getPhysicalName(),
                     this,
-                    new QuickFix("Enter a new physical name...") {
+ new QuickFix("Replace the physical name with " + newLogicalName) {
                         @Override
                         public void apply() {
- ArchitectProject project = getParent().getParent().getParent(); - UserPrompter prompter = project.getSession().createUserPrompter("Enter a legal physical name", - UserPromptType.TEXT, UserPromptOptions.OK_CANCEL, UserPromptResponse.CANCEL,
-                                    physName, "OK", "Cancel");
- if (UserPromptResponse.OK.equals(prompter.promptUser())) { - so.setPhysicalName((String) prompter.getUserSelectedResponse());
-                            }
+                            so.setPhysicalName(newLogicalName);
                         }
                     }
                     ));
@@ -137,6 +127,14 @@

         return criticisms;
     }
+
+    /**
+ * This method will be given the existing physical name of an object being + * criticized that does not match the pattern for valid physical names and + * it will return a valid physical name for the object that passes the legal
+     * name pattern.
+     */
+    public abstract String correctPhysicalName(String existingName);

     @Accessor
     public Pattern getLegalNamePattern() {

Reply via email to