cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ntimof...@apache.org
Subject [1/2] cayenne git commit: CAY-2082 Modeler generates incorrect underscore class with inheritance
Date Wed, 19 Apr 2017 12:00:31 GMT
Repository: cayenne
Updated Branches:
  refs/heads/master 47d0fc5f8 -> 0ac7dd455


CAY-2082 Modeler generates incorrect underscore class with inheritance


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

Branch: refs/heads/master
Commit: 821d730e5f0b738de9f22c4d67fd65468baad68e
Parents: 47d0fc5
Author: Anton Dreka <drekoas@gmail.com>
Authored: Wed Apr 19 14:51:54 2017 +0300
Committer: Anton Dreka <drekoas@gmail.com>
Committed: Wed Apr 19 14:51:54 2017 +0300

----------------------------------------------------------------------
 .../validation/ObjAttributeValidator.java       | 16 ++++++++
 .../modeler/editor/ObjEntityAttributePanel.java | 39 +++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cayenne/blob/821d730e/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjAttributeValidator.java
----------------------------------------------------------------------
diff --git a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjAttributeValidator.java
b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjAttributeValidator.java
index 7f58e32..1cd3d10 100644
--- a/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjAttributeValidator.java
+++ b/cayenne-project/src/main/java/org/apache/cayenne/project/validation/ObjAttributeValidator.java
@@ -50,6 +50,7 @@ class ObjAttributeValidator extends ConfigurationNodeValidator {
         }
 
         checkForDuplicates(attribute, validationResult);
+        checkSuperEntityAttributes(attribute, validationResult);
     }
 
     private void validateName(ObjAttribute attribute, ValidationResult validationResult)
{
@@ -74,6 +75,21 @@ class ObjAttributeValidator extends ConfigurationNodeValidator {
         }
     }
 
+    private void checkSuperEntityAttributes(ObjAttribute attribute, ValidationResult validationResult)
{
+        // Check there is an attribute in entity and super entity at the same time
+
+        boolean selfAttribute = false;
+        if (attribute.getEntity().getDeclaredAttribute(attribute.getName()) != null) {
+            selfAttribute = true;
+        }
+
+        ObjEntity superEntity = attribute.getEntity().getSuperEntity();
+        if (selfAttribute && superEntity != null && superEntity.getAttribute(attribute.getName())
!= null) {
+            addFailure(validationResult, attribute, "'%s' and super '%s' can't have attribute
'%s' together ",
+                    attribute.getEntity().getName(), superEntity.getName(), attribute.getName());
+        }
+    }
+
     private void validateDbAttribute(ObjAttribute attribute, ValidationResult validationResult)
{
         if (attribute.getEntity().isAbstract()) {
             // nothing to validate

http://git-wip-us.apache.org/repos/asf/cayenne/blob/821d730e/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
----------------------------------------------------------------------
diff --git a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
index 7c03193..7601a2c 100644
--- a/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
+++ b/modeler/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributePanel.java
@@ -55,6 +55,8 @@ import javax.swing.BorderFactory;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JComboBox;
+import javax.swing.JDialog;
+import javax.swing.JOptionPane;
 import javax.swing.JMenuItem;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
@@ -74,7 +76,7 @@ import java.awt.event.ActionListener;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Iterator;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
@@ -245,6 +247,9 @@ public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayL
         }
 
         table.select(ind);
+        if (e.getOldName() != null) {
+            removeDuplicateAttribute(e);
+        }
     }
 
     public void objAttributeAdded(AttributeEvent e) {
@@ -290,6 +295,38 @@ public class ObjEntityAttributePanel extends JPanel implements ObjEntityDisplayL
         }
     }
 
+    public void removeDuplicateAttribute(AttributeEvent e) {
+        ObjEntity current = (ObjEntity) e.getEntity();
+        Collection<ObjEntity> objEntities = new ArrayList<>();
+        for (ObjEntity objEntity: e.getEntity().getDataMap().getObjEntities()) {
+            if (objEntity.isSubentityOf(current)) {
+                objEntities.add(objEntity);
+            }
+        }
+
+        for (ObjEntity objEntity: objEntities) {
+            if (objEntity.getDeclaredAttribute(e.getAttribute().getName()) != null) {
+
+                JOptionPane pane = new JOptionPane(
+                        String.format("'%s' and '%s' can't have attribute '%s' together.
" +
+                                        "Would you like to delete this attribute from the
'%s' class?",
+                                objEntity.getName(), e.getEntity().getName(), e.getAttribute().getName(),
objEntity.getName()),
+                        JOptionPane.QUESTION_MESSAGE,
+                        JOptionPane.YES_NO_OPTION);
+
+                JDialog dialog = pane.createDialog(Application.getFrame(), "Confirm Remove");
+                dialog.setVisible(true);
+
+                boolean shouldDelete;
+                Object selectedValue = pane.getValue();
+                shouldDelete = selectedValue != null && selectedValue.equals(JOptionPane.YES_OPTION);
+                if (shouldDelete) {
+                    objEntity.removeAttribute(e.getAttribute().getName());
+                }
+            }
+        }
+    }
+
     public void currentObjEntityChanged(EntityDisplayEvent e) {
         if (e.getSource() == this) {
             return;


Mime
View raw message