cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r787975 - /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/
Date Wed, 24 Jun 2009 11:09:26 GMT
Author: aadamchik
Date: Wed Jun 24 11:09:26 2009
New Revision: 787975

URL: http://svn.apache.org/viewvc?rev=787975&view=rev
Log:
CAY-1220 A function to auto-map the DB relationships

patch by Dima Loiko : inferCombo.txt
that adds naming strategy selection. Reusing non default startegy is sitll broken

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsDialog.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsPanel.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java?rev=787975&r1=787974&r2=787975&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsController.java
Wed Jun 24 11:09:26 2009
@@ -19,7 +19,9 @@
 package org.apache.cayenne.modeler.dialog.autorelationship;
 
 import java.awt.Component;
+import java.util.Vector;
 
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JOptionPane;
 
 import org.apache.cayenne.access.DbLoader;
@@ -30,9 +32,11 @@
 import org.apache.cayenne.map.Entity;
 import org.apache.cayenne.map.event.MapEvent;
 import org.apache.cayenne.map.event.RelationshipEvent;
-import org.apache.cayenne.map.naming.BasicNamingStrategy;
+import org.apache.cayenne.map.naming.NamingStrategy;
 import org.apache.cayenne.modeler.Application;
 import org.apache.cayenne.modeler.CayenneModelerController;
+import org.apache.cayenne.modeler.ClassLoadingService;
+import org.apache.cayenne.modeler.ModelerPreferences;
 import org.apache.cayenne.modeler.ProjectController;
 import org.apache.cayenne.modeler.action.CreateRelationshipAction;
 import org.apache.cayenne.modeler.dialog.ErrorDebugDialog;
