cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r823096 [1/2] - in /cayenne/main/trunk/framework: cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ cayenne-modeler/.settings/ cayenne-modeler/src/main/java...
Date Thu, 08 Oct 2009 09:04:52 GMT
Author: aadamchik
Date: Thu Oct  8 09:04:49 2009
New Revision: 823096

URL: http://svn.apache.org/viewvc?rev=823096&view=rev
Log:
CAY-1260 Modeler support for embeddables and embedded attributes

patch Inspector1_5.txt by Olga Tkachova

Added:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/OverrideEmbeddableAttributeTableModel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CellEditorForAttributeTable.java
Modified:
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Embeddable.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/NamedObjectFactory.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ProjectTraversal.java
    cayenne/main/trunk/framework/cayenne-modeler/.settings/org.eclipse.jdt.core.prefs
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTableModel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableTab.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/Comparators.java

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/DataMap.java Thu Oct  8 09:04:49 2009
@@ -578,6 +578,7 @@
         }
 
         embeddablesMap.put(embeddable.getClassName(), embeddable);
+        embeddable.setDataMap(this);
     }
 
     /**

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Embeddable.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Embeddable.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Embeddable.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/Embeddable.java Thu Oct  8 09:04:49 2009
@@ -41,6 +41,7 @@
 
     protected String className;
     protected SortedMap<String, EmbeddableAttribute> attributes;
+    protected DataMap dataMap;
 
     public Embeddable() {
         this(null);
@@ -51,6 +52,16 @@
         this.className = className;
     }
 
+    
+    public DataMap getDataMap() {
+        return dataMap;
+    }
+
+    
+    public void setDataMap(DataMap dataMap) {
+        this.dataMap = dataMap;
+    }
+
     /**
      * Returns Java class of the embeddable.
      */

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/map/EmbeddedAttribute.java Thu Oct  8 09:04:49 2009
@@ -36,7 +36,6 @@
  */
 public class EmbeddedAttribute extends ObjAttribute {
 
-    protected String type;
     protected SortedMap<String, String> attributeOverrides;
 
     public EmbeddedAttribute() {

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/NamedObjectFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/NamedObjectFactory.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/NamedObjectFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/NamedObjectFactory.java Thu Oct  8 09:04:49 2009
@@ -252,19 +252,44 @@
     }
 
     static class EmbeddableFactory extends NamedObjectFactory {
+        
+        private String nameBase;
+        
+        
+        public String getNameBase() {
+            return nameBase;
+        }
+
+        
+        public void setNameBase(String nameBase) {
+            this.nameBase = nameBase;
+        }
+
         @Override
         protected String nameBase() {
-            return "Package.UntitledObjEntity";
+            System.out.println("nameBase");
+            if(getNameBase()==null){
+                setNameBase("UntitledEmbeddable");
+            }
+            return getNameBase();
+           
         }
 
         @Override
         protected Object create(String name, Object namingContext) {
+            DataMap map = (DataMap) namingContext;
+            if(map.getDefaultPackage() != null){
+                return new Embeddable(map.getDefaultPackage() + "." + name);
+            }
             return new Embeddable(name);
         }
 
         @Override
         protected boolean isNameInUse(String name, Object namingContext) {
             DataMap map = (DataMap) namingContext;
+            if(map.getDefaultPackage() != null){
+                return map.getEmbeddable((map.getDefaultPackage() + "." + name)) != null;
+            }
             return map.getEmbeddable(name) != null;
         }
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ProjectTraversal.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ProjectTraversal.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ProjectTraversal.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/project/ProjectTraversal.java Thu Oct  8 09:04:49 2009
@@ -91,6 +91,9 @@
         else if (rootNode instanceof Entity) {
             this.traverseEntities(Collections.singletonList(rootNode).iterator(), path);
         }
+        else if (rootNode instanceof Embeddable) {
+            this.traverseEmbeddable(Collections.singletonList(rootNode).iterator(), path);
+        }
         else if (rootNode instanceof Attribute) {
             this.traverseAttributes(Collections.singletonList(rootNode).iterator(), path);
         }
@@ -102,9 +105,6 @@
         else if (rootNode instanceof DataNode) {
             this.traverseNodes(Collections.singletonList(rootNode).iterator(), path);
         }
-        else if (rootNode instanceof Embeddable) {
-            this.traverseEmbeddable(Collections.singletonList(rootNode).iterator(), path);
-        }
         else {
             String nodeClass = (rootNode != null)
                     ? rootNode.getClass().getName()
@@ -177,8 +177,8 @@
 
             if (handler.shouldReadChildren(map, path)) {
                 this.traverseEntities(map.getObjEntities().iterator(), mapPath);
-                this.traverseEntities(map.getDbEntities().iterator(), mapPath);
                 this.traverseEmbeddable(map.getEmbeddables().iterator(), mapPath);
+                this.traverseEntities(map.getDbEntities().iterator(), mapPath);                
                 this.traverseProcedures(map.getProcedures().iterator(), mapPath);
                 this.traverseQueries(map.getQueries().iterator(), mapPath);
             }

Modified: cayenne/main/trunk/framework/cayenne-modeler/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/.settings/org.eclipse.jdt.core.prefs?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/.settings/org.eclipse.jdt.core.prefs (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/.settings/org.eclipse.jdt.core.prefs Thu Oct  8 09:04:49 2009
@@ -1,15 +1,5 @@
-#Fri Nov 16 16:54:33 EST 2007
+#Wed Oct 07 15:54:03 EEST 2009
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
-org.eclipse.jdt.core.compiler.compliance=1.5
-org.eclipse.jdt.core.compiler.debug.lineNumber=generate
-org.eclipse.jdt.core.compiler.debug.localVariable=generate
-org.eclipse.jdt.core.compiler.debug.sourceFile=generate
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
 org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=48
 org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/CayenneModelerFrame.java Thu Oct  8 09:04:49 2009
@@ -222,9 +222,8 @@
         projectMenu.add(getAction(CreateDataMapAction.getActionName()).buildMenu());
 
         projectMenu.add(getAction(CreateObjEntityAction.getActionName()).buildMenu());
-        projectMenu.add(getAction(CreateDbEntityAction.getActionName()).buildMenu());
-
         projectMenu.add(getAction(CreateEmbeddableAction.getActionName()).buildMenu());
+        projectMenu.add(getAction(CreateDbEntityAction.getActionName()).buildMenu());
         
         projectMenu.add(getAction(CreateProcedureAction.getActionName()).buildMenu());
         projectMenu.add(getAction(CreateQueryAction.getActionName()).buildMenu());
@@ -390,9 +389,7 @@
 
         
         toolBar.add(getAction(CreateObjEntityAction.getActionName()).buildButton());
-      
         toolBar.add(getAction(CreateEmbeddableAction.getActionName()).buildButton());
-
         toolBar.add(getAction(CreateQueryAction.getActionName()).buildButton());
  
         toolBar.addSeparator();

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/ProjectTreeView.java Thu Oct  8 09:04:49 2009
@@ -925,8 +925,9 @@
         popup.add(buildMenu(CreateDataMapAction.getActionName()));
 
         popup.add(buildMenu(CreateObjEntityAction.getActionName()));
-        popup.add(buildMenu(CreateDbEntityAction.getActionName()));
         popup.add(buildMenu(CreateEmbeddableAction.getActionName()));
+        popup.add(buildMenu(CreateDbEntityAction.getActionName()));
+  
         popup.add(buildMenu(CreateProcedureAction.getActionName()));
         popup.add(buildMenu(CreateQueryAction.getActionName()));
         popup.addSeparator();

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/FindAction.java Thu Oct  8 09:04:49 2009
@@ -29,6 +29,8 @@
 
 import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.EmbeddableAttribute;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.Relationship;
@@ -36,6 +38,7 @@
 import org.apache.cayenne.modeler.dialog.FindDialog;
 import org.apache.cayenne.modeler.util.CayenneAction;
 import org.apache.cayenne.project.ProjectPath;
+import org.apache.cayenne.query.Query;
 
 public class FindAction extends CayenneAction {
     private java.util.List<Object> paths;
@@ -70,6 +73,12 @@
                     paths.add(path.getPath());
                 else if (o instanceof Relationship && matchFound(((Relationship) o).getName(), pattern))
                     paths.add(path.getPath());
+                else if (o instanceof Query && matchFound(((Query) o).getName(), pattern))
+                    paths.add(path.getPath());
+                else if (o instanceof Embeddable && matchFound(((Embeddable) o).getClassName(), pattern))
+                    paths.add(path.getPath());
+                else if (o instanceof EmbeddableAttribute && matchFound(((EmbeddableAttribute) o).getName(), pattern))
+                    paths.add(path.getPath());
             }
         }
      

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialog.java Thu Oct  8 09:04:49 2009
@@ -42,6 +42,8 @@
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.EmbeddableAttribute;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
@@ -52,9 +54,13 @@
 import org.apache.cayenne.modeler.ProjectTreeModel;
 import org.apache.cayenne.modeler.editor.EditorView;
 import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
+import org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent;
+import org.apache.cayenne.modeler.event.EmbeddableDisplayEvent;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
+import org.apache.cayenne.modeler.event.QueryDisplayEvent;
 import org.apache.cayenne.modeler.event.RelationshipDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.query.Query;
 
 /**
  * An instance of this class is responsible for displaying search results and navigating
@@ -80,7 +86,7 @@
 
         this.paths = paths;
 
-        Map objEntityNames = new HashMap(), dbEntityNames = new HashMap(), attrNames = new HashMap(), relatNames = new HashMap();
+        Map objEntityNames = new HashMap(), dbEntityNames = new HashMap(), attrNames = new HashMap(), relatNames = new HashMap(), queryNames = new HashMap(), embeddableNames = new HashMap(), embeddableAttributeNames = new HashMap();
         Iterator it = paths.iterator();
         int index = 0;
         while (it.hasNext()) {
@@ -98,6 +104,27 @@
                         ((DbEntity) path[path.length - 1]).getName());
             }
 
+            if (path[path.length - 1] instanceof Query) {
+                queryNames.put(new Integer(index++), ((Query) path[path.length - 1])
+                        .getName());
+            }
+
+            if (path[path.length - 1] instanceof Embeddable) {
+                
+                String name = ((Embeddable) path[path.length - 1]).getClassName();
+                embeddableNames.put(
+                        new Integer(index++),
+                        name);
+            }
+            
+            if (path[path.length - 1] instanceof EmbeddableAttribute) {
+                
+                Object parentObject = ((EmbeddableAttribute) path[path.length - 1]).getEmbeddable();
+                String parName = getParentName(path, parentObject);
+                embeddableAttributeNames.put(new Integer(index++), parName
+                        + "."
+                        + ((EmbeddableAttribute) path[path.length - 1]).getName());
+            }
             if (path[path.length - 1] instanceof Attribute) {
                 Object parentObject = ((Attribute) path[path.length - 1]).getParent();
                 attrNames.put(new Integer(index++), getParentName(path, parentObject)
@@ -124,7 +151,14 @@
             }
         }
 
-        view = new FindDialogView(objEntityNames, dbEntityNames, attrNames, relatNames);
+        view = new FindDialogView(
+                objEntityNames,
+                dbEntityNames,
+                attrNames,
+                relatNames,
+                queryNames,
+                embeddableNames,
+                embeddableAttributeNames);
         initBindings();
     }
 
@@ -184,7 +218,56 @@
             if (path[path.length - 1] instanceof DbEntity)
                 editor.getDbDetailView().currentDbEntityChanged(event);
         }
+        
+        if (path[path.length - 1] instanceof Query) {
+
+            /** Make selection in a project tree, open correspondent entity tab */
+            editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                    buildTreePath(path, editor));
+            QueryDisplayEvent event = new QueryDisplayEvent(
+                    editor.getProjectTreeView(),
+                    (Query) path[path.length - 1],
+                    (DataMap) path[path.length - 2],
+                    (DataDomain) path[path.length - 3]);
+
+            editor.currentQueryChanged(event);
+        }
+        
+        if (path[path.length - 1] instanceof Embeddable) {
+
+            /** Make selection in a project tree, open correspondent entity tab */
+            editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                    buildTreePath(path, editor));
+            EmbeddableDisplayEvent event = new EmbeddableDisplayEvent(
+                    editor.getProjectTreeView(),
+                    (Embeddable) path[path.length - 1],
+                    (DataMap) path[path.length - 2],
+                    (DataDomain) path[path.length - 3]);
+            event.setMainTabFocus(true);
+
+            editor.currentEmbeddableChanged(event);
+        }
+        
+        if (path[path.length - 1] instanceof EmbeddableAttribute) {
 
+            /** Make selection in a project tree, open correspondent embeddable tab */
+            Object[] o = new Object[path.length - 1];
+            for (int i = 0; i < path.length - 1; i++)
+                o[i] = path[i];
+            editor.getProjectTreeView().getSelectionModel().setSelectionPath(
+                    buildTreePath(o, editor));
+            
+            EmbeddableAttributeDisplayEvent event = new EmbeddableAttributeDisplayEvent(
+                    editor.getProjectTreeView(),
+                    (Embeddable) path[path.length - 2],
+                    (EmbeddableAttribute) path[path.length - 1],
+                    (DataMap) path[path.length - 3],
+                    (DataDomain) path[path.length - 4]);
+            event.setMainTabFocus(true);
+
+            editor.getEmbeddableView().currentEmbeddableAttributeChanged(event);
+        }
+        
         if (path[path.length - 1] instanceof Attribute
                 || path[path.length - 1] instanceof Relationship) {
 
@@ -239,6 +322,7 @@
             event.setMainTabFocus(true);
             editor.getObjDetailView().currentObjRelationshipChanged(event);
         }
