Return-Path: Delivered-To: apmail-cayenne-commits-archive@www.apache.org Received: (qmail 1075 invoked from network); 11 Feb 2010 14:43:58 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 Feb 2010 14:43:58 -0000 Received: (qmail 99430 invoked by uid 500); 11 Feb 2010 14:43:58 -0000 Delivered-To: apmail-cayenne-commits-archive@cayenne.apache.org Received: (qmail 99402 invoked by uid 500); 11 Feb 2010 14:43:58 -0000 Mailing-List: contact commits-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list commits@cayenne.apache.org Received: (qmail 99386 invoked by uid 99); 11 Feb 2010 14:43:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Feb 2010 14:43:56 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Feb 2010 14:43:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 58B182388A3B; Thu, 11 Feb 2010 14:43:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r909003 - in /cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne: modeler/action/SaveAsAction.java pref/CayennePreferenceForProject.java Date: Thu, 11 Feb 2010 14:43:31 -0000 To: commits@cayenne.apache.org From: oltka@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100211144335.58B182388A3B@eris.apache.org> Author: oltka Date: Thu Feb 11 14:43:27 2010 New Revision: 909003 URL: http://svn.apache.org/viewvc?rev=909003&view=rev Log: CAY-1327 Migrate HSQLDB modeler preferences to Java preferences API * when save Project as "Save as" need to save preference for new path to project Modified: 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/pref/CayennePreferenceForProject.java 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=909003&r1=909002&r2=909003&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 Feb 11 14:43:27 2010 @@ -25,6 +25,7 @@ import java.io.File; import java.net.URL; import java.util.List; +import java.util.prefs.Preferences; import javax.swing.JOptionPane; import javax.swing.KeyStroke; @@ -79,7 +80,7 @@ Project p = getCurrentProject(); String oldPath = null; - if(p.getConfigurationResource()!=null){ + if (p.getConfigurationResource() != null) { oldPath = p.getConfigurationResource().getURL().getPath(); } @@ -114,18 +115,29 @@ // update preferences domain key preference.rename(projectDir.getPath()); - - CayennePreferenceForProject.removeOldPreferences(); - if (oldPath != null && oldPath.length() != 0) { - getApplication().getFrameController().changePathInLastProjListAction( - oldPath, - p.getConfigurationResource().getURL().getPath()); - } - else { - getApplication().getFrameController().addToLastProjListAction( - p.getConfigurationResource().getURL().getPath()); + if (oldPath != null + && oldPath.length() != 0 + && !oldPath.equals(p.getConfigurationResource().getURL().getPath())) { + + String newName = p.getConfigurationResource().getURL().getPath().replace( + ".xml", + ""); + String oldName = oldPath.replace(".xml", ""); + + Preferences oldPref = getProjectController().getPreferenceForProject(); + String projPath = oldPref.absolutePath().replace(oldName, ""); + Preferences newPref = getProjectController().getPreferenceForProject().node( + projPath + newName); + CayennePreferenceForProject.copyPreferences(newPref, getProjectController() + .getPreferenceForProject(), false); } + + CayennePreferenceForProject.removeNewPreferences(); + + getApplication().getFrameController().addToLastProjListAction( + p.getConfigurationResource().getURL().getPath()); + Application.getFrame().fireRecentFileListChanged(); /** Modified: cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java?rev=909003&r1=909002&r2=909003&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java (original) +++ cayenne/main/trunk/framework/cayenne-modeler/src/main/java/org/apache/cayenne/pref/CayennePreferenceForProject.java Thu Feb 11 14:43:27 2010 @@ -28,7 +28,7 @@ public abstract class CayennePreferenceForProject extends CayennePreference { - private static List newNode; + private static List newNode; private static List oldNode; public CayennePreferenceForProject(Preferences pref) { @@ -41,57 +41,15 @@ public static Preferences copyPreferences(String newName, Preferences oldPref) { - try { - - // copy all preferences in this node - String[] names = oldPref.keys(); - Preferences parent = oldPref.parent(); - Preferences newPref = parent.node(newName); - for (int i = 0; i < names.length; i++) { - newPref.put(names[i], oldPref.get(names[i], "")); - } - - String oldPath = oldPref.absolutePath(); - String newPath = newPref.absolutePath(); - - // copy children nodes and its preferences - ArrayList childrenOldPref = childrenCopy(oldPref, oldPath, newPath); - - while (childrenOldPref.size() > 0) { - - ArrayList childrenPrefTemp = new ArrayList(); - - Iterator it = childrenOldPref.iterator(); - while (it.hasNext()) { - Preferences child = it.next(); - ArrayList childArray = childrenCopy(child, oldPath, newPath); - - childrenPrefTemp.addAll(childArray); - } - - childrenOldPref.clear(); - childrenOldPref.addAll(childrenPrefTemp); - } - - if (newNode == null) { - newNode = new ArrayList(); - } - if (oldNode == null) { - oldNode = new ArrayList(); - } - - newNode.add(newPref); - oldNode.add(oldPref); - - return newPref; - } - catch (BackingStoreException e) { - new CayenneRuntimeException("Error remane preferences"); - } - return oldPref; + Preferences parent = oldPref.parent(); + Preferences newPref = parent.node(newName); + return copyPreferences(newPref, oldPref, true); } - - private static ArrayList childrenCopy(Preferences pref, String oldPath, String newPath) { + + private static ArrayList childrenCopy( + Preferences pref, + String oldPath, + String newPath) { try { String[] children = pref.childrenNames(); @@ -102,17 +60,19 @@ String child = children[j]; // get old preference Preferences childNode = pref.node(child); - - // path to node - String path = childNode.absolutePath().replace(oldPath, newPath); - - // copy all preferences in this node - String[] names = childNode.keys(); - Preferences newPref = Preferences.userRoot().node(path); - for (int i = 0; i < names.length; i++) { - newPref.put(names[i], childNode.get(names[i], "")); + + if (!oldNode.contains(childNode)) { + // path to node + String path = childNode.absolutePath().replace(oldPath, newPath); + + // copy all preferences in this node + String[] names = childNode.keys(); + Preferences newPref = Preferences.userRoot().node(path); + for (int i = 0; i < names.length; i++) { + newPref.put(names[i], childNode.get(names[i], "")); + } + prefChild.add(childNode); } - prefChild.add(childNode); } return prefChild; @@ -134,8 +94,7 @@ catch (BackingStoreException e) { } } - oldNode.clear(); - newNode.clear(); + clearPreferences(); } } @@ -152,8 +111,74 @@ catch (BackingStoreException e) { } } - oldNode.clear(); - newNode.clear(); + clearPreferences(); } } + + public static void clearPreferences() { + oldNode.clear(); + newNode.clear(); + } + + public static Preferences copyPreferences( + Preferences newPref, + Preferences oldPref, + boolean addToPreferenceList) { + + try { + // copy all preferences in this node + String[] names = oldPref.keys(); + + for (int i = 0; i < names.length; i++) { + newPref.put(names[i], oldPref.get(names[i], "")); + } + + String oldPath = oldPref.absolutePath(); + String newPath = newPref.absolutePath(); + + // copy children nodes and its preferences + ArrayList childrenOldPref = childrenCopy( + oldPref, + oldPath, + newPath); + + while (childrenOldPref.size() > 0) { + + ArrayList childrenPrefTemp = new ArrayList(); + + Iterator it = childrenOldPref.iterator(); + while (it.hasNext()) { + Preferences child = it.next(); + ArrayList childArray = childrenCopy( + child, + oldPath, + newPath); + + childrenPrefTemp.addAll(childArray); + } + + childrenOldPref.clear(); + childrenOldPref.addAll(childrenPrefTemp); + } + + if (newNode == null) { + newNode = new ArrayList(); + } + if (oldNode == null) { + oldNode = new ArrayList(); + } + + if (addToPreferenceList) { + newNode.add(newPref); + oldNode.add(oldPref); + } + + return newPref; + } + catch (BackingStoreException e) { + new CayenneRuntimeException("Error remane preferences"); + } + return oldPref; + } + }