cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r793490 [2/2] - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: ./ action/ dialog/objentity/ editor/ util/
Date Mon, 13 Jul 2009 08:41:51 GMT
Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjRelationshipPathBrowser.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjRelationshipPathBrowser.java?rev=793490&r1=793489&r2=793490&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjRelationshipPathBrowser.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/objentity/ObjRelationshipPathBrowser.java
Mon Jul 13 08:41:50 2009
@@ -27,22 +27,24 @@
 import javax.swing.event.ListSelectionListener;
 import javax.swing.tree.TreePath;
 
+import org.apache.cayenne.map.DbRelationship;
 import org.apache.cayenne.modeler.util.MultiColumnBrowser;
 
 /**
  * Multi-column browser for obj relationships
  */
 public class ObjRelationshipPathBrowser extends MultiColumnBrowser {
+
     /**
      * Listener, which performs adding of new column
      */
-    private MouseListener panelOpener;
-    
+    protected MouseListener panelOpener;
+
     /**
      * Listener, which performs removing of columns to the right of selected row
      */
-    private ListSelectionListener panelRemover;
-    
+    protected ListSelectionListener panelRemover;
+
     public ObjRelationshipPathBrowser() {
         this(DEFAULT_MIN_COLUMNS_COUNT);
     }
@@ -50,27 +52,26 @@
     public ObjRelationshipPathBrowser(int minColumns) {
         super(minColumns);
     }
-    
+
     @Override
     protected void installColumn(BrowserPanel panel) {
         if (panelOpener == null) {
             panelOpener = new PanelOpener();
         }
-        
+
         if (panelRemover == null) {
             panelRemover = new PanelRemover();
         }
-        
+
         panel.addMouseListener(panelOpener);
         panel.addListSelectionListener(panelRemover);
-        
+
         panel.setCellRenderer(renderer);
     }
-    
+
     /**
-     * Selects one path component.
-     * Need to override this method, because list selection does not cause loading
-     * in this browser.
+     * Selects one path component. Need to override this method, because list selection
+     * does not cause loading in this browser.
      */
     @Override
     protected void selectRow(Object row, int index, TreePath path) {
@@ -82,17 +83,18 @@
             updateFromModel(row, index - 1);
         }
     }
-    
+
     @Override
     protected void uninstallColumn(BrowserPanel panel) {
         panel.removeMouseListener(panelOpener);
         panel.removeListSelectionListener(panelRemover);
     }
-    
+
     /**
      * Listener, which performs adding of new column at double-click
      */
     protected class PanelOpener extends MouseAdapter {
+
         /**
          * Invoked when the mouse has been clicked on a component.
          */
@@ -101,35 +103,35 @@
                 process(e);
             }
         }
-               
+
         private void process(MouseEvent e) {
             BrowserPanel panel = (BrowserPanel) e.getSource();
             Object selectedNode = panel.getSelectedValue();
 
             // ignore unselected
-            if (selectedNode != null) {
+            if (selectedNode != null && selectedNode instanceof DbRelationship) {
                 updateFromModel(selectedNode, columns.indexOf(panel));
             }
         }
     }
