cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r924858 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/ modeler/action/ modeler/util/ pref/
Date Thu, 18 Mar 2010 15:20:31 GMT
Author: oltka
Date: Thu Mar 18 15:20:31 2010
New Revision: 924858

URL: http://svn.apache.org/viewvc?rev=924858&view=rev
Log:
CAY-1327 Migrate HSQLDB modeler preferences to Java preferences API

* fix some problems with new project's preferences

Modified:
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NamingStrategyPreferences.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
    cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/RenamedPreferences.java

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java?rev=924858&r1=924857&r2=924858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/Application.java
Thu Mar 18 15:20:31 2010
@@ -46,6 +46,7 @@ import org.apache.cayenne.modeler.util.C
 import org.apache.cayenne.modeler.util.CayenneUserDir;
 import org.apache.cayenne.pref.CayennePreference;
 import org.apache.cayenne.pref.CayenneProjectPreferences;
+import org.apache.cayenne.pref.Preference;
 import org.apache.cayenne.project2.CayenneProjectModule;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.swing.BindingFactory;
@@ -241,6 +242,14 @@ public class Application {
 
         DataChannelDescriptor descriptor = (DataChannelDescriptor) getProject()
                 .getRootNode();
+
+        // if new project
+        if (descriptor.getConfigurationSource() == null) {
+            return Application.getInstance().getPreferencesNode(
+                    getProject().getClass(),
+                    Preference.CAYENNE_TEMP_PREFERENCE_NODE_NAME_FOR_PROJ);
+        }
+
         String path = CayennePreference.filePathToPrefereceNodePath(descriptor
                 .getConfigurationSource()
                 .getURL()

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java?rev=924858&r1=924857&r2=924858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/action/SaveAsAction.java
Thu Mar 18 15:20:31 2010
@@ -35,6 +35,7 @@ import org.apache.cayenne.modeler.Applic
 import org.apache.cayenne.modeler.dialog.validator.ValidationDisplayHandler;
 import org.apache.cayenne.modeler.dialog.validator.ValidatorDialog;
 import org.apache.cayenne.modeler.util.CayenneAction;
+import org.apache.cayenne.pref.Preference;
 import org.apache.cayenne.pref.RenamedPreferences;
 import org.apache.cayenne.project2.Project;
 import org.apache.cayenne.project2.ProjectSaver;
@@ -106,6 +107,13 @@ public class SaveAsAction extends Cayenn
         // /!!!!!!!!!!!!!!!!!!! SAVE AS!!!!!!!!!!!!!!
         ProjectSaver saver = getApplication().getInjector().getInstance(
                 ProjectSaver.class);
+
+        boolean isNewProject = p.getConfigurationResource() == null;
+        Preferences tempOldPref = null;
+        if (isNewProject) {
+            tempOldPref = getApplication().getMainPreferenceForProject();
+        }
+
         saver.saveAs(p, res);
 
         if (oldPath != null
@@ -124,6 +132,25 @@ public class SaveAsAction extends Cayenn
             RenamedPreferences.copyPreferences(newPref, getProjectController()
                     .getPreferenceForProject(), false);
         }
+        else if (isNewProject) {
+            if (tempOldPref != null
+                    && tempOldPref.absolutePath().contains(
+                            Preference.CAYENNE_TEMP_PREFERENCE_NODE_NAME_FOR_PROJ)) {
+                String projPath = tempOldPref.absolutePath().replace(
+                        "/" + Preference.CAYENNE_TEMP_PREFERENCE_NODE_NAME_FOR_PROJ,
+                        "");
+                String newName = p.getConfigurationResource().getURL().getPath().replace(
+                        ".xml",
+                        "");
+
+                Preferences newPref = getApplication()
+                        .getMainPreferenceForProject()
+                        .node(projPath + newName);
+
+                RenamedPreferences.copyPreferences(newPref, tempOldPref, false);
+                tempOldPref.removeNode();
+            }
+        }
 
         RenamedPreferences.removeNewPreferences();
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NamingStrategyPreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NamingStrategyPreferences.java?rev=924858&r1=924857&r2=924858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NamingStrategyPreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/NamingStrategyPreferences.java
Thu Mar 18 15:20:31 2010
@@ -24,7 +24,7 @@ import java.util.prefs.Preferences;
 
 import org.apache.cayenne.configuration.DataChannelDescriptor;
 import org.apache.cayenne.modeler.Application;
-
+
 import org.apache.cayenne.pref.CayennePreference;
 
 /**
@@ -48,7 +48,6 @@ public class NamingStrategyPreferences {
     public static NamingStrategyPreferences getInstance() {
         return instance;
     }
-
 
     Preferences getPreference() {
         return Application.getMainPreferenceForProject();
@@ -58,8 +57,13 @@ public class NamingStrategyPreferences {
      * @return last used strategies, PREDEFINED_STRATEGIES by default
      */
     public Vector<String> getLastUsedStrategies() {
-        String prop = getPreference().get(STRATEGIES_PREFERENCE, null);
-
+
+        String prop = null;
+
+        if (getPreference() != null) {
+            prop = getPreference().get(STRATEGIES_PREFERENCE, null);
+        }
+
         if (prop == null) {
             return PREDEFINED_STRATEGIES;
         }
@@ -84,7 +88,7 @@ public class NamingStrategyPreferences {
         if (strategies.size() > 0) {
             res.deleteCharAt(res.length() - 1);
         }
-
+
         getPreference().put(STRATEGIES_PREFERENCE, res.toString());
     }
 }

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java?rev=924858&r1=924857&r2=924858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/Preference.java
Thu Mar 18 15:20:31 2010
@@ -27,6 +27,8 @@ public interface Preference {
      */
     public static final String CAYENNE_PREFERENCES_PATH = "org/apache/cayenne";
 
+    public static final String CAYENNE_TEMP_PREFERENCE_NODE_NAME_FOR_PROJ = "*temp";
+    
     /**
      * Preferences node name for the editor
      */

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/RenamedPreferences.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/RenamedPreferences.java?rev=924858&r1=924857&r2=924858&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/RenamedPreferences.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/RenamedPreferences.java
Thu Mar 18 15:20:31 2010
@@ -194,16 +194,17 @@ public abstract class RenamedPreferences
     }
 
     private static boolean equalsPath(List<Preferences> listPref, Preferences pref)
{
-        Iterator<Preferences> it = listPref.iterator();
-        while (it.hasNext()) {
-            Preferences next = it.next();
-            String pathInList = (String) next.absolutePath();
-            String path = (String) pref.absolutePath();
-            if (pathInList.equals(path)) {
-                return true;
+        if (listPref != null) {
+            Iterator<Preferences> it = listPref.iterator();
+            while (it.hasNext()) {
+                Preferences next = it.next();
+                String pathInList = (String) next.absolutePath();
+                String path = (String) pref.absolutePath();
+                if (pathInList.equals(path)) {
+                    return true;
+                }
             }
         }
         return false;
     }
-
 }



Mime
View raw message