You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by nt...@apache.org on 2017/12/07 13:07:11 UTC

[5/7] cayenne git commit: CAY-2385 and CAY-2386 cleanup

CAY-2385 and CAY-2386
 cleanup


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

Branch: refs/heads/master
Commit: fe1ee5f7d1d6a542f5795d9e8185dfdb224b13cd
Parents: 2e077dd
Author: Nikita Timofeev <st...@gmail.com>
Authored: Thu Dec 7 15:42:43 2017 +0300
Committer: Nikita Timofeev <st...@gmail.com>
Committed: Thu Dec 7 15:42:43 2017 +0300

----------------------------------------------------------------------
 .../cayenne/modeler/action/RemoveAction.java    |  8 +-
 .../modeler/action/RemoveAttributeAction.java   | 33 ++------
 .../undo/BaseRemovePropertyUndoableEdit.java    | 55 ++++++++++++++
 .../modeler/undo/CayenneUndoableEdit.java       | 11 ---
 .../modeler/undo/DbEntitySyncUndoableEdit.java  | 12 +--
 .../undo/RemoveAttributeUndoableEdit.java       | 80 +++++---------------
 .../undo/RemoveRelationshipUndoableEdit.java    | 26 +++----
 7 files changed, 95 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/fe1ee5f7/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 5c162b5..ce5228c 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
@@ -258,9 +258,7 @@ public class RemoveAction extends CayenneAction {
         		ObjEntity entity = mediator.getCurrentObjEntity();
 
                 application.getUndoManager()
-                        .addEdit(new RemoveAttributeUndoableEdit(
-                                (DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(), entity, objAttrs));
+                        .addEdit(new RemoveAttributeUndoableEdit(entity, objAttrs));
 
                 for (ObjAttribute attrib : objAttrs) {
                     entity.removeAttribute(attrib.getName());
@@ -281,9 +279,7 @@ public class RemoveAction extends CayenneAction {
         		DbEntity entity = mediator.getCurrentDbEntity();
 
                 application.getUndoManager()
-                        .addEdit(new RemoveAttributeUndoableEdit(
-                                (DataChannelDescriptor)mediator.getProject().getRootNode(),
-                                mediator.getCurrentDataMap(), entity, dbAttrs));
+                        .addEdit(new RemoveAttributeUndoableEdit(entity, dbAttrs));
 
                 for (DbAttribute attrib : dbAttrs) {
                     entity.removeAttribute(attrib.getName());

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fe1ee5f7/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/fe1ee5f7/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..69fc0a2
--- /dev/null
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/undo/BaseRemovePropertyUndoableEdit.java
@@ -0,0 +1,55 @@
+/*****************************************************************
+ *   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.DbEntityCounterpartAction;
+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(DbEntityCounterpartAction.class).viewCounterpartEntity(objEntity);
+    }
+
+    protected void focusDBEntity(){
+        actionManager.getAction(ObjEntityCounterpartAction.class).viewCounterpartObject(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/fe1ee5f7/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 86baee4..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
@@ -20,13 +20,9 @@ package org.apache.cayenne.modeler.undo;
 
 import javax.swing.undo.AbstractUndoableEdit;
 
-import org.apache.cayenne.map.DbEntity;
-import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.action.ActionManager;
-import org.apache.cayenne.modeler.action.DbEntityCounterpartAction;
-import org.apache.cayenne.modeler.action.ObjEntityCounterpartAction;
 
 public abstract class CayenneUndoableEdit extends AbstractUndoableEdit {
     
@@ -47,12 +43,5 @@ public abstract class CayenneUndoableEdit extends AbstractUndoableEdit {
     public boolean canUndo() {
         return true;
     }
-    
-    protected void focusObjEntity(ObjEntity objEntity){
-        actionManager.getAction(DbEntityCounterpartAction.class).viewCounterpartEntity(objEntity);
-    }
 
-    protected void focusDBEntity(DbEntity dbEntity){
-        actionManager.getAction(ObjEntityCounterpartAction.class).viewCounterpartObject(dbEntity);
-    }
 }

http://git-wip-us.apache.org/repos/asf/cayenne/blob/fe1ee5f7/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/fe1ee5f7/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 3d85beb..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;
@@ -31,125 +29,87 @@ 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.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(dbEntity);
+            focusDBEntity();
         }
 
         if (embeddable != null) {
             for (EmbeddableAttribute attr : embeddableAttrs) {
                 action.createEmbAttribute(embeddable, attr);
             }
+            focusEmbeddable();
         }
-
     }
 
     @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/fe1ee5f7/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 c0d59a0..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
@@ -28,12 +28,9 @@ import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.modeler.action.CreateRelationshipAction;
 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) {
@@ -52,39 +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(dbEntity);
+            focusDBEntity();
         }
     }
 }