cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/7] cayenne git commit: CAY-2385 CAY-2386 Fixed visualization issues after an undo action for deleted DbRelationship and DbAttribute
Date Thu, 07 Dec 2017 13:07:07 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master ab6ec9eed -> e0b9ebecc


CAY-2385 CAY-2386 Fixed visualization issues after an undo action for deleted DbRelationship
and DbAttribute


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

Branch: refs/heads/master
Commit: 2d0daeeaf9c4d60b59d6a309a4f2462cb5f084ed
Parents: c2200fc
Author: Emerson Castaneda <emecas@users.noreply.github.com>
Authored: Fri Dec 1 22:39:10 2017 -0500
Committer: Emerson Castaneda <emecas@users.noreply.github.com>
Committed: Tue Dec 5 22:38:53 2017 -0500

----------------------------------------------------------------------
 .../action/ObjEntityCounterpartAction.java      | 58 ++++++++++++++++++++
 .../undo/RemoveAttributeUndoableEdit.java       |  9 ++-
 .../undo/RemoveRelationshipUndoableEdit.java    | 11 +++-
 3 files changed, 73 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d0daeea/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..3feef17 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
@@ -19,8 +19,16 @@
 
 package org.apache.cayenne.modeler.action;
 
+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.modeler.Application;
+import org.apache.cayenne.modeler.CayenneModelerFrame;
+import org.apache.cayenne.modeler.ProjectTreeModel;
+import org.apache.cayenne.modeler.editor.EditorView;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 
 public class ObjEntityCounterpartAction extends BaseViewEntityAction {
 
@@ -40,4 +48,54 @@ public class ObjEntityCounterpartAction extends BaseViewEntityAction {
     protected Entity getEntity() {
         return objEntity.getDbEntity();
     }
+
+    public void viewCounterpartObject(DbEntity entity) {
+        TreePath path = buildTreePath(entity);
+        editor().getProjectTreeView().getSelectionModel().setSelectionPath(path);
+
+        EntityDisplayEvent event = new EntityDisplayEvent(
+                editor().getProjectTreeView(),
+                entity,
+                entity.getDataMap(),
+                (DataChannelDescriptor) getProjectController().getProject().getRootNode());
+        getProjectController().fireDbEntityDisplayEvent(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/2d0daeea/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..5fd13d9 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
@@ -31,6 +31,7 @@ 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.ObjEntityCounterpartAction;
 import org.apache.cayenne.modeler.action.RemoveAttributeAction;
 import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
@@ -122,6 +123,7 @@ public class RemoveAttributeUndoableEdit extends CayenneUndoableEdit {
             for (DbAttribute attr : dbAttributes) {
                 action.createDbAttribute(dataMap, dbEntity, attr);
             }
+            focusDBEntity(dbEntity);
         }
 
         if (embeddable != null) {
@@ -133,8 +135,11 @@ public class RemoveAttributeUndoableEdit extends CayenneUndoableEdit
{
     }
 
     private void focusObjEntity(ObjEntity objEntity){
-        actionManager.getAction(DbEntityCounterpartAction.class)
-                .viewCounterpartEntity(objEntity);
+        actionManager.getAction(DbEntityCounterpartAction.class).viewCounterpartEntity(objEntity);
+    }
+
+    private void focusDBEntity(DbEntity dbEntity){
+        actionManager.getAction(ObjEntityCounterpartAction.class).viewCounterpartObject(dbEntity);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/cayenne/blob/2d0daeea/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..afe9320 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
@@ -27,6 +27,7 @@ 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.ObjEntityCounterpartAction;
 import org.apache.cayenne.modeler.action.RemoveRelationshipAction;
 
 public class RemoveRelationshipUndoableEdit extends CayenneUndoableEdit {
@@ -85,11 +86,15 @@ public class RemoveRelationshipUndoableEdit extends CayenneUndoableEdit
{
             for (DbRelationship dr : dbRels) {
                 action.createDbRelationship(dbEntity, dr);
             }
+            focusDBEntity(dbEntity);
         }
     }
-    
+
     private void focusObjEntity(ObjEntity objEntity){
-        actionManager.getAction(DbEntityCounterpartAction.class)
-                .viewCounterpartEntity(objEntity);
+        actionManager.getAction(DbEntityCounterpartAction.class).viewCounterpartEntity(objEntity);
+    }
+
+    private void focusDBEntity(DbEntity dbEntity){
+        actionManager.getAction(ObjEntityCounterpartAction.class).viewCounterpartObject(dbEntity);
     }
 }


Mime
View raw message