cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertdzeig...@apache.org
Subject svn commit: r752200 - in /cayenne/main/trunk: docs/doc/src/main/resources/RELEASE-NOTES.txt framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java
Date Tue, 10 Mar 2009 18:14:03 GMT
Author: robertdzeigler
Date: Tue Mar 10 18:14:03 2009
New Revision: 752200

URL: http://svn.apache.org/viewvc?rev=752200&view=rev
Log:
CAY-1184: Callback methods should default to usable names.

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=752200&r1=752199&r2=752200&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Tue Mar 10 18:14:03 2009
@@ -29,6 +29,7 @@
 CAY-1161 Deprecate SelectQuery custom columns feature
 CAY-1174 Modeler: support optional meaningful PK mapping during reverse engineering
 CAY-1175 Replace String column name capitalization property with an enum
+CAY-1184 Callback methods should default to usable names
 
 Bug Fixes Since M5:
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java?rev=752200&r1=752199&r2=752200&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/AbstractCreateCallbackMethodAction.java
Tue Mar 10 18:14:03 2009
@@ -21,11 +21,13 @@
 import java.awt.event.ActionEvent;
 
 import org.apache.cayenne.map.CallbackMap;
+import org.apache.cayenne.map.LifecycleEvent;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.editor.CallbackType;
 import org.apache.cayenne.modeler.event.CallbackMethodEvent;
 import org.apache.cayenne.modeler.util.CayenneAction;
+import org.apache.cayenne.util.NameConverter;
 
 /**
  * Base class for creating callback methods
@@ -33,10 +35,6 @@
  * @version 1.0 Oct 28, 2007
  */
 public abstract class AbstractCreateCallbackMethodAction extends CayenneAction {
-    /**
-     * default name for new callback method
-     */
-    private static final String NEW_CALLBACK_METHOD = "untitled";
 
     /**
      * Constructor.
@@ -68,12 +66,19 @@
         CallbackType callbackType = getProjectController().getCurrentCallbackType();
 
         //generate methodName
-        int counter = 1;
+        String methodNamePrefix = toMethodName(callbackType.getType());
         String methodName;
-        do {
-            methodName = NEW_CALLBACK_METHOD + counter;
-            counter++;
-        } while(getCallbackMap().getCallbackDescriptor(callbackType.getType()).getCallbackMethods().contains(methodName));
+        //now that we're generating the method names based on the callback type, check to
see if the
+        //raw prefix, no numbers, is taken.
+        if (!getCallbackMap().getCallbackDescriptor(callbackType.getType()).getCallbackMethods().contains(methodNamePrefix))
{
+            methodName = methodNamePrefix;
+        } else {
+            int counter = 1;
+            do {
+                methodName = methodNamePrefix + counter;
+                counter++;
+            } while(getCallbackMap().getCallbackDescriptor(callbackType.getType()).getCallbackMethods().contains(methodName));
+        }
 
         getCallbackMap().getCallbackDescriptor(callbackType.getType()).addCallbackMethod(methodName);
 
@@ -86,5 +91,9 @@
 
         getProjectController().fireCallbackMethodEvent(ce);
     }
+
+    private String toMethodName(LifecycleEvent event) {
+        return "on" + NameConverter.underscoredToJava(event.name(),true);
+    }
 }
 



Mime
View raw message