+
     }
 
     private class JumpToResultActionListener implements MouseListener {
@@ -325,6 +409,10 @@
             DbEntity dbEntity = (DbEntity) parentObject;
             nameParent = dbEntity.getName();
         }
+        if (parentObject instanceof Embeddable) {
+            Embeddable embeddable = (Embeddable) parentObject;
+            nameParent = embeddable.getClassName();
+        }
         return nameParent;
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/FindDialogView.java Thu Oct  8 09:04:49 2009
@@ -49,10 +49,13 @@
 import javax.swing.table.DefaultTableCellRenderer;
 
 import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.ObjRelationship;
 import org.apache.cayenne.modeler.util.CellRenderers;
+import org.apache.cayenne.query.SelectQuery;
+
 
 /**
  * Swing component displaying results produced by search feature.
@@ -73,7 +76,7 @@
     }
 
     public FindDialogView(Map objEntityNames, Map dbEntityNames, Map attrNames,
-            Map relatNames) {
+            Map relatNames, Map queryNames, Map embeddableNames, Map embeddableAttributeNames) {
 
         JPanel panel = new JPanel();
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
@@ -81,7 +84,10 @@
         if (objEntityNames.isEmpty()
                 && dbEntityNames.isEmpty()
                 && attrNames.isEmpty()
-                && relatNames.isEmpty()) {
+                && relatNames.isEmpty()
+                && queryNames.isEmpty()
+                && embeddableNames.isEmpty()
+                && embeddableAttributeNames.isEmpty()) {
             panel.add(new JLabel("Nothing found!"));
         }
         else {
@@ -90,7 +96,10 @@
             int sizeDataVector = objEntityNames.size()
                     + dbEntityNames.size()
                     + attrNames.size()
-                    + relatNames.size();
+                    + relatNames.size()
+                    + queryNames.size()
+                    + embeddableNames.size()
+                    + embeddableAttributeNames.size();
 
             Object[][] dataVector = new Object[sizeDataVector][];
 
@@ -100,18 +109,31 @@
 
             dataVector = createResultTable(objEntityNames, CellRenderers
                     .iconForObject(new ObjEntity()), dataVector, curentLineInTable);
-            curentLineInTable = objEntityNames.size();
+            
+            curentLineInTable = objEntityNames.size();            
+            dataVector = createResultTable(embeddableNames, CellRenderers
+                    .iconForObject(new Embeddable()), dataVector, curentLineInTable);
+
+            curentLineInTable = curentLineInTable + embeddableNames.size();            
             dataVector = createResultTable(dbEntityNames, CellRenderers
                     .iconForObject(new DbEntity()), dataVector, curentLineInTable);
-
-            curentLineInTable = curentLineInTable + dbEntityNames.size();
+            
+            curentLineInTable = curentLineInTable + dbEntityNames.size();            
             dataVector = createResultTable(attrNames, CellRenderers
                     .iconForObject(new ObjAttribute()), dataVector, curentLineInTable);
+            
+            curentLineInTable = curentLineInTable + attrNames.size();         
+            dataVector = createResultTable(embeddableAttributeNames, CellRenderers
+                    .iconForObject(new ObjAttribute()), dataVector, curentLineInTable);
 
-            curentLineInTable = curentLineInTable + attrNames.size();
+            curentLineInTable = curentLineInTable + embeddableAttributeNames.size();
             dataVector = createResultTable(relatNames, CellRenderers
                     .iconForObject(new ObjRelationship()), dataVector, curentLineInTable);
-
+            
+            curentLineInTable = curentLineInTable + relatNames.size();
+            dataVector = createResultTable(queryNames, CellRenderers
+                    .iconForObject(new SelectQuery()), dataVector, curentLineInTable);
+            
             tableModel.setDataVector(dataVector, new Object[] {
                 ""
             });

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialog.java Thu Oct  8 09:04:49 2009
@@ -18,34 +18,55 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.dialog.objentity;
 
+import java.awt.Color;
 import java.awt.Component;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyEvent;
+import java.awt.event.KeyListener;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Vector;
 
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JOptionPane;
+import javax.swing.JTable;
 import javax.swing.WindowConstants;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
+import javax.swing.table.DefaultTableCellRenderer;
+import javax.swing.table.TableColumn;
 import javax.swing.tree.TreePath;
 
 import org.apache.cayenne.map.Attribute;
 import org.apache.cayenne.map.DbAttribute;
 import org.apache.cayenne.map.DbEntity;
 import org.apache.cayenne.map.DbRelationship;
+import org.apache.cayenne.map.Embeddable;
+import org.apache.cayenne.map.EmbeddableAttribute;
+import org.apache.cayenne.map.EmbeddedAttribute;
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.Relationship;
+import org.apache.cayenne.map.event.AttributeEvent;
+import org.apache.cayenne.map.event.EntityEvent;
+import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.editor.ObjAttributeTableModel;
+import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
+import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.util.CayenneController;
 import org.apache.cayenne.modeler.util.Comparators;
 import org.apache.cayenne.modeler.util.EntityTreeFilter;
 import org.apache.cayenne.modeler.util.EntityTreeModel;
+import org.apache.cayenne.modeler.util.ModelerUtil;
+import org.apache.cayenne.project.ProjectPath;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.util.CayenneMapEntry;
 
@@ -53,29 +74,44 @@
         TreeSelectionListener {
 
     private ObjAttributeTableModel model;
+    private OverrideEmbeddableAttributeTableModel embeddableModel;
     private int row;
     protected ObjAttributeInfoDialogView view;
     protected ObjAttribute attribute;
     protected ObjAttribute attributeSaved;
 
-    protected List attributesList;
-    protected List attributesSavedList;
-
     protected List<DbEntity> relTargets;
 
     protected ObjEntity objectTarget;
     protected List<ObjEntity> objectTargets;
 
-    protected List<String> mapKeys;
+    protected Map<String, Embeddable> stringToEmbeddables;
+    protected List<String> embeddableNames;
+
     protected ProjectController mediator;
+    private Object lastObjectType;
 
     public ObjAttributeInfoDialog(ProjectController mediator, int row,
             ObjAttributeTableModel model) {
         super(mediator);
-        this.view = new ObjAttributeInfoDialogView();
+        this.view = new ObjAttributeInfoDialogView(mediator);
         this.mediator = mediator;
         this.model = model;
         this.row = row;
+        this.stringToEmbeddables = new HashMap<String, Embeddable>();
+        this.embeddableNames = new ArrayList<String>();
+        Iterator it = mediator.getProject().treeNodes();
+        while (it.hasNext()) {
+            ProjectPath path = (ProjectPath) it.next();
+            Object o = path.getObject();
+            Object[] p = path.getPath();
+            if (o instanceof Embeddable) {
+                Embeddable emb = (Embeddable) p[p.length - 1];
+                stringToEmbeddables.put(emb.getClassName(), emb);
+                embeddableNames.add(emb.getClassName());
+            }
+        }
+
         initController(model.getAttribute(row));
     }
 
@@ -98,14 +134,24 @@
     }
 
     private void initController(ObjAttribute attr) {
+
+        for (int i = 0; i < embeddableNames.size(); i++) {
+            ((DefaultComboBoxModel) view.getType().getModel()).addElement(embeddableNames
+                    .get(i)
+                    .toString());
+        }
+
         this.attribute = attr;
-        this.attributeSaved = new ObjAttribute();
-        attributeSaved.setDbAttributePath(attribute.getDbAttributePath());
-        attributeSaved.setName(attribute.getName());
-        attributeSaved.setEntity(attribute.getEntity());
-        attributeSaved.setParent(attribute.getParent());
-        attributeSaved.setType(attribute.getType());
-        attributeSaved.setUsedForLocking(attribute.isUsedForLocking());
+
+        if (attribute instanceof EmbeddedAttribute
+                || embeddableNames.contains(attribute.getType())) {
+            this.attributeSaved = new EmbeddedAttribute();
+        }
+        else {
+            this.attributeSaved = new ObjAttribute();
+        }
+
+        copyObjAttribute(attributeSaved, attribute);
 
         relTargets = new ArrayList<DbEntity>(attribute
                 .getEntity()
@@ -135,6 +181,9 @@
             view.getCurrentPathLabel().setText("");
         }
         view.getSourceEntityLabel().setText(attribute.getEntity().getName());
+
+        view.getType().setSelectedItem(attribute.getType());
+
         BindingBuilder builder = new BindingBuilder(
                 getApplication().getBindingFactory(),
                 this);
@@ -149,20 +198,21 @@
             Entity firstEntity = null;
             if (attribute.getDbAttribute() == null) {
 
-                Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
                 if (attribute.getParent() instanceof ObjEntity) {
                     DbEntity dbEnt = ((ObjEntity) attribute.getParent()).getDbEntity();
 
-                    Collection<DbAttribute> attrib = dbEnt.getAttributes();
-                    Collection<DbRelationship> rel = dbEnt.getRelationships();
-
-                    if (attrib.size() > 0) {
-                        Iterator<DbAttribute> iter = attrib.iterator();
-                        firstEntity = iter.next().getEntity();
-                    }
-                    else if (rel.size() > 0) {
-                        Iterator<DbRelationship> iter = rel.iterator();
-                        firstEntity = iter.next().getSourceEntity();
+                    if (dbEnt != null) {
+                        Collection<DbAttribute> attrib = dbEnt.getAttributes();
+                        Collection<DbRelationship> rel = dbEnt.getRelationships();
+
+                        if (attrib.size() > 0) {
+                            Iterator<DbAttribute> iter = attrib.iterator();
+                            firstEntity = iter.next().getEntity();
+                        }
+                        else if (rel.size() > 0) {
+                            Iterator<DbRelationship> iter = rel.iterator();
+                            firstEntity = iter.next().getSourceEntity();
+                        }
                     }
                 }
             }
@@ -194,13 +244,179 @@
                     }
                 });
                 view.getPathBrowser().setModel(treeModel);
-
             }
         }
 
         if (attribute.getDbAttribute() != null) {
             setSelectionPath();
         }
+
+        view.getType().addItemListener(new ItemListener() {
+
+            public void itemStateChanged(ItemEvent e) {
+                if (lastObjectType != null) {
+                    if (!lastObjectType.equals(e.getItemSelectable())) {
+
+                        if (embeddableNames.contains(e
+                                .getItemSelectable()
+                                .getSelectedObjects()[0].toString())) {
+                            if (attributeSaved instanceof ObjAttribute) {
+                                EmbeddedAttribute copyAttrSaved = new EmbeddedAttribute();
+                                copyObjAttribute(copyAttrSaved, attributeSaved);
+                                attributeSaved = copyAttrSaved;
+                            }
+                        }
+                        else {
+                            if (attributeSaved instanceof EmbeddedAttribute) {
+                                ObjAttribute copyAttrSaved = new ObjAttribute();
+                                copyObjAttribute(copyAttrSaved, attributeSaved);
+                                attributeSaved = copyAttrSaved;
+                            }
+                        }
+
+                        attributeSaved
+                                .setType(e.getItemSelectable().getSelectedObjects()[0]
+                                        .toString());
+                        rebuildTable();
+                        setEnabledSaveButton();
+                    }
+                }
+            }
+        });
+
+        view.getAttributeName().addKeyListener(new KeyListener() {
+
+            public void keyPressed(KeyEvent e) {
+                if (!view.getAttributeName().getText().equals(attribute.getName())) {
+                    setEnabledSaveButton();
+                }
+            }
+
+            public void keyReleased(KeyEvent e) {
+                if (!view.getAttributeName().getText().equals(attribute.getName())) {
+                    setEnabledSaveButton();
+                }
+            }
+
+            public void keyTyped(KeyEvent e) {
+            }
+        });
+
+        rebuildTable();
+
+    }
+
+    private void setEnabledSaveButton() {
+        if (!attribute.getDbPathIterator().hasNext()) {
+            view.getSaveButton().setEnabled(true);
+        }
+        else {
+            boolean isAttributeLast = false;
+            Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
+            while (it.hasNext()) {
+                Object obj = it.next();
+                if (obj instanceof DbAttribute && !it.hasNext()) {
+                    isAttributeLast = true;
+                }
+            }
+            view.getSaveButton().setEnabled(isAttributeLast);
+        }
+    }
+
+    private void setUpTableStructure() {
+
+        DefaultTableCellRenderer renderer = new CellRenderer();
+
+        TableColumn nameColumn = view
+                .getOverrideAttributeTable()
+                .getColumnModel()
+                .getColumn(OverrideEmbeddableAttributeTableModel.OBJ_ATTRIBUTE);
+        nameColumn.setMinWidth(180);
+        nameColumn.setCellRenderer(renderer);
+
+        TableColumn typeColumn = view
+                .getOverrideAttributeTable()
+                .getColumnModel()
+                .getColumn(OverrideEmbeddableAttributeTableModel.OBJ_ATTRIBUTE_TYPE);
+        typeColumn.setMinWidth(200);
+        typeColumn.setCellRenderer(renderer);
+
+        TableColumn dbAttrColumn = view
+                .getOverrideAttributeTable()
+                .getColumnModel()
+                .getColumn(OverrideEmbeddableAttributeTableModel.DB_ATTRIBUTE);
+        dbAttrColumn.setMinWidth(180);
+        dbAttrColumn.setCellRenderer(renderer);
+
+        TableColumn dbAttrTypeColumn = view
+                .getOverrideAttributeTable()
+                .getColumnModel()
+                .getColumn(OverrideEmbeddableAttributeTableModel.DB_ATTRIBUTE_TYPE);
+        dbAttrTypeColumn.setMinWidth(180);
+        dbAttrTypeColumn.setCellRenderer(renderer);
+
+        initComboBoxes();
+
+    }
+
+    private void initComboBoxes() {
+        Collection<String> nameAttr = null;
+        if (attributeSaved != null) {
+            DbEntity currentEnt = ((ObjEntity) attributeSaved.getEntity()).getDbEntity();
+
+            if (currentEnt != null) {
+                nameAttr = ModelerUtil.getDbAttributeNames(mediator, currentEnt);
+                embeddableModel.setCellEditor(nameAttr, view.getOverrideAttributeTable());
+                embeddableModel.setComboBoxes(
+                        nameAttr,
+                        OverrideEmbeddableAttributeTableModel.DB_ATTRIBUTE);
+            }
+        }
+    }
+
+    private void rebuildTable() {
+        String typeName = null;
+
+        Collection<EmbeddableAttribute> embAttrTempCopy = new ArrayList<EmbeddableAttribute>();
+
+        if (attributeSaved.getType() != null) {
+            typeName = attributeSaved.getType().toString();
+        }
+        if (embeddableNames.contains(typeName)) {
+
+            Collection<EmbeddableAttribute> embAttrTemp = ((Embeddable) stringToEmbeddables
+                    .get(typeName)).getAttributes();
+            Iterator<EmbeddableAttribute> it = embAttrTemp.iterator();
+
+            while (it.hasNext()) {
+                EmbeddableAttribute temp = (EmbeddableAttribute) it.next();
+                EmbeddableAttribute at = new EmbeddableAttribute();
+                at.setDbAttributeName(temp.getDbAttributeName());
+                at.setName(temp.getName());
+                at.setType(temp.getType());
+                at.setEmbeddable(temp.getEmbeddable());
+                embAttrTempCopy.add(at);
+            }
+        }
+
+        embeddableModel = new OverrideEmbeddableAttributeTableModel(
+                mediator,
+                this,
+                embAttrTempCopy,
+                attributeSaved);
+
+        view.getOverrideAttributeTable().setModel(embeddableModel);
+        view.getOverrideAttributeTable().setRowHeight(25);
+        view.getOverrideAttributeTable().setRowMargin(3);
+
+        setUpTableStructure();
+
+        if (view.getType().getSelectedItem() == null) {
+            lastObjectType = "";
+        }
+        else {
+            lastObjectType = view.getType().getSelectedItem();
+        }
     }
 
     public void closeAction() {
@@ -210,27 +426,30 @@
     public boolean setPath(boolean isChange) {
         StringBuilder attributePath = new StringBuilder();
         StringBuilder pathStr = new StringBuilder();
-        TreePath path = view.getPathBrowser().getSelectionPath();
+        if (((ObjEntity) attribute.getEntity()).getDbEntity() != null) {
+            TreePath path = view.getPathBrowser().getSelectionPath();
 
-        if (path.getLastPathComponent() instanceof DbAttribute) {
-            Object[] pathComponents = path.getPath();
-            for (int i = 0; i < pathComponents.length; i++) {
-                boolean attrOrRel = true;
-                if (pathComponents[i] instanceof DbAttribute) {
-                    pathStr.append(((DbAttribute) pathComponents[i]).getName());
-                    attributePath.append(((DbAttribute) pathComponents[i]).getName());
-                }
-                else if (pathComponents[i] instanceof DbRelationship) {
-                    pathStr.append(((DbRelationship) pathComponents[i]).getName());
-                    attributePath.append(((DbRelationship) pathComponents[i]).getName());
-                }
-                else {
-                    attrOrRel = false;
-                }
+            if (path.getLastPathComponent() instanceof DbAttribute) {
+                Object[] pathComponents = path.getPath();
+                for (int i = 0; i < pathComponents.length; i++) {
+                    boolean attrOrRel = true;
+                    if (pathComponents[i] instanceof DbAttribute) {
+                        pathStr.append(((DbAttribute) pathComponents[i]).getName());
+                        attributePath.append(((DbAttribute) pathComponents[i]).getName());
+                    }
+                    else if (pathComponents[i] instanceof DbRelationship) {
+                        pathStr.append(((DbRelationship) pathComponents[i]).getName());
+                        attributePath.append(((DbRelationship) pathComponents[i])
+                                .getName());
+                    }
+                    else {
+                        attrOrRel = false;
+                    }
 
-                if (i != pathComponents.length - 1 && attrOrRel) {
-                    pathStr.append(" -> ");
-                    attributePath.append(".");
+                    if (i != pathComponents.length - 1 && attrOrRel) {
+                        pathStr.append(" -> ");
+                        attributePath.append(".");
+                    }
                 }
             }
         }
@@ -240,21 +459,51 @@
 
         view.getCurrentPathLabel().setText(pathStr.toString());
 
-        if (attribute.getDbAttributePath() != null) {
+        if (attribute.getDbAttributePath() != null
+                && !embeddableNames.contains(view.getType().getSelectedItem().toString())) {
             if (!attribute.getDbAttributePath().equals(attributePath.toString())
-                    || !attribute.getName().equals(view.getAttributeName().getText())) {
-                attributeSaved.setDbAttributePath(attributePath.toString());
+                    || isChange()) {
+
+                if (isRegistredType(attributeSaved.getType())) {
+                    attributeSaved.setDbAttributePath(attributePath.toString());
+                }
+                else {
+                    attributeSaved.setDbAttributePath("");
+                }
                 attributeSaved.setName(view.getAttributeName().getText());
-                if (!attribute.getDbAttributePath().equals(attributePath.toString()) && isChange) {
+                attributeSaved.setType(view.getType().getSelectedItem().toString());
+
+                if (!attribute.getDbAttributePath().equals(attributePath.toString())
+                        && isChange) {
                     model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
                 }
+
                 return true;
             }
         }
         else {
-            if (attributePath.length() > 0
-                    || !attribute.getName().equals(view.getAttributeName().getText())) {
-                attributeSaved.setDbAttributePath(attributePath.toString());
+            if (attributePath.length() > 0 || isChange()) {
+                if (isRegistredType(attributeSaved.getType())) {
+                    attributeSaved.setDbAttributePath(attributePath.toString());
+                }
+                else {
+                    attributeSaved.setDbAttributePath("");
+
+                    if (attributeSaved instanceof EmbeddedAttribute) {
+
+                        if (embeddableModel.isAttributeOverrideChange()) {
+                            Map<String, String> overrides = ((EmbeddedAttribute) attributeSaved)
+                                    .getAttributeOverrides();
+                            Map<String, String> currentOverrAttr = getCurrentOverrideAttribute();
+                            compareAndSetOverrideInEmbeddedAttribute(
+                                    attributeSaved,
+                                    overrides,
+                                    currentOverrAttr);
+                        }
+                    }
+
+                }
+                attributeSaved.setType(view.getType().getSelectedItem().toString());
                 attributeSaved.setName(view.getAttributeName().getText());
                 if (attributePath.length() > 0 && isChange) {
                     model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
@@ -265,6 +514,21 @@
         return false;
     }
 
+    public boolean isChange() {
+
+        boolean isOvverideTableChange = ((OverrideEmbeddableAttributeTableModel) view
+                .getOverrideAttributeTable()
+                .getModel()).isAttributeOverrideChange();
+        return isOvverideTableChange
+                || !attribute.getName().equals(view.getAttributeName().getText())
+                || (attribute.getType() == null && view
+                        .getType()
+                        .getSelectedItem()
+                        .toString() != null)
+                || !attribute.getType().equals(
+                        view.getType().getSelectedItem().toString());
+    }
+
     public void saveMapping() {
 
         if (setPath(false)) {
@@ -273,14 +537,89 @@
                     "You have changed Db Attribute path. Do you want it to be saved?",
                     "Save ObjAttribute",
                     JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
-                model.setUpdatedValueAt(attributeSaved.getName(), row, 1);
-                model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+
+                if ((attributeSaved instanceof EmbeddedAttribute && !(attribute instanceof EmbeddedAttribute))
+                        || (!(attributeSaved instanceof EmbeddedAttribute) && attribute instanceof EmbeddedAttribute)) {
+                    model.getEntity().removeAttribute(attribute.getName());
+                    model.getEntity().addAttribute(attributeSaved);
+
+                    mediator.fireObjEntityEvent(new EntityEvent(
+                            this,
+                            model.getEntity(),
+                            MapEvent.CHANGE));
+
+                    EntityDisplayEvent event = new EntityDisplayEvent(
+                            this,
+                            mediator.getCurrentObjEntity(),
+                            mediator.getCurrentDataMap(),
+                            mediator.getCurrentDataDomain());
+
+                    mediator.fireObjEntityDisplayEvent(event);
+
+                    mediator.fireObjAttributeEvent(new AttributeEvent(
+                            this,
+                            attributeSaved,
+                            model.getEntity(),
+                            MapEvent.CHANGE));
+
+                    AttributeDisplayEvent eventAttr = new AttributeDisplayEvent(
+                            this,
+                            attributeSaved,
+                            mediator.getCurrentObjEntity(),
+                            mediator.getCurrentDataMap(),
+                            mediator.getCurrentDataDomain());
+
+                    mediator.fireObjAttributeDisplayEvent(eventAttr);
+
+                }
+
+                if ((attributeSaved instanceof EmbeddedAttribute && attribute instanceof EmbeddedAttribute)
+                        || (!(attributeSaved instanceof EmbeddedAttribute) && !(attribute instanceof EmbeddedAttribute))) {
+                    model.setUpdatedValueAt(attributeSaved.getName(), row, 1);
+                    model.setUpdatedValueAt(attributeSaved.getType(), row, 2);
+                    model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
+                }
+
+                if (attributeSaved instanceof EmbeddedAttribute
+                        && attribute instanceof EmbeddedAttribute) {
+
+                    if (embeddableModel.isAttributeOverrideChange()) {
+                        Map<String, String> overrides;
+                        overrides = ((EmbeddedAttribute) attribute)
+                                .getAttributeOverrides();
+                        Map<String, String> currentOverrAttr = ((EmbeddedAttribute) attributeSaved)
+                                .getAttributeOverrides();
+
+                        compareAndSetOverrideInEmbeddedAttribute(
+                                attribute,
+                                overrides,
+                                currentOverrAttr);
+                    }
+                }
             }
         }
-
         closeAction();
     }
 
+    public Map<String, String> getCurrentOverrideAttribute() {
+        Map<String, String> currentEmbeddableOverrite = new HashMap<String, String>();
+        Collection<EmbeddableAttribute> embList = embeddableModel.getEmbeddableList();
+        Embeddable emb = stringToEmbeddables.get(attributeSaved.getType());
+        Iterator<EmbeddableAttribute> it = embList.iterator();
+        while (it.hasNext()) {
+            EmbeddableAttribute e = it.next();
+            if ((emb.getAttribute(e.getName()).getDbAttributeName() == null && e
+                    .getDbAttributeName() != null)
+                    || (emb.getAttribute(e.getName()).getDbAttributeName() != null && !emb
+                            .getAttribute(e.getName())
+                            .getDbAttributeName()
+                            .equals(e.getDbAttributeName()))) {
+                currentEmbeddableOverrite.put(e.getName(), e.getDbAttributeName());
+            }
+        }
+        return currentEmbeddableOverrite;
+    }
+
     public void valueChanged(TreeSelectionEvent e) {
 
         TreePath selectedPath = e.getPath();
@@ -402,4 +741,123 @@
             view.getSaveButton().setEnabled(true);
         }
     }
+
+    public boolean isRegistredType(String typeName) {
+        boolean isType = false;
+        String[] typeNames = ModelerUtil.getRegisteredTypeNames();
+        for (int i = 0; i < typeNames.length; i++) {
+            if (typeNames[i].equals(typeName)) {
+                isType = true;
+            }
+        }
+        return isType;
+    }
+
+    // custom renderer used for inherited attributes highlighting
+    final class CellRenderer extends DefaultTableCellRenderer {
+
+        @Override
+        public Component getTableCellRendererComponent(
+                JTable table,
+                Object value,
+                boolean isSelected,
+                boolean hasFocus,
+                int row,
+                int column) {
+
+            super.getTableCellRendererComponent(
+                    table,
+                    value,
+                    isSelected,
+                    hasFocus,
+                    row,
+                    column);
+
+            OverrideEmbeddableAttributeTableModel model = (OverrideEmbeddableAttributeTableModel) table
+                    .getModel();
+
+            if (!model.isCellEditable(row, column)) {
+                setForeground(Color.GRAY);
+            }
+            else {
+                setForeground(isSelected && !hasFocus
+                        ? table.getSelectionForeground()
+                        : table.getForeground());
+            }
+            setBackground(isSelected && !hasFocus
+                    ? table.getSelectionBackground()
+                    : table.getBackground());
+
+            return this;
+        }
+    }
+
+    private void copyObjAttribute(ObjAttribute attributeSaved, ObjAttribute attribute) {
+        attributeSaved.setDbAttributePath(attribute.getDbAttributePath());
+        attributeSaved.setName(attribute.getName());
+        attributeSaved.setEntity(attribute.getEntity());
+        attributeSaved.setParent(attribute.getParent());
+        attributeSaved.setType(attribute.getType());
+        attributeSaved.setUsedForLocking(attribute.isUsedForLocking());
+
+        if (attributeSaved instanceof EmbeddedAttribute) {
+            Map<String, String> attrOverrides;
+            if (attribute instanceof EmbeddedAttribute) {
+                attrOverrides = ((EmbeddedAttribute) attribute).getAttributeOverrides();
+            }
+            else {
+                attrOverrides = new HashMap<String, String>();
+            }
+            if (attrOverrides.size() > 0) {
+                Iterator it = attrOverrides.entrySet().iterator();
+
+                while (it.hasNext()) {
+                    Map.Entry attrOv = (Map.Entry) it.next();
+                    ((EmbeddedAttribute) attributeSaved).addAttributeOverride(attrOv
+                            .getKey()
+                            .toString(), attrOv.getValue().toString());
+                }
+            }
+        }
+    }
+
+    private void compareAndSetOverrideInEmbeddedAttribute(
+            ObjAttribute attribute,
+            Map<String, String> overrides,
+            Map<String, String> currentOverrAttr) {
+        ArrayList<String> keysForDelete = new ArrayList<String>();
+        ArrayList<String> keysForAdd = new ArrayList<String>();
+
+        Iterator it = overrides.entrySet().iterator();
+        while (it.hasNext()) {
+            Map.Entry obj = (Map.Entry) it.next();
+
+            String key = (String) obj.getKey();
+            if (currentOverrAttr.get(key) == null
+                    || !(obj.getValue().equals(currentOverrAttr.get(key)))) {
+                keysForDelete.add(key);
+            }
+        }
+
+        Iterator iter = currentOverrAttr.entrySet().iterator();
+        while (iter.hasNext()) {
+            Map.Entry obj = (Map.Entry) iter.next();
+            String key = (String) obj.getKey();
+            if (overrides.get(key) == null
+                    || !(obj.getValue().equals(overrides.get(key)))) {
+                keysForAdd.add(key);
+            }
+        }
+
+        for (int i = 0; i < keysForDelete.size(); i++) {
+            ((EmbeddedAttribute) attribute).removeAttributeOverride(keysForDelete.get(i));
+        }
+        for (int i = 0; i < keysForAdd.size(); i++) {
+            String key = keysForAdd.get(i);
+            ((EmbeddedAttribute) attribute).addAttributeOverride(key, currentOverrAttr
+                    .get(key));
+        }
+
+    }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjAttributeInfoDialogView.java Thu Oct  8 09:04:49 2009
@@ -19,8 +19,13 @@
 package org.apache.cayenne.modeler.dialog.objentity;
 
 import java.awt.BorderLayout;
+import java.awt.CardLayout;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentEvent;
+import java.awt.event.ComponentListener;
 
 import javax.swing.JButton;
 import javax.swing.JComboBox;
@@ -30,12 +35,18 @@
 import javax.swing.JScrollPane;
 import javax.swing.JTextField;
 
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.CayenneTable;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+import org.apache.cayenne.modeler.util.ModelerUtil;
 import org.apache.cayenne.modeler.util.MultiColumnBrowser;
 import org.apache.cayenne.modeler.util.PanelFactory;
+import org.apache.cayenne.modeler.util.combo.AutoCompletion;
 
 import com.jgoodies.forms.builder.PanelBuilder;
 import com.jgoodies.forms.layout.CellConstraints;
 import com.jgoodies.forms.layout.FormLayout;
+import com.jgoodies.forms.layout.RowSpec;
 
 public class ObjAttributeInfoDialogView extends JDialog {
 
@@ -52,19 +63,39 @@
     protected JLabel currentPathLabel;
     protected JLabel sourceEntityLabel;
     protected JComboBox targCombo;
-    
+
+    protected JComboBox type;
+    protected JPanel typeManagerPane;
+
+    protected CayenneTable overrideAttributeTable;
+
+    ProjectController mediator;
+
     static final Dimension BROWSER_CELL_DIM = new Dimension(130, 200);
+    
+    static final String EMBEDDABLE_PANEL = "EMBEDDABLE_PANEL"; 
+    static final String FLATTENED_PANEL = "FLATTENED_PANEL"; 
+
+    public ObjAttributeInfoDialogView(ProjectController mediator) {
 
-    public ObjAttributeInfoDialogView() {
+        this.mediator = mediator;
 
         // create widgets
         this.cancelButton = new JButton("Close");
         this.saveButton = new JButton("Done");
         this.selectPathButton = new JButton("Select path");
+
         this.attributeName = new JTextField(25);
         this.currentPathLabel = new JLabel();
         this.sourceEntityLabel = new JLabel();
 
+        this.type = CayenneWidgetFactory.createComboBox(ModelerUtil
+                .getRegisteredTypeNames(), false);
+        AutoCompletion.enable(type, false, true);
+        type.getRenderer();
+
+        overrideAttributeTable = new CayenneTable();
+
         saveButton.setEnabled(false);
         cancelButton.setEnabled(true);
         selectPathButton.setEnabled(false);
@@ -75,12 +106,14 @@
         setLayout(new BorderLayout());
 
         CellConstraints cc = new CellConstraints();
-        PanelBuilder builder = new PanelBuilder(
+        final PanelBuilder builder = new PanelBuilder(
                 new FormLayout(
-                        "right:max(50dlu;pref), 3dlu, fill:min(150dlu;pref), 3dlu, 300dlu, 3dlu, fill:min(120dlu;pref)",
-                        "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, top:14dlu, 3dlu, top:p:grow"));
+                        "right:max(50dlu;pref), 3dlu, fill:min(200dlu;pref), 15dlu, right:max(30dlu;pref), 3dlu, 185dlu, "
+                                + "3dlu, 20dlu, 3dlu, fill:min(70dlu;pref)",
+                        "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 6dlu, p, 6dlu, p, 3dlu, fill:p:grow"));
         builder.setDefaultDialogBorder();
-        builder.addSeparator("ObjAttribute Information", cc.xywh(1, 1, 5, 1));
+        builder.addSeparator("ObjAttribute Information", cc.xywh(1, 1, 11, 1));
+
         builder.addLabel("Attribute:", cc.xy(1, 3));
         builder.add(attributeName, cc.xywh(3, 3, 1, 1));
 
@@ -93,29 +126,111 @@
         builder.addLabel("Target:", cc.xy(1, 9));
         builder.add(targCombo, cc.xywh(3, 9, 1, 1));
 
-        builder.addSeparator("Mapping to DbRelationships", cc.xywh(1, 11, 5, 1));
+        builder.addLabel("Type:", cc.xy(1, 11));
+        builder.add(type, cc.xywh(3, 11, 1, 1));
+
+        builder.addSeparator("Mapping to Attributes", cc.xywh(1, 13, 10, 1));
+
+        typeManagerPane = new JPanel();
+        typeManagerPane.setLayout(new CardLayout());
+
+        final FormLayout fL = new FormLayout(
+                "483dlu ",
+                "p, 3dlu, fill:min(128dlu;pref):grow");
+
+        // panel for Flattened attribute
+        final PanelBuilder builderPathPane = new PanelBuilder(fL);
 
         JPanel buttonsPane = new JPanel(new FlowLayout(FlowLayout.LEADING));
         buttonsPane.add(selectPathButton);
 
-        builder.add(buttonsPane, cc.xywh(1, 13, 5, 1));
+        builderPathPane.add(buttonsPane, cc.xywh(1, 1, 1, 1));
         pathBrowser = new ObjAttributePathBrowser(selectPathButton, saveButton);
         pathBrowser.setPreferredColumnSize(BROWSER_CELL_DIM);
         pathBrowser.setDefaultRenderer();
-        builder.add(new JScrollPane(
+        builderPathPane.add(new JScrollPane(
                 pathBrowser,
                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
-                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), cc.xywh(1, 15, 5, 3));
+                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), cc.xywh(1, 3, 1, 1));
+
+        // panel for embeddable attribute
+        final FormLayout fLEmb = new FormLayout(
+                "483dlu ",
+                "fill:min(140dlu;pref):grow");
+
+        final PanelBuilder embeddablePane = new PanelBuilder(fLEmb);
+
+        embeddablePane.add(new JScrollPane(overrideAttributeTable,
+              JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+              JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED),
+              cc.xywh(1, 1, 1, 1));
+
+        typeManagerPane.add(builderPathPane.getPanel(), FLATTENED_PANEL);
+        typeManagerPane.add(embeddablePane.getPanel(), EMBEDDABLE_PANEL);
+
+        builder.add(typeManagerPane, cc.xywh(1, 15, 11, 1));
 
         add(builder.getPanel(), BorderLayout.CENTER);
+
+        this.addComponentListener(new ComponentListener() {
+
+            int height;
+
+            public void componentHidden(ComponentEvent e) {
+            }
+
+            public void componentMoved(ComponentEvent e) {
+            }
+
+            public void componentResized(ComponentEvent e) {
+                int delta = e.getComponent().getHeight() - height;
+                if (delta < 0) {
+                    fL.setRowSpec(3, new RowSpec("fill:min(10dlu;pref):grow"));
+                    fLEmb.setRowSpec(1, new RowSpec("fill:min(10dlu;pref):grow"));
+                }
+            }
+
+            public void componentShown(ComponentEvent e) {
+                height = e.getComponent().getHeight();
+            }
+        });
+
         add(PanelFactory.createButtonPanel(new JButton[] {
                 saveButton, cancelButton
         }), BorderLayout.SOUTH);
+
+        type.addActionListener(new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                boolean isType = false;
+                String[] typeNames = ModelerUtil.getRegisteredTypeNames();
+                for (int i = 0; i < typeNames.length; i++) {
+                    if (type.getSelectedItem() == null || typeNames[i].equals(type.getSelectedItem().toString())) {
+                        isType = true;
+                    }
+                }
+
+                if (isType) {
+                    ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, FLATTENED_PANEL);
+                }
+                else {
+                    ((CardLayout) typeManagerPane.getLayout()).show(typeManagerPane, EMBEDDABLE_PANEL);
+                    getCurrentPathLabel().setText("");
+                    
+                }
+            }
+
+        });
+    }
+
+    public CayenneTable getOverrideAttributeTable() {
+        return overrideAttributeTable;
+    }
+
+    public JComboBox getType() {
+        return type;
     }
-    
 
-    
-    
     public JComboBox getTargCombo() {
         return targCombo;
     }

Added: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/OverrideEmbeddableAttributeTableModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/OverrideEmbeddableAttributeTableModel.java?rev=823096&view=auto
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/OverrideEmbeddableAttributeTableModel.java (added)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/OverrideEmbeddableAttributeTableModel.java Thu Oct  8 09:04:49 2009
@@ -0,0 +1,286 @@
+/*****************************************************************
+ *   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.dialog.objentity;
+
+import java.awt.Color;
+import java.awt.Component;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.DefaultCellEditor;
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+
+import org.apache.cayenne.dba.TypesMapping;
+import org.apache.cayenne.map.DbAttribute;
+import org.apache.cayenne.map.DbEntity;
+import org.apache.cayenne.map.EmbeddableAttribute;
+import org.apache.cayenne.map.EmbeddedAttribute;
+import org.apache.cayenne.map.ObjAttribute;
+import org.apache.cayenne.map.ObjEntity;
+import org.apache.cayenne.modeler.ProjectController;
+import org.apache.cayenne.modeler.util.CayenneTable;
+import org.apache.cayenne.modeler.util.CayenneTableModel;
+import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+import org.apache.cayenne.modeler.util.CellEditorForAttributeTable;
+
+public class OverrideEmbeddableAttributeTableModel extends CayenneTableModel {
+
+    private Map<String, String> overrideAttr;
+    private ObjAttribute attr;
+    private boolean isAttributeOverrideChange;
+
+    private CellEditorForAttributeTable cellEditor;
+    Collection<String> nameAttr;
+    private CayenneTable table;
+
+    protected List<EmbeddableAttribute> embeddableList;
+
+    public List<EmbeddableAttribute> getEmbeddableList() {
+        return embeddableList;
+    }
+
+    public OverrideEmbeddableAttributeTableModel(ProjectController mediator,
+            Object eventSource, Collection<EmbeddableAttribute> embAttr, ObjAttribute attr) {
+
+        super(mediator, eventSource, new ArrayList<Object>(embAttr));
+        this.embeddableList = new ArrayList<EmbeddableAttribute>(embAttr);
+        this.attr = attr;
+        this.isAttributeOverrideChange = false;
+        if (attr instanceof EmbeddedAttribute) {
+            EmbeddedAttribute embeddedAttribute = (EmbeddedAttribute) attr;
+            this.overrideAttr = embeddedAttribute.getAttributeOverrides();
+        }
+        else {
+            this.overrideAttr = null;
+        }
+
+        Iterator<EmbeddableAttribute> it = embeddableList.iterator();
+
+        while (it.hasNext()) {
+            EmbeddableAttribute emb = it.next();
+            if (overrideAttr != null) {
+                if (overrideAttr.get(emb.getName()) != null) {
+                    emb.setDbAttributeName(overrideAttr.get(emb.getName()));
+                }
+            }
+        }
+    }
+
+    public Map<String, String> getOverrideAttr() {
+        return overrideAttr;
+    }
+
+    // Columns
+    static final int OBJ_ATTRIBUTE = 0;
+    static final int OBJ_ATTRIBUTE_TYPE = 1;
+    static final int DB_ATTRIBUTE = 2;
+    static final int DB_ATTRIBUTE_TYPE = 3;
+
+    protected void orderList() {
+        // NOOP
+    }
+
+    /**
+     * Returns ObjAttribute class.
+     */
+    @Override
+    public Class<?> getElementsClass() {
+        return ObjAttribute.class;
+    }
+
+    @Override
+    public void setUpdatedValueAt(Object value, int row, int col) {
+
+        EmbeddableAttribute attribute = getEmbeddableAttribute(row);
+
+        if (col == DB_ATTRIBUTE) {
+
+            attribute.setDbAttributeName(value != null ? value.toString() : null);
+            fireTableCellUpdated(row, col);
+            this.isAttributeOverrideChange = true;
+            ((ObjAttributeInfoDialogView) ((ObjAttributeInfoDialog) eventSource)
+                    .getView()).getSaveButton().setEnabled(true);
+
+            if (value != null) {
+                DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
+                if (currentEnt != null) {
+                    DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(value
+                            .toString());
+                    if (dbAttr != null) {
+                        fireTableCellUpdated(DB_ATTRIBUTE_TYPE, col);
+                    }
+                }
+            }
+            fireTableRowsUpdated(row, row);
+        }
+    }
+
+    public boolean isAttributeOverrideChange() {
+        return isAttributeOverrideChange;
+    }
+
+    public CellEditorForAttributeTable setCellEditor(
+            Collection<String> nameAttr,
+            CayenneTable table) {
+        this.table = table;
+        this.cellEditor = new CellEditorForAttributeTable(table, CayenneWidgetFactory
+                .createComboBox(nameAttr, true));
+        return cellEditor;
+    }
+
+    public CellEditorForAttributeTable getCellEditor() {
+        return cellEditor;
+    }
+
+    public boolean isCellEditable(int row, int col) {
+        return col == DB_ATTRIBUTE;
+    }
+
+    public EmbeddableAttribute getEmbeddableAttribute(int row) {
+        return (row >= 0 && row < embeddableList.size())
+                ? (EmbeddableAttribute) embeddableList.get(row)
+                : null;
+    }
+
+    public int getColumnCount() {
+        return 4;
+    }
+
+    public Object getValueAt(int row, int column) {
+        EmbeddableAttribute attribute = getEmbeddableAttribute(row);
+
+        if (column == OBJ_ATTRIBUTE) {
+            return attribute.getName();
+        }
+        else if (column == OBJ_ATTRIBUTE_TYPE) {
+            return attribute.getType();
+        }
+        else {
+            String dbAttributeName = attribute.getDbAttributeName();
+            if (column == DB_ATTRIBUTE) {
+                return dbAttributeName;
+            }
+            else if (column == DB_ATTRIBUTE_TYPE) {
+
+                DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
+                if (currentEnt != null
+                        && currentEnt.getAttributes() != null
+                        && dbAttributeName != null) {
+                    DbAttribute dbAttr = (DbAttribute) currentEnt
+                            .getAttribute(dbAttributeName);
+                    if (dbAttr != null) {
+                        return TypesMapping.getSqlNameByType(dbAttr.getType());
+                    }
+                }
+                return null;
+            }
+            else {
+                return null;
+            }
+        }
+    }
+
+    public String getColumnName(int column) {
+        switch (column) {
+            case OBJ_ATTRIBUTE:
+                return "ObjAttribute";
+            case OBJ_ATTRIBUTE_TYPE:
+                return "Java Type";
+            case DB_ATTRIBUTE:
+                return "DbAttribute";
+            case DB_ATTRIBUTE_TYPE:
+                return "DB Type";
+            default:
+                return "";
+        }
+    }
+
+    public void setComboBoxes(Collection<String> nameAttr, int column) {
+
+        int count = getRowCount();
+        for (int i = 0; i < count; i++) {
+            EmbeddableAttribute embAt = getEmbeddableAttribute(i);
+            if (!nameAttr.contains(embAt.getDbAttributeName())
+                    && embAt.getDbAttributeName() != null) {
+                Collection<String> attributeComboForRow = new ArrayList<String>();
+                attributeComboForRow.addAll(nameAttr);
+                attributeComboForRow.add(embAt.getDbAttributeName());
+                JComboBox comboBoxForRow = CayenneWidgetFactory.createComboBox(
+                        attributeComboForRow,
+                        true);
+
+                cellEditor.setEditorAt(new Integer(i), new DefaultCellEditor(
+                        comboBoxForRow));
+                BoxCellRenderer renderer = new BoxCellRenderer();
+                renderer.setNotActiveColumn(attributeComboForRow.size() - 1);
+                comboBoxForRow.setRenderer(renderer);
+
+            }
+        }
+
+        table.getColumnModel().getColumn(column).setCellEditor(cellEditor);
+    }
+
+    public ObjAttribute getAttribute() {
+        return attr;
+    }
+
+}
+
+class BoxCellRenderer implements ListCellRenderer {
+
+    protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();
+    private int notActiveColumn;
+
+    public Component getListCellRendererComponent(
+            JList list,
+            Object value,
+            int index,
+            boolean isSelected,
+            boolean cellHasFocus) {
+
+        JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(
+                list,
+                value,
+                index,
+                isSelected,
+                cellHasFocus);
+
+        if (getNotActiveColumn() != 0 && index == getNotActiveColumn()) {
+            renderer.setForeground(Color.GRAY);
+        }
+
+        return renderer;
+    }
+
+    public int getNotActiveColumn() {
+        return notActiveColumn;
+    }
+
+    public void setNotActiveColumn(int notActiveColumn) {
+        this.notActiveColumn = notActiveColumn;
+    }
+}

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EditorView.java Thu Oct  8 09:04:49 2009
@@ -86,19 +86,24 @@
     protected Container detailPanel;
     protected CardLayout detailLayout;
     private ProjectTreeView treePanel;
