cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject cayenne git commit: CAY-2388 Backport fix from master
Date Thu, 07 Dec 2017 13:37:13 GMT
Repository: cayenne
Updated Branches:
  refs/heads/STABLE-4.0 6a6cd0bfb -> d0b88ba35


CAY-2388 Backport fix from master


Project: http://git-wip-us.apache.org/repos/asf/cayenne/repo
Commit: http://git-wip-us.apache.org/repos/asf/cayenne/commit/d0b88ba3
Tree: http://git-wip-us.apache.org/repos/asf/cayenne/tree/d0b88ba3
Diff: http://git-wip-us.apache.org/repos/asf/cayenne/diff/d0b88ba3

Branch: refs/heads/STABLE-4.0
Commit: d0b88ba3564a798af5a1dae1af41707737fa9bac
Parents: 6a6cd0b
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Dec 7 16:34:27 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Dec 7 16:34:27 2017 +0300

----------------------------------------------------------------------
 docs/doc/src/main/resources/RELEASE-NOTES.txt   |   3 +-
 .../modeler/action/BaseViewEntityAction.java    |  41 ++-
 .../action/DbEntityCounterpartAction.java       |  85 +-----
 .../action/ObjEntityCounterpartAction.java      |   6 +
 .../action/ObjEntityToSuperEntityAction.java    |   7 +-
 .../cayenne/modeler/action/RemoveAction.java    | 277 ++++++-------------
 .../modeler/action/RemoveAttributeAction.java   |  33 +--
 .../undo/BaseRemovePropertyUndoableEdit.java    |  54 ++++
 .../modeler/undo/CayenneUndoableEdit.java       |   1 +
 .../modeler/undo/DbEntitySyncUndoableEdit.java  |  12 +-
 .../undo/RemoveAttributeUndoableEdit.java       |  85 ++----
 .../undo/RemoveRelationshipUndoableEdit.java    |  31 +--
 .../cayenne/modeler/util/CayenneAction.java     |  44 +++
 13 files changed, 260 insertions(+), 419 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/docs/doc/src/main/resources/RELEASE-NOTES.txt
----------------------------------------------------------------------
diff --git a/docs/doc/src/main/resources/RELEASE-NOTES.txt b/docs/doc/src/main/resources/RELEASE-NOTES.txt
index dfa0524..f933cf2 100644
--- a/docs/doc/src/main/resources/RELEASE-NOTES.txt
+++ b/docs/doc/src/main/resources/RELEASE-NOTES.txt
@@ -20,10 +20,9 @@ CAY-2365 SQLExec query tries to convert (unexpected) result set into objects
 CAY-2367 ClassCastException reading object with an attribute of type 'char'
 CAY-2368 ColumnSelect: Property.self() translates into wrong SQL code
 CAY-2370 ValueObjectType for byte[] fails lookup
-CAY-2379 Modeler: Visualization issue after an undo action for a deleted ObjAttribute
 CAY-2382 Lack of synchronization in DataContext serialization
-CAY-2384 Modeler: Visualization issue after an undo action for a deleted ObjRelationship
 CAY-2387 Can't select byte[] property with ColumnSelect
+CAY-2388 Modeler: Visualization issues with undo/redo actions for attributes and relationships
 
 ----------------------------------
 Release: 4.0.B2

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/BaseViewEntityAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/BaseViewEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/BaseViewEntityAction.java
index be4f26b..091c6dc 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/BaseViewEntityAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/BaseViewEntityAction.java
@@ -24,7 +24,6 @@ import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneAction;
 
@@ -34,9 +33,7 @@ import java.awt.event.ActionEvent;
 /**
  * @since 4.0
  */
