cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r893555 - in /cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: action/ undo/
Date Wed, 23 Dec 2009 15:54:35 GMT
Author: oltka
Date: Wed Dec 23 15:54:34 2009
New Revision: 893555

URL: http://svn.apache.org/viewvc?rev=893555&view=rev
Log:
CAY-1346
(cherry picked from commit c08ae46a1a00ae8add6e5411b413d48bc3b70395)

Added:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapEntityListenerUndoableEdit.java
Modified:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapEntityListenerAction.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityListenerAction.java

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapEntityListenerAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapEntityListenerAction.java?rev=893555&r1=893554&r2=893555&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapEntityListenerAction.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateDataMapEntityListenerAction.java
Wed Dec 23 15:54:34 2009
@@ -18,16 +18,24 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.action;
 
+import java.awt.event.ActionEvent;
+
+import javax.swing.JOptionPane;
+
+import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.EntityListener;
+import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.Application;
-
+import org.apache.cayenne.modeler.event.EntityListenerEvent;
+import org.apache.cayenne.modeler.undo.CreateDataMapEntityListenerUndoableEdit;
 
 /**
  * Action class for creating entity listeners on a DataMap
- *
+ * 
  * @version 1.0 Oct 30, 2007
  */
 public class CreateDataMapEntityListenerAction extends CreateObjEntityListenerAction {
+
     /**
      * unique action name
      */
@@ -35,7 +43,7 @@
 
     /**
      * Constructor.
-     *
+     * 
      * @param application Application instance
      */
     public CreateDataMapEntityListenerAction(Application application) {
@@ -51,20 +59,63 @@
 
     /**
      * checks whether the new name of listener class already exists
-     *
+     * 
      * @param className entered class name
      * @return true or false
      */
     protected boolean isListenerClassAlreadyExists(String className) {
-        return getProjectController().getCurrentDataMap().getDefaultEntityListener(className)
!= null;
+        return getProjectController().getCurrentDataMap().getDefaultEntityListener(
+                className) != null;
     }
 
     /**
      * adds new entity listener
+     * 
      * @param listener new EntityListener instance
      */
     protected void addEntityListener(EntityListener listener) {
         getProjectController().getCurrentDataMap().addDefaultEntityListener(listener);
     }
-}
 
+    /**
+     * base entity listenre creation logic
+     * 
+     * @param e event
+     */
+    @Override
+    public void performAction(ActionEvent e) {
+        String listenerClass = JOptionPane
+                .showInputDialog("Please enter listener class:");
+        if (listenerClass != null && listenerClass.trim().length() > 0) {
+            if (isListenerClassAlreadyExists(listenerClass)) {
+                JOptionPane.showMessageDialog(
+                        null,
+                        "Listener class already exists.",
+                        "Error creating entity listener",
+                        JOptionPane.ERROR_MESSAGE);
+            }
+            else {
+                DataMap dataMap = getProjectController().getCurrentDataMap();
+                if (dataMap != null) {
+                    EntityListener listener = new EntityListener(listenerClass);
+                    createMapListener(dataMap, listener);
+
+                    application
+                            .getUndoManager()
+                            .addEdit(
+                                    new CreateDataMapEntityListenerUndoableEdit(
+                                            dataMap,
+                                            listener));
+                }
+            }
+        }
+    }
+
+    public void createMapListener(DataMap dataMap, EntityListener listener) {
+        dataMap.addDefaultEntityListener(listener);
+
+        getProjectController().fireEntityListenerEvent(
+                new EntityListenerEvent(CreateDataMapEntityListenerAction.this, listener
+                        .getClassName(), listener.getClassName(), MapEvent.ADD));
+    }
+}

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityListenerAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityListenerAction.java?rev=893555&r1=893554&r2=893555&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityListenerAction.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/CreateObjEntityListenerAction.java
Wed Dec 23 15:54:34 2009
@@ -37,8 +37,6 @@
  */
 public class CreateObjEntityListenerAction extends CayenneAction {
 
-    
-
     /**
      * unique action name
      */

Added: cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapEntityListenerUndoableEdit.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapEntityListenerUndoableEdit.java?rev=893555&view=auto
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapEntityListenerUndoableEdit.java
(added)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CreateDataMapEntityListenerUndoableEdit.java
Wed Dec 23 15:54:34 2009
@@ -0,0 +1,59 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.modeler.undo;
+
+import javax.swing.undo.CannotRedoException;
+import javax.swing.undo.CannotUndoException;
+
+import org.apache.cayenne.map.DataMap;
+import org.apache.cayenne.map.EntityListener;
+import org.apache.cayenne.modeler.action.CreateDataMapEntityListenerAction;
+import org.apache.cayenne.modeler.action.RemoveEntityListenerForDataMapAction;
+
+
+public class CreateDataMapEntityListenerUndoableEdit extends CayenneUndoableEdit {
+
+    private DataMap dataMap;
+    private EntityListener listener;
+
+    public CreateDataMapEntityListenerUndoableEdit(DataMap dataMap, EntityListener listener)
{
+        this.dataMap = dataMap;
+        this.listener = listener;
+    }
+
+    @Override
+    public String getPresentationName() {
+        return "Create Entity Listener";
+    }
+
+    @Override
+    public void redo() throws CannotRedoException {
+        CreateDataMapEntityListenerAction action = (CreateDataMapEntityListenerAction) actionManager
+                .getAction(CreateDataMapEntityListenerAction.getActionName());
+        action.createMapListener(dataMap, listener);
+    }
+
+    @Override
+    public void undo() throws CannotUndoException {
+        RemoveEntityListenerForDataMapAction action = (RemoveEntityListenerForDataMapAction)
actionManager
+                .getAction(RemoveEntityListenerForDataMapAction.getActionName());
+
+        action.removeEntityListener(dataMap, listener.getClassName());
+    }
+}



Mime
View raw message