+    
+    private DbEntityTabbedView dbDetailView;
+    private ObjEntityTabbedView objDetailView;
+    private EmbeddableTabbedView embeddableView;
 
+    
     public ProjectTreeView getProjectTreeView() {
         return treePanel;
     }
 
-    private DbEntityTabbedView dbDetailView;
-
+    public EmbeddableTabbedView getEmbeddableView() {
+        return embeddableView;
+    }
+    
     public DbEntityTabbedView getDbDetailView() {
         return dbDetailView;
     }
 
-    private ObjEntityTabbedView objDetailView;
-
     public ObjEntityTabbedView getObjDetailView() {
         return objDetailView;
     }
@@ -153,7 +158,7 @@
         Component ejbqlQueryView = new EjbqlTabbedView(eventController);
         detailPanel.add(ejbqlQueryView, EJBQL_QUERY_VIEW);
 
-        Component embeddableView = new EmbeddableTabbedView(eventController);
+        embeddableView = new EmbeddableTabbedView(eventController);
         detailPanel.add(new JScrollPane(embeddableView), EMBEDDABLE_VIEW);
 
         objDetailView = new ObjEntityTabbedView(eventController);

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTab.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTab.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTab.java Thu Oct  8 09:04:49 2009
@@ -19,8 +19,6 @@
 package org.apache.cayenne.modeler.editor;
 
 import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
 import java.util.EventObject;
 import java.util.List;
 
