cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From torehal...@apache.org
Subject svn commit: r612454 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db: MergerOptions.java MergerTokenSelectorController.java MergerTokenTableModel.java
Date Wed, 16 Jan 2008 13:45:25 GMT
Author: torehalset
Date: Wed Jan 16 05:45:24 2008
New Revision: 612454

URL: http://svn.apache.org/viewvc?rev=612454&view=rev
Log:
CAY-885: merge changes between model and db
 * mark model as unsaved if model is changed
 * generics

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java?rev=612454&r1=612453&r2=612454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerOptions.java
Wed Jan 16 05:45:24 2008
@@ -38,6 +38,7 @@
 import org.apache.cayenne.map.DataMap;
 import org.apache.cayenne.merge.DbMerger;
 import org.apache.cayenne.merge.ExecutingMergerContext;
+import org.apache.cayenne.merge.MergeDirection;
 import org.apache.cayenne.merge.MergerContext;
 import org.apache.cayenne.merge.MergerToken;
 import org.apache.cayenne.modeler.Application;
@@ -45,6 +46,7 @@
 import org.apache.cayenne.modeler.dialog.ValidationResultBrowser;
 import org.apache.cayenne.modeler.pref.DBConnectionInfo;
 import org.apache.cayenne.modeler.util.CayenneController;
+import org.apache.cayenne.project.Project;
 import org.apache.cayenne.swing.BindingBuilder;
 import org.apache.cayenne.swing.ObjectBinding;
 import org.apache.cayenne.validation.ValidationResult;
@@ -148,7 +150,7 @@
                     .getClassLoadingService());
             tokens.setMergerFactory(adapter.mergerFactory());
             merger = new DbMerger();
-            List mergerTokens = merger.createMergeTokens(adapter, connectionInfo
+            List<MergerToken> mergerTokens = merger.createMergeTokens(adapter, connectionInfo
                     .makeDataSource(getApplication().getClassLoadingService()), dataMap);
             tokens.setTokens(mergerTokens);
         }
@@ -164,7 +166,7 @@
         // convert them to string representation for display
         final StringBuffer buf = new StringBuffer();
 
-        Iterator it = tokens.getSelectedTokens().iterator();
+        Iterator<MergerToken> it = tokens.getSelectedTokens().iterator();
         String batchTerminator = adapter.getBatchTerminator();
 
         final String lineEnd = (batchTerminator != null) ? "\n"
@@ -193,7 +195,7 @@
         };
 
         while (it.hasNext()) {
-            MergerToken token = (MergerToken) it.next();
+            MergerToken token = it.next();
             token.execute(context);
             // buf.append(token.createSql(adapter)).append(lineEnd);
         }
@@ -249,7 +251,7 @@
         refreshGeneratorAction();
 
         // sanity check...
-        List tokensToMigrate = tokens.getSelectedTokens();
+        List<MergerToken> tokensToMigrate = tokens.getSelectedTokens();
         if (tokensToMigrate.isEmpty()) {
             JOptionPane.showMessageDialog(getView(), "Nothing to migrate.");
             return;
@@ -264,10 +266,27 @@
                     dataMap,
                     dataSource,
                     adapter);
-            for (Iterator it = tokensToMigrate.iterator(); it.hasNext();) {
-                MergerToken tok = (MergerToken) it.next();
+            boolean modelChanged = false;
+            for (Iterator<MergerToken> it = tokensToMigrate.iterator(); it.hasNext();)
{
+                MergerToken tok = it.next();
                 tok.execute(mergerContext);
+                if (!modelChanged && tok.getDirection().equals(MergeDirection.TO_MODEL))
{
+                    modelChanged = true;
+                }
+            }
+            
+            if (modelChanged) {
+                // mark the model as unsaved
+                Project project = Application.getProject();
+                project.setModified(true);
+
+                ProjectController projectController = Application
+                        .getInstance()
+                        .getFrameController()
+                        .getProjectController();
+                projectController.setDirty(true);
             }
+            
             ValidationResult failures = mergerContext.getValidationResult();
 
             if (failures == null || !failures.hasFailures()) {

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java?rev=612454&r1=612453&r2=612454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenSelectorController.java
Wed Jan 16 05:45:24 2008
@@ -47,15 +47,15 @@
 
     protected MergerToken token;
     protected int permanentlyExcludedCount;
-    protected Set excludedTokens;
-    protected List selectableTokensList;
+    protected Set<MergerToken> excludedTokens;
+    protected List<MergerToken> selectableTokensList;
     protected MergerFactory mergerFactory;
 
     public MergerTokenSelectorController(CayenneController parent) {
         super(parent);
         this.view = new MergerTokenSelectorView();
-        this.excludedTokens = new HashSet();
-        this.selectableTokensList = new ArrayList();
+        this.excludedTokens = new HashSet<MergerToken>();
+        this.selectableTokensList = new ArrayList<MergerToken>();
         initController();
     }
 
@@ -63,19 +63,19 @@
         this.mergerFactory = mergerFactory;
     }
 
-    public void setTokens(List tokens) {
+    public void setTokens(List<MergerToken> tokens) {
         selectableTokensList.clear();
         selectableTokensList.addAll(tokens);
         excludedTokens.addAll(tokens);
     }
 
-    public List getSelectedTokens() {
-        List t = new ArrayList(selectableTokensList);
+    public List<MergerToken> getSelectedTokens() {
+        List<MergerToken> t = new ArrayList<MergerToken>(selectableTokensList);
         t.removeAll(excludedTokens);
         return Collections.unmodifiableList(t);
     }
 
-    public List getSelectableTokens() {
+    public List<MergerToken> getSelectableTokens() {
         return Collections.unmodifiableList(selectableTokensList);
     }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java?rev=612454&r1=612453&r2=612454&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/dialog/db/MergerTokenTableModel.java
Wed Jan 16 05:45:24 2008
@@ -34,7 +34,7 @@
 
     private MergerTokenSelectorController controller;
 
-    private List tokens;
+    private List<MergerToken> tokens;
 
     public MergerTokenTableModel(MergerTokenSelectorController controller) {
         this.controller = controller;



Mime
View raw message