-public abstract class BaseViewEntityAction extends CayenneAction{
-
-    protected ObjEntity objEntity;
+public abstract class BaseViewEntityAction extends CayenneAction {
 
     abstract protected Entity getEntity();
 
@@ -53,31 +50,25 @@ public abstract class BaseViewEntityAction extends CayenneAction{
     }
 
     protected void viewEntity() {
-        ProjectController mediator = getProjectController();
-
-        objEntity = mediator.getCurrentObjEntity();
-
-        if (objEntity == null) {
-            return;
-        }
-
         Entity entity = getEntity();
-
         if(entity != null) {
-            TreePath path = DbEntityCounterpartAction.buildTreePath(entity);
-            DbEntityCounterpartAction.editor().getProjectTreeView().getSelectionModel().setSelectionPath(path);
+            navigateToEntity(entity);
+        }
+    }
 
-            EntityDisplayEvent event = new EntityDisplayEvent(
-                    DbEntityCounterpartAction.editor().getProjectTreeView(),
-                    entity,
-                    entity.getDataMap(),
-                    (DataChannelDescriptor) getProjectController().getProject().getRootNode());
+    public void navigateToEntity(Entity entity) {
+        TreePath path = buildTreePath(entity);
+        editor().getProjectTreeView().getSelectionModel().setSelectionPath(path);
 
-            if (entity instanceof DbEntity) {
-                mediator.fireDbEntityDisplayEvent(event);
-            } else if (entity instanceof ObjEntity){
-                mediator.fireObjEntityDisplayEvent(event);
-            }
+        EntityDisplayEvent event = new EntityDisplayEvent(
+                editor().getProjectTreeView(),
+                entity,
+                entity.getDataMap(),
+                (DataChannelDescriptor) getProjectController().getProject().getRootNode());
+        if (entity instanceof DbEntity) {
+            getProjectController().fireDbEntityDisplayEvent(event);
+        } else if (entity instanceof ObjEntity){
+            getProjectController().fireObjEntityDisplayEvent(event);
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DbEntityCounterpartAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DbEntityCounterpartAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DbEntityCounterpartAction.java
index 35cf7f5..700b951 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DbEntityCounterpartAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/DbEntityCounterpartAction.java
@@ -19,24 +19,14 @@
 
 package org.apache.cayenne.modeler.action;
 
-import java.awt.event.ActionEvent;
 import java.util.Iterator;
 
-import javax.swing.tree.TreePath;
-
-import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.CayenneModelerFrame;
-import org.apache.cayenne.modeler.ProjectController;
-import org.apache.cayenne.modeler.ProjectTreeModel;
-import org.apache.cayenne.modeler.editor.EditorView;
-import org.apache.cayenne.modeler.event.EntityDisplayEvent;
-import org.apache.cayenne.modeler.util.CayenneAction;
 
-public class DbEntityCounterpartAction extends CayenneAction {
+public class DbEntityCounterpartAction extends BaseViewEntityAction {
 
     public static String getActionName() {
         return "View related ObjEntity";
@@ -50,78 +40,19 @@ public class DbEntityCounterpartAction extends CayenneAction {
         return "icon-move_up.png";
     }
 
-    /**
-     * @see org.apache.cayenne.modeler.util.CayenneAction#performAction(ActionEvent)
-     */
-    public void performAction(ActionEvent e) {
-        viewCounterpartEntity();
-    }
-
-    protected void viewCounterpartEntity() {
-        ProjectController mediator = getProjectController();
-
-        DbEntity dbEntity = mediator.getCurrentDbEntity();
-
+    @Override
+    protected Entity getEntity() {
+        DbEntity dbEntity = getProjectController().getCurrentDbEntity();
         if (dbEntity == null) {
-            return;
+            return null;
         }
-        
+
         Iterator<ObjEntity> it = dbEntity.getDataMap().getMappedEntities(dbEntity).iterator();
         if (!it.hasNext()) {
-            return;
+            return null;
         }
 
-        ObjEntity entity = it.next();
-        viewCounterpartEntity(entity);
+        return it.next();
     }
 
-    public void viewCounterpartEntity(ObjEntity entity) {        
-        TreePath path = buildTreePath(entity);
-        editor().getProjectTreeView().getSelectionModel().setSelectionPath(path);
-        
-        EntityDisplayEvent event = new EntityDisplayEvent(
-                editor().getProjectTreeView(),
-                entity,
-                entity.getDataMap(),
-                (DataChannelDescriptor) getProjectController().getProject().getRootNode());
-        getProjectController().fireObjEntityDisplayEvent(event);
-    }
-    
-    public static EditorView editor() {
-        return ((CayenneModelerFrame) Application
-                .getInstance()
-                .getFrameController()
-                .getView()).getView();
-    }
-    
-    /**
-     * Builds a tree path for a given entity. Urgent for later selection.
-     * 
-     * @param entity to build path for
-     * @return tree path
-     */
-    public static TreePath buildTreePath(Entity entity) {
-        DataChannelDescriptor domain = (DataChannelDescriptor) Application
-                .getInstance()
-                .getProject()
-                .getRootNode();
-        
-        Object[] path = new Object[] {domain, entity.getDataMap(), entity};
-
-        Object[] mutableTreeNodes = new Object[path.length];
-        mutableTreeNodes[0] = ((ProjectTreeModel) editor().getProjectTreeView().getModel())
-                .getRootNode();
-
-        Object[] helper;
-        for (int i = 1; i < path.length; i++) {
-            helper = new Object[i];
-            for (int j = 0; j < i;) {
-                helper[j] = path[++j];
-            }
-            mutableTreeNodes[i] = ((ProjectTreeModel) editor()
-                    .getProjectTreeView()
-                    .getModel()).getNodeForObjectPath(helper);
-        }
-        return new TreePath(mutableTreeNodes);
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityCounterpartAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityCounterpartAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityCounterpartAction.java
index 7126a0a..615ff93 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityCounterpartAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityCounterpartAction.java
@@ -20,6 +20,7 @@
 package org.apache.cayenne.modeler.action;
 
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
 
 public class ObjEntityCounterpartAction extends BaseViewEntityAction {
@@ -38,6 +39,11 @@ public class ObjEntityCounterpartAction extends BaseViewEntityAction {
 
     @Override
     protected Entity getEntity() {
+        ObjEntity objEntity = getProjectController().getCurrentObjEntity();
+        if (objEntity == null) {
+            return null;
+        }
         return objEntity.getDbEntity();
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityToSuperEntityAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityToSuperEntityAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityToSuperEntityAction.java
index eb0b839..16550ee 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityToSuperEntityAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/ObjEntityToSuperEntityAction.java
@@ -20,6 +20,7 @@
 package org.apache.cayenne.modeler.action;
 
 import org.apache.cayenne.map.Entity;
+import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
 
 /**
@@ -37,6 +38,10 @@ public class ObjEntityToSuperEntityAction extends BaseViewEntityAction {
 
     @Override
     protected Entity getEntity() {
-        return super.objEntity.getSuperEntity();
+        ObjEntity objEntity = getProjectController().getCurrentObjEntity();
+        if (objEntity == null) {
+            return null;
+        }
+        return objEntity.getSuperEntity();
     }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAction.java
index 7c36701..c39bde1 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAction.java
@@ -100,9 +100,7 @@ public class RemoveAction extends CayenneAction {
 
     @Override
     public KeyStroke getAcceleratorKey() {
-        return KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit
-                .getDefaultToolkit()
-                .getMenuShortcutKeyMask());
+        return KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
     }
 
     /**
@@ -127,172 +125,122 @@ public class RemoveAction extends CayenneAction {
     public void performAction(ActionEvent e, boolean allowAsking) {
 
         ProjectController mediator = getProjectController();
-
         ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
         
         if (mediator.getCurrentObjEntity() != null) {
-            if (dialog
-                    .shouldDelete("ObjEntity", mediator.getCurrentObjEntity().getName())) {
-                application.getUndoManager().addEdit(
-                        new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator
-                                .getCurrentObjEntity()));
-                removeObjEntity(mediator.getCurrentDataMap(), mediator
-                        .getCurrentObjEntity());
+            if (dialog.shouldDelete("ObjEntity", mediator.getCurrentObjEntity().getName())) {
+
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity()));
+                removeObjEntity(mediator.getCurrentDataMap(), mediator.getCurrentObjEntity());
             }
-        }
-        else if (mediator.getCurrentDbEntity() != null) {
+        } else if (mediator.getCurrentDbEntity() != null) {
             if (dialog.shouldDelete("DbEntity", mediator.getCurrentDbEntity().getName())) {
-                application.getUndoManager().addEdit(
-                        new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator
-                                .getCurrentDbEntity()));
-                removeDbEntity(mediator.getCurrentDataMap(), mediator
-                        .getCurrentDbEntity());
+
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity()));
+                removeDbEntity(mediator.getCurrentDataMap(), mediator.getCurrentDbEntity());
             }
-        }
-        else if (mediator.getCurrentQuery() != null) {
+        } else if (mediator.getCurrentQuery() != null) {
             if (dialog.shouldDelete("query", mediator.getCurrentQuery().getName())) {
-                application.getUndoManager().addEdit(
-                        new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator
-                                .getCurrentQuery()));
+
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentQuery()));
                 removeQuery(mediator.getCurrentDataMap(), mediator.getCurrentQuery());
             }
-        }
-        else if (mediator.getCurrentProcedure() != null) {
-            if (dialog
-                    .shouldDelete("procedure", mediator.getCurrentProcedure().getName())) {
-
-                application.getUndoManager().addEdit(
-                        new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator
-                                .getCurrentProcedure()));
-
-                removeProcedure(mediator.getCurrentDataMap(), mediator
-                        .getCurrentProcedure());
+        } else if (mediator.getCurrentProcedure() != null) {
+            if (dialog.shouldDelete("procedure", mediator.getCurrentProcedure().getName())) {
 
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentProcedure()));
+                removeProcedure(mediator.getCurrentDataMap(), mediator.getCurrentProcedure());
             }
-        }
-        else if (mediator.getCurrentEmbeddable() != null) {
-            if (dialog.shouldDelete("embeddable", mediator
-                    .getCurrentEmbeddable()
-                    .getClassName())) {
-
-                application.getUndoManager().addEdit(
-                        new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator
-                                .getCurrentEmbeddable()));
+        } else if (mediator.getCurrentEmbeddable() != null) {
+            if (dialog.shouldDelete("embeddable", mediator.getCurrentEmbeddable().getClassName())) {
 
-                removeEmbeddable(mediator.getCurrentDataMap(), mediator
-                        .getCurrentEmbeddable());
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable()));
+                removeEmbeddable(mediator.getCurrentDataMap(), mediator.getCurrentEmbeddable());
             }
-        }
-        else if (mediator.getCurrentDataMap() != null) {
+        } else if (mediator.getCurrentDataMap() != null) {
             if (dialog.shouldDelete("data map", mediator.getCurrentDataMap().getName())) {
 
                 // In context of Data node just remove from Data Node
                 if (mediator.getCurrentDataNode() != null) {
-                    application.getUndoManager().addEdit(
-                            new RemoveUndoableEdit(application, mediator
-                                    .getCurrentDataNode(), mediator.getCurrentDataMap()));
-
-                    removeDataMapFromDataNode(mediator.getCurrentDataNode(), mediator
-                            .getCurrentDataMap());
-
-                }
-                else {
+                    application.getUndoManager()
+                            .addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode(),
+                                    mediator.getCurrentDataMap()));
+                    removeDataMapFromDataNode(mediator.getCurrentDataNode(), mediator.getCurrentDataMap());
+                } else {
                     // Not under Data Node, remove completely
-                    application.getUndoManager().addEdit(
-                            new RemoveUndoableEdit(application, mediator
-                                    .getCurrentDataMap()));
-
+                    application.getUndoManager()
+                            .addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataMap()));
                     removeDataMap(mediator.getCurrentDataMap());
-
                 }
             }
-        }
-        else if (mediator.getCurrentDataNode() != null) {
+        } else if (mediator.getCurrentDataNode() != null) {
             if (dialog.shouldDelete("data node", mediator.getCurrentDataNode().getName())) {
-                application
-                        .getUndoManager()
-                        .addEdit(
-                                new RemoveUndoableEdit(application, mediator
-                                        .getCurrentDataNode()));
 
+                application.getUndoManager()
+                        .addEdit(new RemoveUndoableEdit(application, mediator.getCurrentDataNode()));
                 removeDataNode(mediator.getCurrentDataNode());
             }
-        }
-
-        else if (mediator.getCurrentPaths() != null) { // multiple deletion
+        } else if (mediator.getCurrentPaths() != null) { // multiple deletion
             if (dialog.shouldDelete("selected objects")) {
+
                 Object[] paths = mediator.getCurrentPaths();
                 Object parentPath = mediator.getCurrentParentPath();
 
                 CompoundEdit compoundEdit = new RemoveCompoundUndoableEdit();
-
                 for (Object path : paths) {
                     compoundEdit.addEdit(removeLastPathComponent(path, parentPath));
                 }
                 compoundEdit.end();
 
                 application.getUndoManager().addEdit(compoundEdit);
-
             }
         } else if(mediator.getCurrentCallbackMethods().length > 0) {
             removeMethods(mediator, dialog, getProjectController().getCurrentCallbackMethods());
-        }
-        else if(mediator.getCurrentObjRelationships().length > 0) {
+        } else if(mediator.getCurrentObjRelationships().length > 0) {
       		removeObjRelationships(mediator, dialog, getProjectController().getCurrentObjRelationships());
-        }
-        else if(mediator.getCurrentDbRelationships().length > 0) {
+        } else if(mediator.getCurrentDbRelationships().length > 0) {
       		removeDBRelationships(mediator, dialog, getProjectController().getCurrentDbRelationships());
-        }
-        else if(mediator.getCurrentObjAttributes().length > 0) {
+        } else if(mediator.getCurrentObjAttributes().length > 0) {
       		removeObjAttributes(mediator, dialog, getProjectController().getCurrentObjAttributes());
-        }
-        else if(mediator.getCurrentEmbAttributes().length > 0) {
+        } else if(mediator.getCurrentEmbAttributes().length > 0) {
       		removeEmbAttributes(mediator, dialog, getProjectController().getCurrentEmbAttributes());
-        }
-        else if(mediator.getCurrentDbAttributes().length > 0) {
+        } else if(mediator.getCurrentDbAttributes().length > 0) {
         	removeDbAttributes(mediator, dialog, getProjectController().getCurrentDbAttributes());
-        }
-        else if(mediator.getCurrentProcedureParameters().length > 0) {
+        } else if(mediator.getCurrentProcedureParameters().length > 0) {
         	removeProcedureParameters(mediator.getCurrentProcedure(), mediator.getCurrentProcedureParameters());
         }
 
     }
 
-    private void removeProcedureParameters(
-            Procedure procedure,
-            ProcedureParameter[] parameters) {
+    private void removeProcedureParameters(Procedure procedure, ProcedureParameter[] parameters) {
         ProjectController mediator = getProjectController();
-
         for (ProcedureParameter parameter : parameters) {
-
             procedure.removeCallParameter(parameter.getName());
-
-            ProcedureParameterEvent e = new ProcedureParameterEvent(Application
-                    .getFrame(), parameter, MapEvent.REMOVE);
-
+            ProcedureParameterEvent e = new ProcedureParameterEvent(Application.getFrame(), parameter, MapEvent.REMOVE);
             mediator.fireProcedureParameterEvent(e);
         }
     }
     
-    private void removeEmbAttributes(ProjectController mediator,
-			ConfirmRemoveDialog dialog,
-			EmbeddableAttribute[] embAttrs) {
+    private void removeEmbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog,
+                                     EmbeddableAttribute[] embAttrs) {
     	if (embAttrs != null && embAttrs.length > 0) {
-        	if ((embAttrs.length == 1 && dialog.shouldDelete("DbAttribute", embAttrs[0]
-        			.getName()))
+        	if ((embAttrs.length == 1 && dialog.shouldDelete("DbAttribute", embAttrs[0].getName()))
                     || (embAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
 
         		Embeddable embeddable = mediator.getCurrentEmbeddable();
 
-                application.getUndoManager().addEdit(
-                		new RemoveAttributeUndoableEdit(
-                                embeddable,
-                                embAttrs));
+                application.getUndoManager()
+                        .addEdit(new RemoveAttributeUndoableEdit(embeddable, embAttrs));
 
                 for (EmbeddableAttribute attrib : embAttrs) {
                     embeddable.removeAttribute(attrib.getName());
-                    EmbeddableAttributeEvent e = new EmbeddableAttributeEvent(Application
-                            .getFrame(), attrib, embeddable, MapEvent.REMOVE);
+                    EmbeddableAttributeEvent e = new EmbeddableAttributeEvent(Application.getFrame(),
+                            attrib, embeddable, MapEvent.REMOVE);
                     mediator.fireEmbeddableAttributeEvent(e);
                 }
 
@@ -304,28 +252,17 @@ public class RemoveAction extends CayenneAction {
 	private void removeObjAttributes(ProjectController mediator,
 			ConfirmRemoveDialog dialog, ObjAttribute[] objAttrs) {
     	if (objAttrs != null && objAttrs.length > 0) {
-        	if ((objAttrs.length == 1 && dialog.shouldDelete("DbAttribute", objAttrs[0]
-        			.getName()))
+        	if ((objAttrs.length == 1 && dialog.shouldDelete("DbAttribute", objAttrs[0].getName()))
                     || (objAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
 
         		ObjEntity entity = mediator.getCurrentObjEntity();
 
-                application.getUndoManager().addEdit(
-                        new RemoveAttributeUndoableEdit(
-                                (DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(),
-                                entity,
-                                objAttrs));
+                application.getUndoManager()
+                        .addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
 
                 for (ObjAttribute attrib : objAttrs) {
                     entity.removeAttribute(attrib.getName());
-
-                    AttributeEvent e = new AttributeEvent(
-                            Application.getFrame(),
-                            attrib,
-                            entity,
-                            MapEvent.REMOVE);
-
+                    AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                     mediator.fireObjAttributeEvent(e);
                 }
 
@@ -334,32 +271,19 @@ public class RemoveAction extends CayenneAction {
     	}
 	}
 
-	private void removeDbAttributes(ProjectController mediator,
-			ConfirmRemoveDialog dialog,
-			DbAttribute[] dbAttrs) {
+	private void removeDbAttributes(ProjectController mediator, ConfirmRemoveDialog dialog, DbAttribute[] dbAttrs) {
     	if (dbAttrs != null && dbAttrs.length > 0) {
-        	if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0]
-        			.getName()))
+        	if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0].getName()))
                     || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
 
         		DbEntity entity = mediator.getCurrentDbEntity();
 
-                application.getUndoManager().addEdit(
-                		new RemoveAttributeUndoableEdit(
-                				(DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(),
-                                entity,
-                                dbAttrs));
+                application.getUndoManager()
+                        .addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
 
                 for (DbAttribute attrib : dbAttrs) {
                     entity.removeAttribute(attrib.getName());
-
-                    AttributeEvent e = new AttributeEvent(
-                            Application.getFrame(),
-                            attrib,
-                            entity,
-                            MapEvent.REMOVE);
-
+                    AttributeEvent e = new AttributeEvent(Application.getFrame(), attrib, entity, MapEvent.REMOVE);
                     mediator.fireDbAttributeEvent(e);
                 }
 
@@ -368,53 +292,40 @@ public class RemoveAction extends CayenneAction {
     	}
     }
     
-    private void removeDBRelationships(ProjectController mediator,
-			ConfirmRemoveDialog dialog,
-			DbRelationship[] dbRels) {
+    private void removeDBRelationships(ProjectController mediator, ConfirmRemoveDialog dialog,
+                                       DbRelationship[] dbRels) {
 		if (dbRels != null && dbRels.length > 0) {
-			if ((dbRels.length == 1 && dialog.shouldDelete(
-					"DbRelationship", dbRels[0].getName()))
-					|| (dbRels.length > 1 && dialog
-							.shouldDelete("selected DbRelationships"))) {
+			if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName()))
+					|| (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
 				DbEntity entity = mediator.getCurrentDbEntity();
 				
 				for (DbRelationship rel : dbRels) {
 					entity.removeRelationship(rel.getName());
-
-					RelationshipEvent e = new RelationshipEvent(Application.getFrame(),
-							rel, entity, MapEvent.REMOVE);
+					RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
 					mediator.fireDbRelationshipEvent(e);
 				}
 
 				ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
-				
-				Application.getInstance().getUndoManager().addEdit(
-						new RemoveRelationshipUndoableEdit(entity, dbRels));
+				Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
 			}
 		}
 	}
 
-	private void removeObjRelationships(ProjectController mediator,
-			ConfirmRemoveDialog dialog,
-			ObjRelationship[] rels) {
-		if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship",
-				rels[0].getName()))
-				|| (rels.length > 1 && dialog
-						.shouldDelete("selected ObjRelationships"))) {
+	private void removeObjRelationships(ProjectController mediator, ConfirmRemoveDialog dialog,
+                                        ObjRelationship[] rels) {
+		if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName()))
+				|| (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
 			ObjEntity entity = mediator.getCurrentObjEntity();
 			for (ObjRelationship rel : rels) {
 				entity.removeRelationship(rel.getName());
-				RelationshipEvent e = new RelationshipEvent(Application.getFrame(),
-						rel, entity, MapEvent.REMOVE);
+				RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
 				mediator.fireObjRelationshipEvent(e);
 			}
-			Application.getInstance().getUndoManager().addEdit(
-					new RemoveRelationshipUndoableEdit(entity, rels));
+			Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
 		}		
 	}
 
-	private void removeMethods(ProjectController mediator,
-			ConfirmRemoveDialog dialog, ObjCallbackMethod[] methods) {
+	private void removeMethods(ProjectController mediator, ConfirmRemoveDialog dialog, ObjCallbackMethod[] methods) {
     	CallbackMap callbackMap = mediator.getCurrentObjEntity().getCallbackMap();
     	CallbackType callbackType = mediator.getCurrentCallbackType();
 
@@ -423,25 +334,21 @@ public class RemoveAction extends CayenneAction {
             for (ObjCallbackMethod callbackMethod : methods) {
             	callbackMap.getCallbackDescriptor(callbackType.getType()).removeCallbackMethod(callbackMethod.getName());
                     
-                CallbackMethodEvent ce = new CallbackMethodEvent(
-                        this,
-                        null,
+                CallbackMethodEvent ce = new CallbackMethodEvent(this, null,
                         callbackMethod.getName(),
                         MapEvent.REMOVE);
                     
                 mediator.fireCallbackMethodEvent(ce);
             }
             
-            Application.getInstance().getUndoManager().addEdit( 
-            		new RemoveCallbackMethodUndoableEdit(callbackType, methods));
+            Application.getInstance().getUndoManager()
+                    .addEdit(new RemoveCallbackMethodUndoableEdit(callbackType, methods));
         }		
 	}
 
 	public void removeDataMap(DataMap map) {
         ProjectController mediator = getProjectController();
-        DataChannelDescriptor domain = (DataChannelDescriptor) mediator
-                .getProject()
-                .getRootNode();
+        DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
         DataMapEvent e = new DataMapEvent(Application.getFrame(), map, MapEvent.REMOVE);
         e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
 
@@ -451,11 +358,9 @@ public class RemoveAction extends CayenneAction {
             Collection<URL> unusedResources = getCurrentProject().getUnusedResources();
             unusedResources.add(mapURL);
         }
-        
-        Iterator<DataNodeDescriptor> iterator = domain.getNodeDescriptors().iterator();
-        while(iterator.hasNext()){
-            DataNodeDescriptor node = iterator.next();
-            if(node.getDataMapNames().contains(map.getName())){
+
+        for (DataNodeDescriptor node : domain.getNodeDescriptors()) {
+            if (node.getDataMapNames().contains(map.getName())) {
                 removeDataMapFromDataNode(node, map);
             }
         }
@@ -465,9 +370,7 @@ public class RemoveAction extends CayenneAction {
 
     public void removeDataNode(DataNodeDescriptor node) {
         ProjectController mediator = getProjectController();
-        DataChannelDescriptor domain = (DataChannelDescriptor) mediator
-                .getProject()
-                .getRootNode();
+        DataChannelDescriptor domain = (DataChannelDescriptor) mediator.getProject().getRootNode();
         DataNodeEvent e = new DataNodeEvent(Application.getFrame(), node, MapEvent.REMOVE);
         e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
 
@@ -507,10 +410,7 @@ public class RemoveAction extends CayenneAction {
     public void removeProcedure(DataMap map, Procedure procedure) {
         ProjectController mediator = getProjectController();
 
-        ProcedureEvent e = new ProcedureEvent(
-                Application.getFrame(),
-                procedure,
-                MapEvent.REMOVE);
+        ProcedureEvent e = new ProcedureEvent(Application.getFrame(), procedure, MapEvent.REMOVE);
         e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
 
         map.removeProcedure(procedure.getName());
@@ -537,9 +437,7 @@ public class RemoveAction extends CayenneAction {
             if (!QueryDescriptor.EJBQL_QUERY.equals(query.getType())) {
                 Object root = query.getRoot();
 
-                if (root == entity
-                        || (root instanceof String && root.toString().equals(
-                                entity.getName()))) {
+                if (root == entity || (root instanceof String && root.toString().equals(entity.getName()))) {
                     removeQuery(map, query);
                 }
             }
@@ -549,10 +447,7 @@ public class RemoveAction extends CayenneAction {
     public void removeEmbeddable(DataMap map, Embeddable embeddable) {
         ProjectController mediator = getProjectController();
 
-        EmbeddableEvent e = new EmbeddableEvent(
-                Application.getFrame(),
-                embeddable,
-                MapEvent.REMOVE);
+        EmbeddableEvent e = new EmbeddableEvent(Application.getFrame(), embeddable, MapEvent.REMOVE);
         e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
 
         map.removeEmbeddable(embeddable.getClassName());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAttributeAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAttributeAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAttributeAction.java
index 769b2a0..66cb396 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAttributeAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/RemoveAttributeAction.java
@@ -44,12 +44,9 @@ import org.apache.cayenne.modeler.util.ProjectUtil;
 
 /**
  * Removes currently selected attribute from either the DbEntity or ObjEntity.
- * 
  */
 public class RemoveAttributeAction extends RemoveAction implements MultipleObjectsAction {
 
-    
-
     private final static String ACTION_NAME = "Remove Attribute";
 
     /**
@@ -75,11 +72,7 @@ public class RemoveAttributeAction extends RemoveAction implements MultipleObjec
      */
     @Override
     public boolean enableForPath(ConfigurationNode object) {
-        if (object == null) {
-            return false;
-        }
-
-        return object instanceof Attribute;
+        return object != null && object instanceof Attribute;
     }
 
     @Override
@@ -107,37 +100,25 @@ public class RemoveAttributeAction extends RemoveAction implements MultipleObjec
                 removeEmbeddableAttributes(embeddable, embAttrs);
 
             }
-        }
-        else if (objAttrs != null && objAttrs.length > 0) {
+        } else if (objAttrs != null && objAttrs.length > 0) {
             if ((objAttrs.length == 1 && dialog.shouldDelete("ObjAttribute", objAttrs[0]
                     .getName()))
                     || (objAttrs.length > 1 && dialog.shouldDelete("selected ObjAttributes"))) {
 
                 ObjEntity entity = mediator.getCurrentObjEntity();
 
-                application.getUndoManager().addEdit(
-                        new RemoveAttributeUndoableEdit(
-                                (DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(),
-                                entity,
-                                objAttrs));
+                application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
 
                 removeObjAttributes(entity, objAttrs);
             }
-        }
-        else if (dbAttrs != null && dbAttrs.length > 0) {
+        } else if (dbAttrs != null && dbAttrs.length > 0) {
         	if ((dbAttrs.length == 1 && dialog.shouldDelete("DbAttribute", dbAttrs[0]
         			.getName()))
                     || (dbAttrs.length > 1 && dialog.shouldDelete("selected DbAttributes"))) {
 
         		DbEntity entity = mediator.getCurrentDbEntity();
 
-                application.getUndoManager().addEdit(
-                		new RemoveAttributeUndoableEdit(
-                				(DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(),
-                                entity,
-                                dbAttrs));
+                application.getUndoManager().addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
 
                 removeDbAttributes(mediator.getCurrentDataMap(), entity, dbAttrs);
         	}
@@ -181,9 +162,7 @@ public class RemoveAttributeAction extends RemoveAction implements MultipleObjec
         }
     }
 
-    public void removeEmbeddableAttributes(
-            Embeddable embeddable,
-            EmbeddableAttribute[] attrs) {
+    public void removeEmbeddableAttributes(Embeddable embeddable, EmbeddableAttribute[] attrs) {
         ProjectController mediator = getProjectController();
 
         for (EmbeddableAttribute attrib : attrs) {

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/BaseRemovePropertyUndoableEdit.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/BaseRemovePropertyUndoableEdit.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/BaseRemovePropertyUndoableEdit.java
new file mode 100644
index 0000000..30a9270
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/BaseRemovePropertyUndoableEdit.java
@@ -0,0 +1,54 @@
+/*****************************************************************
+ *   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 org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.action.ObjEntityCounterpartAction;
+import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
+
+/**
+ * @since 4.1
+ */
+public abstract class BaseRemovePropertyUndoableEdit extends CayenneUndoableEdit {
+
+    protected ObjEntity objEntity;
+    protected DbEntity dbEntity;
+    protected Embeddable embeddable;
+
+    protected void focusObjEntity(){
+        actionManager.getAction(ObjEntityCounterpartAction.class).navigateToEntity(objEntity);
+    }
+
+    protected void focusDBEntity(){
+        actionManager.getAction(ObjEntityCounterpartAction.class).navigateToEntity(dbEntity);
+    }
+
+    protected void focusEmbeddable() {
+        controller.fireEmbeddableDisplayEvent(new EmbeddableDisplayEvent(
+                this,
+                embeddable,
+                embeddable.getDataMap(),
+                (DataChannelDescriptor) controller.getProject().getRootNode()));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java
index 6bd8527..659f236 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/CayenneUndoableEdit.java
@@ -43,4 +43,5 @@ public abstract class CayenneUndoableEdit extends AbstractUndoableEdit {
     public boolean canUndo() {
         return true;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/DbEntitySyncUndoableEdit.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/DbEntitySyncUndoableEdit.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/DbEntitySyncUndoableEdit.java
index 20e1749..9d8d258 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/DbEntitySyncUndoableEdit.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/DbEntitySyncUndoableEdit.java
@@ -60,9 +60,7 @@ public class DbEntitySyncUndoableEdit extends CompoundEdit {
         }
 
         public void objRelationshipAdded(ObjRelationship rel) {
-            addEdit(new CreateRelationshipUndoableEdit(entity, new ObjRelationship[] {
-                rel
-            }));
+            addEdit(new CreateRelationshipUndoableEdit(entity, new ObjRelationship[] {rel}));
         }
 
         public void objAttributeAdded(ObjAttribute attr) {
@@ -86,13 +84,7 @@ public class DbEntitySyncUndoableEdit extends CompoundEdit {
             for (DbAttribute da : dbAttrs) {
                 ObjAttribute oa = entity.getAttributeForDbAttribute(da);
                 if (oa != null) {
-                    addEdit(new RemoveAttributeUndoableEdit(
-                            domain,
-                            map,
-                            entity,
-                            new ObjAttribute[] {
-                                oa
-                            }));
+                    addEdit(new RemoveAttributeUndoableEdit(entity, new ObjAttribute[] {oa}));
                 }
             }
         }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java
index 5db0c52..5ef1497 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveAttributeUndoableEdit.java
@@ -21,8 +21,6 @@ package org.apache.cayenne.modeler.undo;
 import javax.swing.undo.CannotRedoException;
 import javax.swing.undo.CannotUndoException;
 
-import org.apache.cayenne.configuration.DataChannelDescriptor;
-import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.Embeddable;
@@ -30,131 +28,88 @@ import org.apache.cayenne.map.EmbeddableAttribute;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.action.CreateAttributeAction;
-import org.apache.cayenne.modeler.action.DbEntityCounterpartAction;
 import org.apache.cayenne.modeler.action.RemoveAttributeAction;
-import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
-import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 
-public class RemoveAttributeUndoableEdit extends CayenneUndoableEdit {
-
-    private DataChannelDescriptor domain;
-    private DataMap dataMap;
+public class RemoveAttributeUndoableEdit extends BaseRemovePropertyUndoableEdit {
 
     private DbAttribute[] dbAttributes;
     private ObjAttribute[] objAttributes;
-
-    private ObjEntity objEntity;
-    private DbEntity dbEntity;
-
-    private Embeddable embeddable;
     private EmbeddableAttribute[] embeddableAttrs;
 
-    public RemoveAttributeUndoableEdit(Embeddable embeddable,
-            EmbeddableAttribute[] embeddableAttrs) {
+    public RemoveAttributeUndoableEdit(Embeddable embeddable, EmbeddableAttribute[] embeddableAttributes) {
         super();
         this.embeddable = embeddable;
-        this.embeddableAttrs = embeddableAttrs;
+        this.embeddableAttrs = embeddableAttributes;
     }
 
-    public RemoveAttributeUndoableEdit(DataChannelDescriptor domain, DataMap dataMap,
-            ObjEntity entity, ObjAttribute[] attribs) {
+    public RemoveAttributeUndoableEdit(ObjEntity entity, ObjAttribute[] objAttributes) {
         this.objEntity = entity;
-        this.objAttributes = attribs;
-        this.domain = domain;
-        this.dataMap = dataMap;
+        this.objAttributes = objAttributes;
     }
 
-    public RemoveAttributeUndoableEdit(DataChannelDescriptor domain, DataMap dataMap,
-            DbEntity entity, DbAttribute[] attribs) {
+    public RemoveAttributeUndoableEdit(DbEntity entity, DbAttribute[] dbAttributes) {
         this.dbEntity = entity;
-        this.dbAttributes = attribs;
-        this.domain = domain;
-        this.dataMap = dataMap;
+        this.dbAttributes = dbAttributes;
     }
 
     @Override
     public void redo() throws CannotRedoException {
-        RemoveAttributeAction action = actionManager
-                .getAction(RemoveAttributeAction.class);
+        RemoveAttributeAction action = actionManager.getAction(RemoveAttributeAction.class);
 
         if (objEntity != null) {
             action.removeObjAttributes(objEntity, objAttributes);
-            controller.fireObjEntityDisplayEvent(new EntityDisplayEvent(
-                    this,
-                    objEntity,
-                    dataMap,
-                    domain));
+            focusObjEntity();
         }
 
         if (dbEntity != null) {
             action.removeDbAttributes(dbEntity.getDataMap(), dbEntity, dbAttributes);
-            controller.fireDbEntityDisplayEvent(new EntityDisplayEvent(
-                    this,
-                    dbEntity,
-                    dataMap,
-                    domain));
+            focusDBEntity();
         }
 
         if (embeddable != null) {
             action.removeEmbeddableAttributes(embeddable, embeddableAttrs);
-            controller.fireEmbeddableDisplayEvent(new EmbeddableDisplayEvent(
-                    this,
-                    embeddable,
-                    dataMap,
-                    domain));
+            focusEmbeddable();
         }
     }
 
     @Override
     public void undo() throws CannotUndoException {
-
-        CreateAttributeAction action = actionManager
-                .getAction(CreateAttributeAction.class);
+        CreateAttributeAction action = actionManager.getAction(CreateAttributeAction.class);
 
         if (objEntity != null) {
             for (ObjAttribute attr : objAttributes) {
-                action.createObjAttribute(dataMap, objEntity, attr);
+                action.createObjAttribute(objEntity.getDataMap(), objEntity, attr);
             }
-            focusObjEntity(objEntity);
+            focusObjEntity();
         }
 
         if (dbEntity != null) {
             for (DbAttribute attr : dbAttributes) {
-                action.createDbAttribute(dataMap, dbEntity, attr);
+                action.createDbAttribute(dbEntity.getDataMap(), dbEntity, attr);
             }
+            focusDBEntity();
         }
 
         if (embeddable != null) {
             for (EmbeddableAttribute attr : embeddableAttrs) {
                 action.createEmbAttribute(embeddable, attr);
             }
+            focusEmbeddable();
         }
-
-    }
-
-    private void focusObjEntity(ObjEntity objEntity){
-        actionManager.getAction(DbEntityCounterpartAction.class)
-                .viewCounterpartEntity(objEntity);
     }
 
     @Override
     public String getPresentationName() {
         if (objEntity != null) {
-            return (objAttributes.length > 1)
-                    ? "Remove ObjAttributes"
-                    : "Remove ObjAttribute";
+            return (objAttributes.length > 1) ? "Remove ObjAttributes" : "Remove ObjAttribute";
         }
 
         if (dbEntity != null) {
-            return (dbAttributes.length > 1)
-                    ? "Remove DbAttributes"
-                    : "Remove DbAttribute";
+            return (dbAttributes.length > 1) ? "Remove DbAttributes" : "Remove DbAttribute";
         }
 
         if (embeddableAttrs != null) {
-            return (embeddableAttrs.length > 1)
-                    ? "Remove Embeddable Attributes"
-                    : "Remove Embeddable Attribute";
+            return (embeddableAttrs.length > 1) ? "Remove Embeddable Attributes" : "Remove Embeddable Attribute";
         }
 
         return super.getPresentationName();

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java
index d915f0b..611f55c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/RemoveRelationshipUndoableEdit.java
@@ -26,15 +26,11 @@ import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.modeler.action.CreateRelationshipAction;
-import org.apache.cayenne.modeler.action.DbEntityCounterpartAction;
 import org.apache.cayenne.modeler.action.RemoveRelationshipAction;
 
-public class RemoveRelationshipUndoableEdit extends CayenneUndoableEdit {
+public class RemoveRelationshipUndoableEdit extends BaseRemovePropertyUndoableEdit {
 
-    private ObjEntity objEntity;
     private ObjRelationship[] rels;
-
-    private DbEntity dbEntity;
     private DbRelationship[] dbRels;
 
     public RemoveRelationshipUndoableEdit(ObjEntity objEntity, ObjRelationship[] rels) {
@@ -53,43 +49,36 @@ public class RemoveRelationshipUndoableEdit extends CayenneUndoableEdit {
     public String getPresentationName() {
         if (objEntity != null) {
             return "Remove Obj Relationship";
-        }
-        else {
+        } else {
             return "Remove Db Relationship";
         }
     }
 
     @Override
     public void redo() throws CannotRedoException {
-        RemoveRelationshipAction action = actionManager
-                .getAction(RemoveRelationshipAction.class);
+        RemoveRelationshipAction action = actionManager.getAction(RemoveRelationshipAction.class);
         if (objEntity != null) {
             action.removeObjRelationships(objEntity, rels);
-        }
-        else {
+            focusObjEntity();
+        } else {
             action.removeDbRelationships(dbEntity, dbRels);
+            focusDBEntity();
         }
     }
 
     @Override
     public void undo() throws CannotUndoException {
-        CreateRelationshipAction action = actionManager
-                .getAction(CreateRelationshipAction.class);
+        CreateRelationshipAction action = actionManager.getAction(CreateRelationshipAction.class);
         if (objEntity != null) {
             for (ObjRelationship r : rels) {
                 action.createObjRelationship(objEntity, r);
             }
-            focusObjEntity(objEntity);
-        }
-        else {
+            focusObjEntity();
+        } else {
             for (DbRelationship dr : dbRels) {
                 action.createDbRelationship(dbEntity, dr);
             }
+            focusDBEntity();
         }
     }
-    
-    private void focusObjEntity(ObjEntity objEntity){
-        actionManager.getAction(DbEntityCounterpartAction.class)
-                .viewCounterpartEntity(objEntity);
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/d0b88ba3/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
index 8b294ca..213b5f6 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneAction.java
@@ -31,11 +31,17 @@ import javax.swing.JButton;
 import javax.swing.JCheckBoxMenuItem;
 import javax.swing.JMenuItem;
 import javax.swing.KeyStroke;
+import javax.swing.tree.TreePath;
 
 import org.apache.cayenne.configuration.ConfigurationNode;
+import org.apache.cayenne.configuration.DataChannelDescriptor;
+import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
 import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.ProjectTreeModel;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
+import org.apache.cayenne.modeler.editor.EditorView;
 import org.apache.cayenne.project.Project;
 import org.apache.cayenne.swing.components.image.FilteredIconFactory;
 import org.apache.cayenne.util.Util;
@@ -322,4 +328,42 @@ public abstract class CayenneAction extends AbstractAction {
             }
         }
     }
+    
+    protected static EditorView editor() {
+        return ((CayenneModelerFrame) Application
+                .getInstance()
+                .getFrameController()
+                .getView()).getView();
+    }
+    
+    /**
+     * Builds a tree path for a given entity. Urgent for later selection.
+     * 
+     * @param entity to build path for
+     * @return tree path
+     */
+    protected static TreePath buildTreePath(Entity entity) {
+        DataChannelDescriptor domain = (DataChannelDescriptor) Application
+                .getInstance()
+                .getProject()
+                .getRootNode();
+        
+        Object[] path = new Object[] {domain, entity.getDataMap(), entity};
+
+        Object[] mutableTreeNodes = new Object[path.length];
+        mutableTreeNodes[0] = ((ProjectTreeModel) editor().getProjectTreeView().getModel())
+                .getRootNode();
+
+        Object[] helper;
+        for (int i = 1; i < path.length; i++) {
+            helper = new Object[i];
+            for (int j = 0; j < i;) {
+                helper[j] = path[++j];
+            }
+            mutableTreeNodes[i] = ((ProjectTreeModel) editor()
+                    .getProjectTreeView()
+                    .getModel()).getNodeForObjectPath(helper);
+        }
+        return new TreePath(mutableTreeNodes);
+    }
 }


Mime
View raw message