cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [7/7] cayenne git commit: CAY-2388 unify Obj and DbEntity actions
Date Thu, 07 Dec 2017 13:07:13 GMT
CAY-2388 unify Obj and DbEntity actions


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

Branch: refs/heads/master
Commit: e0b9ebecc873a17baccba9f0e850dfdaddbdbfec
Parents: c98ec81
Author: Nikita Timofeev <stariy95@gmail.com>
Authored: Thu Dec 7 16:05:13 2017 +0300
Committer: Nikita Timofeev <stariy95@gmail.com>
Committed: Thu Dec 7 16:05:13 2017 +0300

----------------------------------------------------------------------
 .../modeler/action/BaseViewEntityAction.java    | 41 +++++++----------
 .../action/DbEntityCounterpartAction.java       | 47 ++++----------------
 .../action/ObjEntityCounterpartAction.java      | 22 +++------
 .../action/ObjEntityToSuperEntityAction.java    |  7 ++-
 .../undo/BaseRemovePropertyUndoableEdit.java    |  5 +--
 5 files changed, 38 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/e0b9ebec/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/e0b9ebec/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 adb586b..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,20 +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.ProjectController;
-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";
@@ -46,42 +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);
-    }
-    
-    
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e0b9ebec/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 ec04a22..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
@@ -19,13 +19,9 @@
 
 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.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
-import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 
 public class ObjEntityCounterpartAction extends BaseViewEntityAction {
 
@@ -43,19 +39,11 @@ public class ObjEntityCounterpartAction extends BaseViewEntityAction {
 
     @Override
     protected Entity getEntity() {
+        ObjEntity objEntity = getProjectController().getCurrentObjEntity();
+        if (objEntity == null) {
+            return null;
+        }
         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);
-    }
-
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/e0b9ebec/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/e0b9ebec/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
index 69fc0a2..30a9270 100644
--- 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
@@ -23,7 +23,6 @@ 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.DbEntityCounterpartAction;
 import org.apache.cayenne.modeler.action.ObjEntityCounterpartAction;
 import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
 
@@ -37,11 +36,11 @@ public abstract class BaseRemovePropertyUndoableEdit extends CayenneUndoableEdit
     protected Embeddable embeddable;
 
     protected void focusObjEntity(){
-        actionManager.getAction(DbEntityCounterpartAction.class).viewCounterpartEntity(objEntity);
+        actionManager.getAction(ObjEntityCounterpartAction.class).navigateToEntity(objEntity);
     }
 
     protected void focusDBEntity(){
-        actionManager.getAction(ObjEntityCounterpartAction.class).viewCounterpartObject(dbEntity);
+        actionManager.getAction(ObjEntityCounterpartAction.class).navigateToEntity(dbEntity);
     }
 
     protected void focusEmbeddable() {


Mime
View raw message