-    
+
     /**
      * Listener, which performs removing columns to the right of selected row
      */
     protected class PanelRemover implements ListSelectionListener {
 
         public void valueChanged(ListSelectionEvent e) {
-         // ignore "adjusting"
+            // ignore "adjusting"
             if (!e.getValueIsAdjusting()) {
                 BrowserPanel panel = (BrowserPanel) e.getSource();
-                
+
                 Object selectedNode = panel.getSelectedValue();
-                
+
                 if (selectedNode != null) {
                     updateFromModel(selectedNode, columns.indexOf(panel), false);
                 }
             }
         }
-        
+
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java?rev=793490&r1=793489&r2=793490&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjAttributeTableModel.java
Mon Jul 13 08:41:50 2009
@@ -27,6 +27,7 @@
 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.ObjAttribute;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.map.EmbeddedAttribute;
@@ -144,10 +145,10 @@
     public Object getValueAt(int row, int column) {
         ObjAttribute attribute = getAttribute(row);
 
-
         if (column == INHERITED) {
             return attribute.isInherited();
-        } else if (column == OBJ_ATTRIBUTE) {
+        }
+        else if (column == OBJ_ATTRIBUTE) {
             return attribute.getName();
         }
         else if (column == OBJ_ATTRIBUTE_TYPE) {
@@ -160,29 +161,41 @@
             DbAttribute dbAttribute = attribute.getDbAttribute();
             if (column == DB_ATTRIBUTE) {
                 if (dbAttribute == null) {
-                    if (!attribute.isInherited() && ((ObjEntity)attribute.getEntity()).isAbstract())
{
+                    if (!attribute.isInherited()
+                            && ((ObjEntity) attribute.getEntity()).isAbstract())
{
                         return attribute.getDbAttributePath();
-                    } else {
+                    }
+                    else {
                         return null;
                     }
                 }
-                return dbAttribute.getName(); }
-            else 
-            if (column == DB_ATTRIBUTE_TYPE) {
+                else if (attribute.getDbAttributePath() != null
+                        && attribute.getDbAttributePath().contains(".")) {
+                    return attribute.getDbAttributePath();
+                }
+                return dbAttribute.getName();
+            }
+            else if (column == DB_ATTRIBUTE_TYPE) {
                 int type;
                 if (dbAttribute == null) {
                     if (!(attribute instanceof EmbeddedAttribute)) {
                         try {
-                            type = TypesMapping.getSqlTypeByJava(getAttribute(row).getJavaClass());
-                            //have to catch the exception here to make sure that exceptional
situations
-                            //(class doesn't exist, for example) don't prevent the gui from
properly updating.
-                        } catch (CayenneRuntimeException cre) {
+                            type = TypesMapping.getSqlTypeByJava(getAttribute(row)
+                                    .getJavaClass());
+                            // have to catch the exception here to make sure that
+                            // exceptional situations
+                            // (class doesn't exist, for example) don't prevent the gui
+                            // from properly updating.
+                        }
+                        catch (CayenneRuntimeException cre) {
                             return null;
                         }
-                    } else {
+                    }
+                    else {
                         return null;
                     }
-                } else {
+                }
+                else {
                     type = dbAttribute.getType();
                 }
                 return TypesMapping.getSqlNameByType(type);
@@ -216,25 +229,70 @@
         }
         else {
             if (column == DB_ATTRIBUTE) {
+
                 // If db attrib exist, associate it with obj attribute
                 if (value != null) {
                     String path = value.toString();
-                    if (dbEntity != null) {
-                        DbAttribute dbAttribute = (DbAttribute) dbEntity.getAttribute(value
-                                .toString());
-                        path = dbAttribute != null ? dbAttribute.getName() : null;
+
+                    String[] pathSplit = path.split("\\.");
+
+                    // If flattened attribute
+                    if (pathSplit.length > 1) {
+
+                        DbEntity currentEnt = dbEntity;
+                        StringBuilder pathBuf = new StringBuilder();
+                        boolean isTruePath = true;
+
+                        if (dbEntity != null) {
+
+                            for (int j = 0; j < pathSplit.length; j++) {
+
+                                if (j == pathSplit.length - 1 && isTruePath) {
+                                    DbAttribute dbAttribute = (DbAttribute) currentEnt
+                                            .getAttribute(pathSplit[j]);
+                                    if (dbAttribute != null) {
+                                        pathBuf.append(dbAttribute.getName());
+                                    }
+                                    else {
+                                        isTruePath = false;
+                                    }
+                                }
+                                else if (isTruePath) {
+                                    DbRelationship dbRelationship = (DbRelationship) currentEnt
+                                            .getRelationship(pathSplit[j]);
+                                    if (dbRelationship != null) {
+                                        currentEnt = (DbEntity) dbRelationship
+                                                .getTargetEntity();
+                                        pathBuf.append(dbRelationship.getName());
+                                        pathBuf.append(".");
+                                    }
+                                    else {
+                                        isTruePath = false;
+                                    }
+                                }
+                            }
+                        }
+                        path = isTruePath ? pathBuf.toString() : null;
+                    }
+                    else {
+
+                        if (dbEntity != null) {
+                            DbAttribute dbAttribute = (DbAttribute) dbEntity
+                                    .getAttribute(value.toString());
+                            path = dbAttribute != null ? dbAttribute.getName() : null;
+                        }
                     }
                     attribute.setDbAttributePath(path);
+
                 }
                 // If name is erased, remove db attribute from obj attribute.
                 else if (attribute.getDbAttribute() != null) {
                     attribute.setDbAttributePath(null);
                 }
-            }
 
+            }
             fireTableRowsUpdated(row, row);
         }
-
         mediator.fireObjAttributeEvent(event);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java?rev=793490&r1=793489&r2=793490&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/editor/ObjEntityAttributeTab.java
Mon Jul 13 08:41:50 2009
@@ -23,9 +23,14 @@
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Font;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.Collection;
 import java.util.EventObject;
 import java.util.List;
 
+import javax.swing.Icon;
+import javax.swing.JButton;
 import javax.swing.JComboBox;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
@@ -52,6 +57,7 @@
 import org.apache.cayenne.modeler.action.ObjEntitySyncAction;
 import org.apache.cayenne.modeler.action.PasteAction;
 import org.apache.cayenne.modeler.action.RemoveAttributeAction;
+import org.apache.cayenne.modeler.dialog.objentity.ObjAttributeInfoDialog;
 import org.apache.cayenne.modeler.event.AttributeDisplayEvent;
 import org.apache.cayenne.modeler.event.EntityDisplayEvent;
 import org.apache.cayenne.modeler.event.ObjEntityDisplayListener;
@@ -73,9 +79,10 @@
     protected ProjectController mediator;
     protected CayenneTable table;
 
+    JButton resolve;
+
     public ObjEntityAttributeTab(ProjectController mediator) {
         this.mediator = mediator;
-
         init();
         initController();
     }
@@ -88,29 +95,38 @@
         toolBar.add(app.getAction(CreateAttributeAction.getActionName()).buildButton());
         toolBar.add(app.getAction(ObjEntitySyncAction.getActionName()).buildButton());
         toolBar.addSeparator();
+
+        Icon ico = ModelerUtil.buildIcon("icon-info.gif");
+
+        resolve = new JButton();
+        resolve.setIcon(ico);
+        resolve.setToolTipText("Edit Attribute");
+        toolBar.add(resolve);
+
+        toolBar.addSeparator();
         toolBar.add(app.getAction(RemoveAttributeAction.getActionName()).buildButton());
-        
+
         toolBar.addSeparator();
         toolBar.add(app.getAction(CutAttributeAction.getActionName()).buildButton());
         toolBar.add(app.getAction(CopyAttributeAction.getActionName()).buildButton());
         toolBar.add(app.getAction(PasteAction.getActionName()).buildButton());
-        
+
         add(toolBar, BorderLayout.NORTH);
 
         table = new CayenneTable();
         table.setDefaultRenderer(String.class, new CellRenderer());
-        
+
         /**
          * Create and install a popup
          */
         JPopupMenu popup = new JPopupMenu();
         popup.add(app.getAction(RemoveAttributeAction.getActionName()).buildMenu());
-        
+
         popup.addSeparator();
         popup.add(app.getAction(CutAttributeAction.getActionName()).buildMenu());
         popup.add(app.getAction(CopyAttributeAction.getActionName()).buildMenu());
         popup.add(app.getAction(PasteAction.getActionName()).buildMenu());
-        
+
         TablePopupHandler.install(table, popup);
 
         add(PanelFactory.createTablePanel(table, null), BorderLayout.CENTER);
@@ -127,29 +143,59 @@
                 processExistingSelection(e);
             }
         });
-        
-        mediator.getApplication().getActionManager().setupCCP(table, 
-                CutAttributeAction.getActionName(), CopyAttributeAction.getActionName());
+
+        ActionListener resolver = new ActionListener() {
+
+            public void actionPerformed(ActionEvent e) {
+                int row = table.getSelectedRow();
+                if (row < 0) {
+                    return;
+                }
+
+                ObjAttributeTableModel model = (ObjAttributeTableModel) table.getModel();
+
+                // ... show dialog...
+                new ObjAttributeInfoDialog(mediator, row, model).startupAction();
+
+                /**
+                 * This is required for a table to be updated properly
+                 */
+                table.cancelEditing();
+
+                // need to refresh selected row... do this by unselecting/selecting the
+                // row
+                table.getSelectionModel().clearSelection();
+                table.select(row);
+            }
+        };
+
+        resolve.addActionListener(resolver);
+
+        mediator.getApplication().getActionManager().setupCCP(
+                table,
+                CutAttributeAction.getActionName(),
+                CopyAttributeAction.getActionName());
     }
 
     /**
      * Selects a specified attribute.
      */
     public void selectAttributes(ObjAttribute[] attrs) {
-        ModelerUtil.updateActions(attrs.length,  
+        ModelerUtil.updateActions(
+                attrs.length,
                 RemoveAttributeAction.getActionName(),
                 CutAttributeAction.getActionName(),
                 CopyAttributeAction.getActionName());
-        
+
         ObjAttributeTableModel model = (ObjAttributeTableModel) table.getModel();
-        
+
         List listAttrs = model.getObjectList();
         int[] newSel = new int[attrs.length];
-        
+
         for (int i = 0; i < attrs.length; i++) {
             newSel[i] = listAttrs.indexOf(attrs[i]);
         }
-        
+
         table.select(newSel);
     }
 
@@ -157,22 +203,29 @@
         if (e instanceof ChangeEvent) {
             table.clearSelection();
         }
-        
+
         ObjAttribute[] attrs = new ObjAttribute[0];
         if (table.getSelectedRow() >= 0) {
             ObjAttributeTableModel model = (ObjAttributeTableModel) table.getModel();
-            
+
             int[] sel = table.getSelectedRows();
             attrs = new ObjAttribute[sel.length];
-            
+
             for (int i = 0; i < sel.length; i++) {
                 attrs[i] = model.getAttribute(sel[i]);
             }
-     
+
             if (sel.length == 1) {
                 // scroll table
                 UIUtil.scrollToSelectedRow(table);
+                resolve.setEnabled(true);
             }
+            else {
+                resolve.setEnabled(false);
+            }
+        }
+        else {
+            resolve.setEnabled(false);
         }
 
         AttributeDisplayEvent ev = new AttributeDisplayEvent(this, attrs, mediator
@@ -231,7 +284,7 @@
                 ObjAttributeTableModel.INHERITED);
         inheritanceColumn.setMinWidth(20);
         inheritanceColumn.setMaxWidth(20);
-        
+
         TableColumn nameColumn = table.getColumnModel().getColumn(
                 ObjAttributeTableModel.OBJ_ATTRIBUTE);
         nameColumn.setMinWidth(150);
@@ -258,13 +311,24 @@
         dbNameColumn.setMinWidth(150);
 
         if (model.getEntity().getDbEntity() != null) {
-            JComboBox dbAttributesCombo = CayenneWidgetFactory
-                    .createComboBox(ModelerUtil.getDbAttributeNames(mediator, model
-                            .getEntity()
-                            .getDbEntity()), true);
+            Collection<String> nameAttr = ModelerUtil.getDbAttributeNames(mediator,
model
+                    .getEntity()
+                    .getDbEntity());
+
+            int count = model.getRowCount();
+            for (int i = 0; i < count; i++) {
+                if (model.getAttribute(i).getDbAttributePath() != null
+                        && model.getAttribute(i).getDbAttributePath().contains("."))
{
+                    nameAttr.add(model.getAttribute(i).getDbAttributePath());
+                }
+            }
+            JComboBox dbAttributesCombo = CayenneWidgetFactory.createComboBox(
+                    nameAttr,
+                    true);
             AutoCompletion.enable(dbAttributesCombo);
 
-            dbNameColumn.setCellEditor(CayenneWidgetFactory.createCellEditor(dbAttributesCombo));
+            dbNameColumn.setCellEditor(CayenneWidgetFactory
+                    .createCellEditor(dbAttributesCombo));
         }
     }
 
