cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r930691 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler: Application.java action/SaveAsAction.java util/CayenneController.java
Date Sun, 04 Apr 2010 13:47:31 GMT
Author: aadamchik
Date: Sun Apr  4 13:47:31 2010
New Revision: 930691

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

fixing a method used for temporary naming of new project preferences node

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/CayenneController.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=930691&r1=930690&r2=930691&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
Sun Apr  4 13:47:31 2010
@@ -95,25 +95,31 @@ public class Application {
 
     protected Injector injector;
 
-    private static String id;
+    private String newProjectTemporaryName;
 
     public static Application getInstance() {
         return instance;
     }
 
-    public static String getId() {
-        if (id == null) {
-            byte[] byteId = IDUtil.pseudoUniqueByteSequence(16);
-            id = "new_project_" + byteId.toString();
-        }
-        return id;
-    }
-
     // static methods that should probably go away eventually...
     public static CayenneModelerFrame getFrame() {
         return (CayenneModelerFrame) getInstance().getFrameController().getView();
     }
 
+    public String getNewProjectTemporaryName() {
+
+        // TODO: andrus 4/4/2010 - should that be reset every time a new project is opened
+        if (newProjectTemporaryName == null) {
+            StringBuffer buffer = new StringBuffer("new_project_");
+            for (byte aKey : IDUtil.pseudoUniqueByteSequence(16)) {
+                IDUtil.appendFormattedByte(buffer, aKey);
+            }
+            newProjectTemporaryName = buffer.toString();
+        }
+
+        return newProjectTemporaryName;
+    }
+
     public Application(File initialProject) {
         this.initialProject = initialProject;
 
@@ -236,7 +242,9 @@ public class Application {
 
         // if new project
         if (descriptor.getConfigurationSource() == null) {
-            return getPreferencesNode(getProject().getClass(), getId());
+            return getPreferencesNode(
+                    getProject().getClass(),
+                    getNewProjectTemporaryName());
         }
 
         String path = CayennePreference.filePathToPrefereceNodePath(descriptor

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=930691&r1=930690&r2=930691&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
Sun Apr  4 13:47:31 2010
@@ -132,21 +132,28 @@ public class SaveAsAction extends Cayenn
                     .getPreferenceForProject(), false);
         }
         else if (isNewProject) {
-            if (tempOldPref != null
-                    && tempOldPref.absolutePath().contains(Application.getId()))
{
+            if (tempOldPref != null) {
 
-                String projPath = tempOldPref.absolutePath().replace(
-                        "/" + Application.getId(),
-                        "");
-                String newName = p.getConfigurationResource().getURL().getPath().replace(
-                        ".xml",
-                        "");
+                String newProjectName = getApplication().getNewProjectTemporaryName();
 
-                Preferences newPref = getApplication().getMainPreferenceForProject().node(
-                        projPath + newName);
+                if (tempOldPref.absolutePath().contains(newProjectName)) {
 
-                RenamedPreferences.copyPreferences(newPref, tempOldPref, false);
-                tempOldPref.removeNode();
+                    String projPath = tempOldPref.absolutePath().replace(
+                            "/" + newProjectName,
+                            "");
+                    String newName = p
+                            .getConfigurationResource()
+                            .getURL()
+                            .getPath()
+                            .replace(".xml", "");
+
+                    Preferences newPref = getApplication()
+                            .getMainPreferenceForProject()
+                            .node(projPath + newName);
+
+                    RenamedPreferences.copyPreferences(newPref, tempOldPref, false);
+                    tempOldPref.removeNode();
+                }
             }
         }
 

Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneController.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneController.java?rev=930691&r1=930690&r2=930691&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneController.java
(original)
+++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/modeler/util/CayenneController.java
Sun Apr  4 13:47:31 2010
@@ -105,15 +105,12 @@ public abstract class CayenneController 
      * Returns preference for this component view.
      */
     protected Preferences getViewPreferences() {
-        Preferences pref;
-        if (getApplication().getProject() == null
-                || ((DataChannelDescriptor) getApplication().getProject().getRootNode())
-                        .getConfigurationSource() == null) {
-            pref = getApplication().getPreferencesNode(getView().getClass(), "");
-            return pref;
+
+        if (getApplication().getProject() == null) {
+            return getApplication().getPreferencesNode(getView().getClass(), "");
         }
 
-        pref = getApplication().getMainPreferenceForProject();
+        Preferences pref = getApplication().getMainPreferenceForProject();
         String pathToProject = pref.absolutePath();
         String path = pathToProject
                 + "/"



Mime
View raw message