@@ -28,12 +26,10 @@
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
-import javax.swing.JTable;
 import javax.swing.JToolBar;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;
-import javax.swing.table.DefaultTableCellRenderer;
 import javax.swing.table.TableColumn;
 
 import org.apache.cayenne.map.DataMap;
@@ -95,7 +91,6 @@
         add(toolBar, BorderLayout.NORTH);
 
         table = new CayenneTable();
-        table.setDefaultRenderer(String.class, new CellRenderer());
 
         /**
          * Create and install a popup
@@ -261,51 +256,4 @@
 
     public void embeddableRemoved(EmbeddableEvent e, DataMap map) {
     }
-
-    // custom renderer used for inherited attributes highlighting
-    final class CellRenderer extends DefaultTableCellRenderer {
-
-        @Override
-        public Component getTableCellRendererComponent(
-                JTable table,
-                Object value,
-                boolean isSelected,
-                boolean hasFocus,
-                int row,
-                int column) {
-
-            super.getTableCellRendererComponent(
-                    table,
-                    value,
-                    isSelected,
-                    hasFocus,
-                    row,
-                    column);
-
-            EmbeddableAttributeTableModel model = (EmbeddableAttributeTableModel) table
-                    .getModel();
-            EmbeddableAttribute attribute = model.getEmbeddableAttribute(row);
-            if (column != EmbeddableAttributeTableModel.INHERITED) {
-
-                if (!model.isCellEditable(row, column)) {
-                    setForeground(Color.GRAY);
-                }
-                else {
-                    setForeground(isSelected && !hasFocus ? table
-                            .getSelectionForeground() : table.getForeground());
-                }
-
-                setIcon(null);
-            }
-            else {
-                setText("");
-            }
-            setBackground(isSelected && !hasFocus
-                    ? table.getSelectionBackground()
-                    : table.getBackground());
-
-            return this;
-        }
-    }
-
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTableModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTableModel.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTableModel.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableAttributeTableModel.java Thu Oct  8 09:04:49 2009
@@ -18,20 +18,10 @@
  ****************************************************************/
 package org.apache.cayenne.modeler.editor;
 
