cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r591618 - in /cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map: CallbackDescriptor.java CallbackMap.java
Date Sat, 03 Nov 2007 13:17:36 GMT
Author: aadamchik
Date: Sat Nov  3 06:17:35 2007
New Revision: 591618

URL: http://svn.apache.org/viewvc?rev=591618&view=rev
Log:
CAY-900 Create CayenneModeler Swing UI for managing callbacks and lifecycle listeners
(first cut)

Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
    cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java?rev=591618&r1=591617&r2=591618&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackDescriptor.java
Sat Nov  3 06:17:35 2007
@@ -73,4 +73,50 @@
 
         this.callbackType = callbackType;
     }
+
+    /**
+     * moves specified callback method to the specified position
+     *
+     * @param callbackMethod callbacm method name (should exist)
+     * @param destinationIndex destinationi index (should be valid)
+     * @return true if any changes were made
+     */
+    public boolean moveMethod(String callbackMethod, int destinationIndex) {
+        List callbackMethodsList = new ArrayList(callbackMethods);
+        int currentIndex = callbackMethodsList.indexOf(callbackMethod);
+        if (currentIndex < 0)
+            throw new IllegalArgumentException("Unknown callback method: " + callbackMethod);
+
+        boolean changed = false;
+
+        if (destinationIndex > currentIndex) {
+            callbackMethodsList.add(destinationIndex + 1, callbackMethod);
+            callbackMethodsList.remove(currentIndex);
+            changed = true;
+        }
+        else if (destinationIndex < currentIndex) {
+            callbackMethodsList.add(destinationIndex, callbackMethod);
+            callbackMethodsList.remove(currentIndex + 1);
+            changed = true;
+        }
+
+        if (changed) {
+            callbackMethods.clear();
+            callbackMethods.addAll(callbackMethodsList);
+        }
+
+        return changed;
+    }
+
+    /**
+     * replaces callback method at the specified position
+     * @param index callback method index
+     * @param method new callback method
+     */
+    public void setCallbackMethodAt(int index, String method) {
+        List callbackMethodsList = new ArrayList(callbackMethods);
+        callbackMethodsList.set(index, method);
+        callbackMethods.clear();
+        callbackMethods.addAll(callbackMethodsList);
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java?rev=591618&r1=591617&r2=591618&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.4-unpublished/src/main/java/org/apache/cayenne/map/CallbackMap.java
Sat Nov  3 06:17:35 2007
@@ -20,6 +20,8 @@
 
 import java.io.Serializable;
 import java.util.Iterator;
+import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.cayenne.LifecycleListener;
 import org.apache.cayenne.util.XMLEncoder;
@@ -54,6 +56,11 @@
     protected CallbackDescriptor postRemove;
     protected CallbackDescriptor postLoad;
 
+    /**
+     * map for quick access to a callback descriptor by type
+     */
+    private Map callbacksMap = new HashMap();
+
     public CallbackMap() {
         this.prePersist = new CallbackDescriptor(LifecycleListener.PRE_PERSIST);
         this.postPersist = new CallbackDescriptor(LifecycleListener.POST_PERSIST);
@@ -62,10 +69,18 @@
         this.preRemove = new CallbackDescriptor(LifecycleListener.PRE_REMOVE);
         this.postRemove = new CallbackDescriptor(LifecycleListener.POST_REMOVE);
         this.postLoad = new CallbackDescriptor(LifecycleListener.POST_LOAD);
+
+        callbacksMap.put(new Integer(LifecycleListener.PRE_PERSIST), prePersist);
+        callbacksMap.put(new Integer(LifecycleListener.POST_PERSIST), postPersist);
+        callbacksMap.put(new Integer(LifecycleListener.PRE_UPDATE), preUpdate);
+        callbacksMap.put(new Integer(LifecycleListener.POST_UPDATE), postUpdate);
+        callbacksMap.put(new Integer(LifecycleListener.PRE_REMOVE), preRemove);
+        callbacksMap.put(new Integer(LifecycleListener.POST_REMOVE), postRemove);
+        callbacksMap.put(new Integer(LifecycleListener.POST_LOAD), postLoad);
     }
 
     /**
-     * Returns all event callbacks in a single array ordered by event type, following the
+     * @return all event callbacks in a single array ordered by event type, following the
      * order in {@link CallbackMap#CALLBACKS} array.
      */
     public CallbackDescriptor[] getCallbacks() {
@@ -73,6 +88,14 @@
                 prePersist, preRemove, preUpdate, postPersist, postRemove, postUpdate,
                 postLoad
         };
+    }
+
+    /**
+     * @param callbackType callback type id
+     * @return CallbackDescriptor for the specified callback type id
+     */
+    public CallbackDescriptor getCallbackDescriptor(int callbackType) {
+        return (CallbackDescriptor)callbacksMap.get(new Integer(callbackType));
     }
 
     public CallbackDescriptor getPostLoad() {



Mime
View raw message