@@ -322,9 +386,8 @@
                     setForeground(Color.GRAY);
                 }
                 else {
-                    setForeground(isSelected && !hasFocus
-                            ? table.getSelectionForeground()
-                            : table.getForeground());
+                    setForeground(isSelected && !hasFocus ? table
+                            .getSelectionForeground() : table.getForeground());
                 }
 
                 if (attribute.isInherited()) {
@@ -333,7 +396,8 @@
                     setFont(newFont);
                 }
                 setIcon(null);
-            } else {
+            }
+            else {
                 if (attribute.isInherited()) {
                     ImageIcon objEntityIcon = ModelerUtil.buildIcon("icon-override.gif");
                     setIcon(objEntityIcon);

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java?rev=793490&r1=793489&r2=793490&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/ProjectUtil.java
Mon Jul 13 08:41:50 2009
@@ -145,11 +145,11 @@
             return;
         }
 
-        if(query instanceof AbstractQuery){
-            ((AbstractQuery)query).setName(newName);
+        if (query instanceof AbstractQuery) {
+            ((AbstractQuery) query).setName(newName);
         }
-        if(query instanceof EJBQLQuery){
-            ((EJBQLQuery)query).setName(newName);
+        if (query instanceof EJBQLQuery) {
+            ((EJBQLQuery) query).setName(newName);
         }
         map.removeQuery(oldName);
         map.addQuery(query);
@@ -248,19 +248,69 @@
                 continue;
             }
 
-            // check individual attributes           
+            // check individual attributes
             for (ObjAttribute att : entity.getAttributes()) {
-                DbAttribute dbAtt = att.getDbAttribute();
-                if (dbAtt != null) {
-                    if (dbEnt.getAttribute(dbAtt.getName()) != dbAtt) {
-                        att.setDbAttributePath(null);
+
+                // If flattenet atribute
+                if (att.getDbAttributePath() != null
+                        && att.getDbAttributePath().contains(".")) {
+                    String[] pathSplit = att.getDbAttributePath().split("\\.");
+
+                    // If flattened attribute
+                    if (pathSplit.length > 1) {
+
+                        DbEntity currentEnt = dbEnt;
+                        StringBuilder pathBuf = new StringBuilder();
+                        boolean isTruePath = true;
+
+                        if (currentEnt != null) {
+
+                            for (int j = 0; j < pathSplit.length; j++) {
+
+                                if (j == pathSplit.length - 1 && isTruePath) {
+                                    DbAttribute dbAttribute = (DbAttribute) currentEnt
+                                            .getAttribute(pathSplit[j]);
+                                    if (dbAttribute != null) {
+                                        pathBuf.append(dbAttribute.getName());
+                                    }
+                                    else {
+                                        isTruePath = false;
+                                    }
+                                }
+                                else if (isTruePath) {
+                                    DbRelationship dbRelationship = (DbRelationship) currentEnt
+                                            .getRelationship(pathSplit[j]);
+                                    if (dbRelationship != null) {
+                                        currentEnt = (DbEntity) dbRelationship
+                                                .getTargetEntity();
+                                        pathBuf.append(dbRelationship.getName());
+                                        pathBuf.append(".");
+                                    }
+                                    else {
+                                        isTruePath = false;
+                                    }
+                                }
+                            }
+                        }
+
+                        if (!isTruePath) {
+                            att.setDbAttributePath(null);
+                        }
+                    }
+                }
+                else {
+                    DbAttribute dbAtt = att.getDbAttribute();
+                    if (dbAtt != null) {
+                        if (dbEnt.getAttribute(dbAtt.getName()) != dbAtt) {
+                            att.setDbAttributePath(null);
+                        }
                     }
                 }
             }
 
-            // check individual relationships           
+            // check individual relationships
             for (ObjRelationship rel : entity.getRelationships()) {
-                
+
                 List<DbRelationship> dbRelList = new ArrayList<DbRelationship>(rel
                         .getDbRelationships());
                 for (DbRelationship dbRel : dbRelList) {
@@ -285,7 +335,7 @@
             return;
         }
 
-       for (ObjAttribute objAttr : entity.getAttributeMap().values()) {
+        for (ObjAttribute objAttr : entity.getAttributeMap().values()) {
             DbAttribute dbAttr = objAttr.getDbAttribute();
             if (null != dbAttr) {
                 objAttr.setDbAttributePath(null);
@@ -308,7 +358,7 @@
             return false;
         }
 
-       for (DbJoin join : relationship.getJoins()) {
+        for (DbJoin join : relationship.getJoins()) {
             if (join.getSource() == attribute) {
                 return true;
             }



Mime
View raw message