-import java.awt.Component;
-import java.awt.event.MouseEvent;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
-import java.util.EventObject;
-import java.util.Hashtable;
-
-import javax.swing.DefaultCellEditor;
-import javax.swing.JComboBox;
-import javax.swing.JTable;
-import javax.swing.event.CellEditorListener;
-import javax.swing.table.TableCellEditor;
 
 import org.apache.cayenne.map.Embeddable;
 import org.apache.cayenne.map.EmbeddableAttribute;
@@ -40,6 +30,7 @@
 import org.apache.cayenne.modeler.util.CayenneTable;
 import org.apache.cayenne.modeler.util.CayenneTableModel;
 import org.apache.cayenne.modeler.util.CayenneWidgetFactory;
+import org.apache.cayenne.modeler.util.CellEditorForAttributeTable;
 import org.apache.cayenne.modeler.util.ProjectUtil;
 import org.apache.cayenne.util.Util;
 
@@ -53,9 +44,7 @@
     static final int OBJ_ATTRIBUTE_TYPE = 2;
     static final int DB_ATTRIBUTE = 3;
 
-    private CellEditor cellEditor;
-
-    private CayenneTable table;
+    private CellEditorForAttributeTable cellEditor;
 
     public EmbeddableAttributeTableModel(Embeddable embeddable,
             ProjectController mediator, Object eventSource) {
@@ -143,15 +132,14 @@
         }
     }
 