@@ -46,12 +50,25 @@
 
 public class InferRelationshipsController extends InferRelationshipsControllerBase {
 
+    private static final String STRATEGIES_PREFERENCE = "recent.preferences";
+
+    private static final Vector<String> PREDEFINED_STRATEGIES = new Vector<String>();
+    static {
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.map.naming.BasicNamingStrategy");
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.map.naming.SmartNamingStrategy");
+    };
+
+    public static final int SELECT = 1;
+    public static final int CANCEL = 0;
+
     private static Log logObj = LogFactory.getLog(ErrorDebugDialog.class);
 
     protected InferRelationshipsDialog view;
 
     protected InferRelationshipsTabController entitySelector;
 
+    protected NamingStrategy strategy;
+
     public InferRelationshipsController(CayenneController parent, DataMap dataMap) {
         super(parent, dataMap);
 
@@ -75,6 +92,7 @@
         centerView();
         makeCloseableOnEscape();
         view.setVisible(true);
+
     }
 
     protected void initBindings() {
@@ -85,6 +103,7 @@
         builder.bindToAction(view.getCancelButton(), "cancelAction()");
         builder.bindToAction(view.getGenerateButton(), "generateAction()");
         builder.bindToAction(this, "entitySelectedAction()", SELECTED_PROPERTY);
+        builder.bindToAction(view.getStrategyCombo(), "strategyComboAction()");
     }
 
     public void entitySelectedAction() {
@@ -104,6 +123,45 @@
         view.getEntityCount().setText(label);
     }
 
+    public void strategyComboAction() {
+        try {
+            ClassLoadingService classLoader = Application
+                    .getInstance()
+                    .getClassLoadingService();
+            String strategyClass = (String) view.getStrategyCombo().getSelectedItem();
+
+            this.strategy = (NamingStrategy) classLoader
+                    .loadClass(strategyClass)
+                    .newInstance();
+            
+            /**
+             * Be user-friendly and update preferences with specified strategy
+             */
+            ModelerPreferences pref = ModelerPreferences.getPreferences();
+            Vector arr = pref.getVector(STRATEGIES_PREFERENCE, PREDEFINED_STRATEGIES);
+
+            // move to top
+            arr.remove(strategyClass);
+            arr.add(0, strategyClass);
+
+            pref.setProperty(STRATEGIES_PREFERENCE, arr);
+        }
+        catch (Throwable th) {
+            logObj.error("Error in " + getClass().getName(), th);
+            return;
+        }
+
+        setNamingStrategy(strategy);
+        createName();
+        entitySelector.initBindings();
+        view.setChoice(SELECT);
+
+    }
+
+    public NamingStrategy getNamingStrategy() {
+        return strategy;
+    }
+
     public void cancelAction() {
         view.dispose();
     }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java?rev=787975&r1=787974&r2=787975&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsControllerBase.java
Wed Jun 24 11:09:26 2009
@@ -55,7 +55,7 @@
     protected List<DbEntity> entities;
     protected Set<InferRelationships> selectedEntities;
     protected int index = 0;
-    protected BasicNamingStrategy strategy;
+    protected NamingStrategy strategy;
 
     protected transient InferRelationships currentEntity;
     protected transient Integer entityNumber;
@@ -66,6 +66,7 @@
         this.dataMap = dataMap;
         this.entities = new ArrayList(dataMap.getDbEntities());
         this.selectedEntities = new HashSet();
+        strategy = new BasicNamingStrategy();
         setRelationships();
         createJoin();
         createName();
@@ -171,6 +172,7 @@
     }
 
     public void createName() {
+
         ExportedKey key = null;
         for (InferRelationships myir : ir) {
             if (myir.getJoinSource().isPrimaryKey()) {
@@ -283,4 +285,8 @@
         return null;
     }
 
+    public void setNamingStrategy(NamingStrategy namestr) {
+        strategy = namestr;
+    }
+
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsDialog.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsDialog.java?rev=787975&r1=787974&r2=787975&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsDialog.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsDialog.java
Wed Jun 24 11:09:26 2009
@@ -22,22 +22,42 @@
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.FlowLayout;
+import java.util.Vector;
 
 import javax.swing.Box;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
+import javax.swing.JComboBox;
 import javax.swing.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JTabbedPane;
 import javax.swing.SwingConstants;
 
+import org.apache.cayenne.map.naming.NamingStrategy;
 import org.apache.cayenne.modeler.Application;
+import org.apache.cayenne.modeler.ModelerPreferences;
 
 public class InferRelationshipsDialog extends JDialog {
 
+    private static final String STRATEGIES_PREFERENCE = "recent.preferences";
+
+    private static final Vector<String> PREDEFINED_STRATEGIES = new Vector<String>();
+    static {
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.map.naming.BasicNamingStrategy");
+        PREDEFINED_STRATEGIES.add("org.apache.cayenne.map.naming.SmartNamingStrategy");
+    };
+
+    public static final int SELECT = 1;
+    public static final int CANCEL = 0;
+    protected int choice;
+
     protected JButton generateButton;
     protected JButton cancelButton;
     protected JLabel entityCount;
+    protected JLabel strategyLabel;
+
+    protected JComboBox strategyCombo;
 
     public InferRelationshipsDialog(Component entitySelectorPanel) {
         super(Application.getFrame());
@@ -46,7 +66,14 @@
         this.entityCount = new JLabel("No DbRelationships selected");
         entityCount.setFont(entityCount.getFont().deriveFont(10f));
 
+        this.strategyCombo = new JComboBox();
+        strategyCombo.setEditable(true);
+        this.strategyLabel = new JLabel("Naming Strategy:  ");
+
         // assemble
+        JPanel strategyPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
+        strategyPanel.add(strategyLabel);
+        strategyPanel.add(strategyCombo);
 
         JPanel messages = new JPanel(new BorderLayout());
         messages.add(entityCount, BorderLayout.WEST);
@@ -59,12 +86,27 @@
 
         Container contentPane = getContentPane();
         contentPane.setLayout(new BorderLayout());
+        contentPane.add(strategyPanel, BorderLayout.NORTH);
         contentPane.add(entitySelectorPanel, BorderLayout.CENTER);
         contentPane.add(buttons, BorderLayout.SOUTH);
 
+        this.choice = CANCEL;
+
+        ModelerPreferences pref = ModelerPreferences.getPreferences();
+        Vector<?> arr = pref.getVector(STRATEGIES_PREFERENCE, PREDEFINED_STRATEGIES);
+        strategyCombo.setModel(new DefaultComboBoxModel(arr));
+
         setTitle("Infer Relationships");
     }
 
+    public int getChoice() {
+        return choice;
+    }
+
+    public void setChoice(int choice) {
+        this.choice = choice;
+    }
+
     public JButton getCancelButton() {
         return cancelButton;
     }
@@ -76,4 +118,8 @@
     public JLabel getEntityCount() {
         return entityCount;
     }
+
+    public JComboBox getStrategyCombo() {
+        return strategyCombo;
+    }
 }
\ No newline at end of file

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsPanel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsPanel.java?rev=787975&r1=787974&r2=787975&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsPanel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/autorelationship/InferRelationshipsPanel.java
Wed Jun 24 11:09:26 2009
@@ -23,22 +23,27 @@
 import java.awt.FlowLayout;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.util.Vector;
 
 import javax.swing.AbstractButton;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTable;
 import javax.swing.ScrollPaneConstants;
 
+import org.apache.cayenne.map.naming.NamingStrategy;
+import org.apache.cayenne.modeler.ModelerPreferences;
 
 public class InferRelationshipsPanel extends JPanel {
-    
+
     protected JTable table;
     protected JCheckBox checkAll;
     protected JLabel checkAllLabel;
-    
+
     public InferRelationshipsPanel() {
         this.table = new JTable();
 
@@ -76,7 +81,7 @@
         setLayout(new BorderLayout());
         add(topPanel, BorderLayout.NORTH);
         add(tablePanel, BorderLayout.CENTER);
-        
+
     }
 
     public JTable getTable() {



Mime
View raw message