-    public CellEditor setCellEditor(Collection<String> nameAttr, CayenneTable table) {
-        this.cellEditor = new CellEditor(table, CayenneWidgetFactory.createComboBox(
+    public CellEditorForAttributeTable setCellEditor(Collection<String> nameAttr, CayenneTable table) {
+        this.cellEditor = new CellEditorForAttributeTable(table, CayenneWidgetFactory.createComboBox(
                 nameAttr,
                 true));
-        this.table = table;
         return cellEditor;
     }
 
-    public CellEditor getCellEditor() {
+    public CellEditorForAttributeTable getCellEditor() {
         return cellEditor;
     }
 
@@ -175,85 +163,4 @@
             return a.getEmbeddable() == embeddable ? 1 : -1;
         }
     }
-
-    final class CellEditor implements TableCellEditor {
-
-        protected Hashtable editors;
-        protected TableCellEditor editor, defaultEditor;
-        JTable table;
-
-        public CellEditor(JTable table, JComboBox combo) {
-            this.table = table;
-            editors = new Hashtable();
-            if (combo != null) {
-                defaultEditor = new DefaultCellEditor(combo);
-            }
-            else {
-                defaultEditor = new DefaultCellEditor(new JComboBox());
-            }
-        }
-
-        public void setEditorAt(int row, TableCellEditor editor) {
-            editors.put(new Integer(row), editor);
-        }
-
-        public Component getTableCellEditorComponent(
-                JTable table,
-                Object value,
-                boolean isSelected,
-                int row,
-                int column) {
-
-            return editor.getTableCellEditorComponent(
-                    table,
-                    value,
-                    isSelected,
-                    row,
-                    column);
-        }
-
-        public Object getCellEditorValue() {
-            return editor.getCellEditorValue();
-        }
-
-        public boolean stopCellEditing() {
-            return editor.stopCellEditing();
-        }
-
-        public void cancelCellEditing() {
-            editor.cancelCellEditing();
-        }
-
-        public boolean isCellEditable(EventObject anEvent) {
-            selectEditor((MouseEvent) anEvent);
-            return editor.isCellEditable(anEvent);
-        }
-
-        public void addCellEditorListener(CellEditorListener l) {
-            editor.addCellEditorListener(l);
-        }
-
-        public void removeCellEditorListener(CellEditorListener l) {
-            editor.removeCellEditorListener(l);
-        }
-
-        public boolean shouldSelectCell(EventObject anEvent) {
-            selectEditor((MouseEvent) anEvent);
-            return editor.shouldSelectCell(anEvent);
-        }
-
-        protected void selectEditor(MouseEvent e) {
-            int row;
-            if (e == null) {
-                row = table.getSelectionModel().getAnchorSelectionIndex();
-            }
-            else {
-                row = table.rowAtPoint(e.getPoint());
-            }
-            editor = (TableCellEditor) editors.get(new Integer(row));
-            if (editor == null) {
-                editor = defaultEditor;
-            }
-        }
-    }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableTab.java?rev=823096&r1=823095&r2=823096&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableTab.java (original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/EmbeddableTab.java Thu Oct  8 09:04:49 2009
@@ -34,6 +34,7 @@
 import org.apache.cayenne.modeler.event.EmbeddableDisplayListener;
 import org.apache.cayenne.modeler.util.TextAdapter;
 import org.apache.cayenne.util.Util;
+import org.apache.cayenne.validation.ValidationException;
 
 import com.jgoodies.forms.builder.DefaultFormBuilder;
 import com.jgoodies.forms.layout.FormLayout;
@@ -102,12 +103,23 @@
         if (Util.nullSafeEquals(newClassName, embeddable.getClassName())) {
             return;
         }
-
-        // completely new name, set new name for entity
-        EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
-        embeddable.setClassName(newClassName);
         
-        mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
+        if(newClassName == null){
+            throw new ValidationException("Entity name is required.");
+        }  else if (embeddable.getDataMap().getEmbeddable(newClassName) == null) {
+            // completely new name, set new name for embeddable
+            EmbeddableEvent e = new EmbeddableEvent(this, embeddable, embeddable.getClassName());
+            embeddable.setClassName(newClassName);
+            
+            mediator.fireEmbeddableEvent(e, mediator.getCurrentDataMap());
+        } else {
+            // there is an embeddable with the same name
+            throw new ValidationException("There is another embeddable with name '"
+                    + newClassName
+                    + "'.");
+        }
+
+      
     }
 
     public void currentEmbeddableChanged(EmbeddableDisplayEvent e) {



Mime
View raw message